diff --git a/ApplicationComponents/CMakeLists.txt b/ApplicationComponents/CMakeLists.txt index 671d7f1c84f8b86739b4948dbb06739d6bcb5c95..835f99d2beb439812c50e6401c9582735b1134f9 100644 --- a/ApplicationComponents/CMakeLists.txt +++ b/ApplicationComponents/CMakeLists.txt @@ -42,6 +42,9 @@ add_library(lqApplicationComponents lqRulerReaction.cxx lqLiveSourceScalarColoringBehavior.cxx lqLiveSourceScalarColoringBehavior.h + SaveAndLoadLidarState/lqChooseLidarDialog.cxx + SaveAndLoadLidarState/lqChooseLidarDialog.h + SaveAndLoadLidarState/lqChooseLidarDialog.ui SaveAndLoadLidarState/lqSaveLidarStateReaction.cxx SaveAndLoadLidarState/lqSaveLidarStateReaction.h SaveAndLoadLidarState/lqLoadLidarStateReaction.cxx diff --git a/ApplicationComponents/SaveAndLoadLidarState/lqChooseLidarDialog.cxx b/ApplicationComponents/SaveAndLoadLidarState/lqChooseLidarDialog.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6abd893082c3641fbb01d148a4f717f8b089920d --- /dev/null +++ b/ApplicationComponents/SaveAndLoadLidarState/lqChooseLidarDialog.cxx @@ -0,0 +1,37 @@ +#include "lqChooseLidarDialog.h" + +#include "ui_lqChooseLidarDialog.h" + +#include <pqApplicationCore.h> +#include <pqSettings.h> + +#include <QDialog> +#include <QListWidget> +#include <QListWidgetItem> + +//----------------------------------------------------------------------------- +class lqChooseLidarDialog::pqInternal : public Ui::lqChooseLidarDialog +{ +}; + +//----------------------------------------------------------------------------- +lqChooseLidarDialog::lqChooseLidarDialog(QWidget* p, const QStringList& lidarNames) + : QDialog(p) + , Internal(new pqInternal) +{ + this->Internal->setupUi(this); + + foreach (QString fullname, lidarNames) + { + QListWidgetItem* item = new QListWidgetItem(); + item->setText(fullname); + item->setData(Qt::UserRole, ""); + this->Internal->ListLidar->addItem(item); + } +} + +//----------------------------------------------------------------------------- +int lqChooseLidarDialog::getSelectedLidarIndex() const +{ + return this->Internal->ListLidar->currentRow(); +} diff --git a/ApplicationComponents/SaveAndLoadLidarState/lqChooseLidarDialog.h b/ApplicationComponents/SaveAndLoadLidarState/lqChooseLidarDialog.h new file mode 100644 index 0000000000000000000000000000000000000000..c7600f6e8107d6df53ef84493d52efb23ac1cf9f --- /dev/null +++ b/ApplicationComponents/SaveAndLoadLidarState/lqChooseLidarDialog.h @@ -0,0 +1,58 @@ +/*========================================================================= + + Program: LidarView + Module: lqChooseLidarDialog.h + + Copyright (c) Kitware Inc. + All rights reserved. + + LidarView is a free software; you can redistribute it and/or modify it + under the terms of the LidarView license. + + See LICENSE for the full LidarView license. + A copy of this license can be obtained by contacting + Kitware Inc. + 28 Corporate Drive + Clifton Park, NY 12065 + USA + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +========================================================================*/ + +#ifndef lqChooseLidarDialog_H +#define lqChooseLidarDialog_H + +#include <QDialog> + +/** + * @brief Dialog so the user can select the lidar to save from + */ +class lqChooseLidarDialog : public QDialog +{ + Q_OBJECT + +public: + lqChooseLidarDialog(QWidget* parent, const QStringList& lidarNames); + virtual ~lqChooseLidarDialog(){}; + + Q_INVOKABLE int getSelectedLidarIndex() const; + +private: + class pqInternal; + pqInternal* Internal; + + Q_DISABLE_COPY(lqChooseLidarDialog) +}; + +#endif // lqChooseLidarDialog_H diff --git a/ApplicationComponents/SaveAndLoadLidarState/lqChooseLidarDialog.ui b/ApplicationComponents/SaveAndLoadLidarState/lqChooseLidarDialog.ui new file mode 100644 index 0000000000000000000000000000000000000000..208c758194f242ccb6e811de199ef283ad666139 --- /dev/null +++ b/ApplicationComponents/SaveAndLoadLidarState/lqChooseLidarDialog.ui @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>lqChooseLidarDialog</class> + <widget class="QDialog" name="lqChooseLidarDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>555</width> + <height>231</height> + </rect> + </property> + <property name="windowTitle"> + <string>Choose Lidar</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0" colspan="2"> + <widget class="QGroupBox" name="LidarGroup"> + <property name="title"> + <string>Multiple lidars sources found, please select the one to save</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QListWidget" name="ListLidar"/> + </item> + </layout> + </widget> + </item> + <item row="1" column="1"> + <widget class="QDialogButtonBox" name="ButtonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>ButtonBox</sender> + <signal>accepted()</signal> + <receiver>lqChooseLidarDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>ButtonBox</sender> + <signal>rejected()</signal> + <receiver>lqChooseLidarDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.cxx b/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.cxx index 34e3334b898eb4b8d43cc988705d0cac853259bf..6a0f2548762ab0d9cad27f7afa8ad0aceab5b1b6 100644 --- a/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.cxx +++ b/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.cxx @@ -31,22 +31,42 @@ lqLoadLidarStateReaction::lqLoadLidarStateReaction(QAction* action) //----------------------------------------------------------------------------- void lqLoadLidarStateReaction::onTriggered() { - // Get the first lidar source - std::vector<vtkSMProxy*> lidarProxys = GetLidarsProxy(); - - if (lidarProxys.empty()) + pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel(); + if (smmodel == nullptr) { - QMessageBox::warning(nullptr, tr(""), tr("No lidar source found in the pipeline")); return; } + // The first lidar source by default + int index = 0; + QStringList lidarNames; + std::vector<vtkSMProxy*> lidarProxys; + foreach (pqPipelineSource* src, smmodel->findItems<pqPipelineSource*>()) + { + if (IsLidarProxy(src->getProxy())) + { + lidarProxys.push_back(src->getProxy()); + lidarNames << src->getSMName(); + } + } + if (lidarProxys.size() > 1) { - QMessageBox::warning( - nullptr, tr(""), tr("Multiple lidars sources found, only the first one will be updated")); + lqChooseLidarDialog dialog(nullptr, lidarNames); + if (!dialog.exec()) + { + return; + } + index = dialog.getSelectedLidarIndex(); + } + + if (lidarProxys.size() < 1 || lidarProxys[index] == nullptr) + { + QMessageBox::warning(nullptr, tr(""), tr("No lidar source found in the pipeline")); + return; } - lqLoadLidarStateReaction::LoadLidarState(lidarProxys[0]); + lqLoadLidarStateReaction::LoadLidarState(lidarProxys[index]); } //----------------------------------------------------------------------------- diff --git a/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.h b/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.h index b9a9eb203997cff39f460b81bc74da91adfddd24..7fbcdd477bcf6053497dfeb06dd21f7cdc155d13 100644 --- a/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.h +++ b/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.h @@ -5,6 +5,7 @@ #include "pqReaction.h" +#include "lqChooseLidarDialog.h" #include "lqLidarStateDialog.h" #include "lqapplicationcomponents_export.h" @@ -25,6 +26,10 @@ class LQAPPLICATIONCOMPONENTS_EXPORT lqLoadLidarStateReaction : public pqReactio public: lqLoadLidarStateReaction(QAction* action); + /** + * @brief Load from a json file the lidar properties state and apply them + * @param lidarProxy proxy to write the properties into + */ static void LoadLidarState(vtkSMProxy* lidarCurrentProxy); public slots: diff --git a/ApplicationComponents/SaveAndLoadLidarState/lqSaveLidarStateReaction.cxx b/ApplicationComponents/SaveAndLoadLidarState/lqSaveLidarStateReaction.cxx index 7b9edeba52c1031a2cfdf577b9c88cff905aaa7f..658c4d3de55547cab48fe8dbfae601ff679b92ba 100644 --- a/ApplicationComponents/SaveAndLoadLidarState/lqSaveLidarStateReaction.cxx +++ b/ApplicationComponents/SaveAndLoadLidarState/lqSaveLidarStateReaction.cxx @@ -29,45 +29,51 @@ lqSaveLidarStateReaction::lqSaveLidarStateReaction(QAction* action) //----------------------------------------------------------------------------- void lqSaveLidarStateReaction::onTriggered() { - // Get the first lidar source pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel(); if (smmodel == nullptr) { return; } - vtkSMProxy* lidarProxy = nullptr; + + // The first lidar source by default + int index = 0; + QStringList lidarNames; + std::vector<vtkSMProxy*> lidarProxys; foreach (pqPipelineSource* src, smmodel->findItems<pqPipelineSource*>()) { if (IsLidarProxy(src->getProxy())) { - if (lidarProxy == nullptr) - { - lidarProxy = src->getProxy(); - } - else - { - QMessageBox::warning( - nullptr, tr(""), tr("Multiple lidars sources found, only the first one will be saved")); - } + lidarProxys.push_back(src->getProxy()); + lidarNames << src->getSMName(); + } + } + + if (lidarProxys.size() > 1) + { + lqChooseLidarDialog dialog(nullptr, lidarNames); + if (!dialog.exec()) + { + return; } + index = dialog.getSelectedLidarIndex(); } - if (lidarProxy == nullptr) + if (lidarProxys.size() < 1 || lidarProxys[index] == nullptr) { QMessageBox::warning(nullptr, tr(""), tr("No lidar source found in the pipeline")); return; } - lqSaveLidarStateReaction::SaveLidarState(lidarProxy); + lqSaveLidarStateReaction::SaveLidarState(lidarProxys[index], lidarNames[index]); } //----------------------------------------------------------------------------- -void lqSaveLidarStateReaction::SaveLidarState(vtkSMProxy* lidarProxy) +void lqSaveLidarStateReaction::SaveLidarState(vtkSMProxy* lidarProxy, const QString& lidarName) { // Save Lidar information file and save the folder in which it was saved to find it again later - QString defaultFileName = QString("/SaveLidarInformation.json"); + QString defaultFileName = QString("/" + lidarName + "Information.json"); pqSettings* settings = pqApplicationCore::instance()->settings(); QString defaultDir = settings->value("LidarPlugin/OpenData/DefaultDirState", QDir::homePath()).toString(); diff --git a/ApplicationComponents/SaveAndLoadLidarState/lqSaveLidarStateReaction.h b/ApplicationComponents/SaveAndLoadLidarState/lqSaveLidarStateReaction.h index 8c235f0c708abdc624b452911dfdf905c61296d9..213a1809197981850ee494d2a454f3134fec8fe2 100644 --- a/ApplicationComponents/SaveAndLoadLidarState/lqSaveLidarStateReaction.h +++ b/ApplicationComponents/SaveAndLoadLidarState/lqSaveLidarStateReaction.h @@ -8,6 +8,7 @@ #include <vtkSMProperty.h> #include <vtk_jsoncpp.h> +#include "lqChooseLidarDialog.h" #include "lqLidarStateDialog.h" #include "lqapplicationcomponents_export.h" @@ -25,7 +26,12 @@ class LQAPPLICATIONCOMPONENTS_EXPORT lqSaveLidarStateReaction : public pqReactio public: lqSaveLidarStateReaction(QAction* action); - static void SaveLidarState(vtkSMProxy* lidarProxy); + /** + * @brief Save to a json file the current lidar properties state + * @param lidarProxy proxy to extract the properties + * @param lidarName lidar name that will be used in default filename + */ + static void SaveLidarState(vtkSMProxy* lidarProxy, const QString& lidarName); public slots: /** diff --git a/ApplicationComponents/SensorWidget/lqSensorWidget.cxx b/ApplicationComponents/SensorWidget/lqSensorWidget.cxx index 4c35630ba7184d362f99fdd4163ae84dea8d6299..a7237dfea310aab3be0f74ce42f7039ee1c9865c 100644 --- a/ApplicationComponents/SensorWidget/lqSensorWidget.cxx +++ b/ApplicationComponents/SensorWidget/lqSensorWidget.cxx @@ -375,7 +375,8 @@ void lqSensorWidget::onSaveLidarState() { if (this->LidarSource) { - lqSaveLidarStateReaction::SaveLidarState(this->LidarSource->getProxy()); + lqSaveLidarStateReaction::SaveLidarState( + this->LidarSource->getProxy(), this->LidarSource->getSMName()); } }