From fe523ec6cfb30f2ecd9590dad3c46a487b2b757e Mon Sep 17 00:00:00 2001
From: Nick Laurenson <nick.laurenson@kitware.com>
Date: Tue, 17 Aug 2021 10:11:40 +0200
Subject: [PATCH] [feat] Offer Interpreter Brand Selection

Hesai calibration file are csv
---
 .../Ui/Widgets/vvCalibrationDialog.cxx        |  17 +-
 Application/Ui/Widgets/vvCalibrationDialog.h  |   1 +
 Application/Ui/Widgets/vvCalibrationDialog.ui | 426 ++++++++++--------
 .../Ui/lqUpdateCalibrationReaction.cxx        |  34 +-
 Application/Ui/lqUpdateCalibrationReaction.h  |   2 +-
 5 files changed, 272 insertions(+), 208 deletions(-)

diff --git a/Application/Ui/Widgets/vvCalibrationDialog.cxx b/Application/Ui/Widgets/vvCalibrationDialog.cxx
index 78b020c3e..38dd35a58 100644
--- a/Application/Ui/Widgets/vvCalibrationDialog.cxx
+++ b/Application/Ui/Widgets/vvCalibrationDialog.cxx
@@ -698,6 +698,21 @@ QString vvCalibrationDialog::selectedCalibrationFile() const
   return this->Internal->ListWidget->item(row)->data(Qt::UserRole).toString();
 }
 
+//-----------------------------------------------------------------------------
+QString vvCalibrationDialog::selectedInterpreterName() const
+{
+  // Return first Checked RadioButton
+  Q_FOREACH(QRadioButton* button,  this->Internal->InterpreterBox->findChildren<QRadioButton*>())
+  {
+    if(button->isChecked()){
+      return button->objectName();
+    }
+  }
+  
+  // None Checked
+  return QString();
+}
+
 //-----------------------------------------------------------------------------
 bool vvCalibrationDialog::isCrashAnalysing() const
 {
@@ -940,7 +955,7 @@ void vvCalibrationDialog::addFile()
 
   pqFileDialog dial(
     pqActiveObjects::instance().activeServer(), pqCoreUtilities::mainWidget(),
-    tr("Choose Calibration File"), defaultDir, tr("xml (*.xml)")
+    tr("Choose Calibration File"), defaultDir
   );
   dial.setObjectName("LidarFileCalibDialog");
   dial.setFileMode(pqFileDialog::ExistingFile);
diff --git a/Application/Ui/Widgets/vvCalibrationDialog.h b/Application/Ui/Widgets/vvCalibrationDialog.h
index 406ff7196..3dc5299da 100644
--- a/Application/Ui/Widgets/vvCalibrationDialog.h
+++ b/Application/Ui/Widgets/vvCalibrationDialog.h
@@ -29,6 +29,7 @@ public:
   virtual ~vvCalibrationDialog();
 
   Q_INVOKABLE QString selectedCalibrationFile() const;
+  Q_INVOKABLE QString selectedInterpreterName() const;
 
   Q_INVOKABLE QStringList calibrationFiles() const;
 
diff --git a/Application/Ui/Widgets/vvCalibrationDialog.ui b/Application/Ui/Widgets/vvCalibrationDialog.ui
index a508bc244..a50bda848 100644
--- a/Application/Ui/Widgets/vvCalibrationDialog.ui
+++ b/Application/Ui/Widgets/vvCalibrationDialog.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>716</width>
-    <height>523</height>
+    <width>846</width>
+    <height>699</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -283,6 +283,16 @@
      </layout>
     </widget>
    </item>
+   <item row="6" column="0" colspan="3">
+    <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>
    <item row="4" column="2">
     <widget class="QGroupBox" name="NetworkForwardingGroup">
      <property name="title">
@@ -388,12 +398,12 @@
       </item>
       <item row="1" column="1">
        <widget class="QSpinBox" name="GPSPortSpinBox">
-        <property name="maximum">
-         <number>65535</number>
-        </property>
         <property name="enabled">
          <bool>false</bool>
         </property>
+        <property name="maximum">
+         <number>65535</number>
+        </property>
        </widget>
       </item>
       <item row="2" column="0">
@@ -425,220 +435,236 @@
       <bool>false</bool>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout_2">
-     <item row="0">
-      <widget class="QCheckBox" name="EnableInterpretGPSPackets">
-       <property name="enabled">
-        <bool>true</bool>
-       </property>
-       <property name="text">
-        <string>Enable interpreting GPS packets</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-     <layout class="QHBoxLayout" name="horizontalLayout_2">
       <item>
-       <layout class="QFormLayout" name="formLayout_4">
-        <item row="0" column="0">
-         <widget class="QLabel" name="GpsXLabel">
-          <property name="text">
-           <string>X</string>
-          </property>
-         </widget>
-        </item>
-        <item row="0" column="1">
-         <widget class="QDoubleSpinBox" name="GpsXSpinBox">
-          <property name="minimum">
-           <double>-100.000000000000000</double>
-          </property>
-          <property name="maximum">
-           <double>100.000000000000000</double>
-          </property>
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-         </widget>
-        </item>
-        <item row="1" column="0">
-         <widget class="QLabel" name="GpsYLabel">
-          <property name="text">
-           <string>Y</string>
-          </property>
-         </widget>
-        </item>
-        <item row="1" column="1">
-         <widget class="QDoubleSpinBox" name="GpsYSpinBox">
-          <property name="minimum">
-           <double>-100.000000000000000</double>
-          </property>
-          <property name="maximum">
-           <double>100.000000000000000</double>
-          </property>
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-         </widget>
-        </item>
-        <item row="2" column="0">
-         <widget class="QLabel" name="GpsZLabel">
-          <property name="text">
-           <string>Z</string>
-          </property>
-         </widget>
-        </item>
-        <item row="2" column="1">
-         <widget class="QDoubleSpinBox" name="GpsZSpinBox">
-          <property name="minimum">
-           <double>-100.000000000000000</double>
-          </property>
-          <property name="maximum">
-           <double>100.000000000000000</double>
-          </property>
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-         </widget>
-        </item>
-        <item row="3" column="0">
-         <widget class="QLabel" name="gpsTimeOffsetLabel">
-          <property name="text">
-           <string>Time offset</string>
-          </property>
-         </widget>
-        </item>
-        <item row="3" column="1">
-         <widget class="QDoubleSpinBox" name="gpsTimeOffsetSpinBox">
-          <property name="minimum">
-           <double>-1000000000.000000000000000</double>
-          </property>
-          <property name="maximum">
-           <double>1000000000.000000000000000</double>
-          </property>
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </item>
-      <item>
-       <spacer name="horizontalSpacer_6">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeType">
-         <enum>QSizePolicy::Fixed</enum>
+       <widget class="QCheckBox" name="EnableInterpretGPSPackets">
+        <property name="enabled">
+         <bool>true</bool>
         </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>12</width>
-          <height>20</height>
-         </size>
+        <property name="text">
+         <string>Enable interpreting GPS packets</string>
         </property>
-       </spacer>
+       </widget>
       </item>
       <item>
-       <layout class="QFormLayout">
-        <property name="fieldGrowthPolicy">
-         <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
-        </property>
-        <item row="1" column="0">
-         <widget class="QLabel" name="GpsRollLabel">
-          <property name="text">
-           <string>Roll</string>
-          </property>
-         </widget>
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
+        <item>
+         <layout class="QFormLayout" name="formLayout_4">
+          <item row="0" column="0">
+           <widget class="QLabel" name="GpsXLabel">
+            <property name="text">
+             <string>X</string>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="1">
+           <widget class="QDoubleSpinBox" name="GpsXSpinBox">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="minimum">
+             <double>-100.000000000000000</double>
+            </property>
+            <property name="maximum">
+             <double>100.000000000000000</double>
+            </property>
+           </widget>
+          </item>
+          <item row="1" column="0">
+           <widget class="QLabel" name="GpsYLabel">
+            <property name="text">
+             <string>Y</string>
+            </property>
+           </widget>
+          </item>
+          <item row="1" column="1">
+           <widget class="QDoubleSpinBox" name="GpsYSpinBox">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="minimum">
+             <double>-100.000000000000000</double>
+            </property>
+            <property name="maximum">
+             <double>100.000000000000000</double>
+            </property>
+           </widget>
+          </item>
+          <item row="2" column="0">
+           <widget class="QLabel" name="GpsZLabel">
+            <property name="text">
+             <string>Z</string>
+            </property>
+           </widget>
+          </item>
+          <item row="2" column="1">
+           <widget class="QDoubleSpinBox" name="GpsZSpinBox">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="minimum">
+             <double>-100.000000000000000</double>
+            </property>
+            <property name="maximum">
+             <double>100.000000000000000</double>
+            </property>
+           </widget>
+          </item>
+          <item row="3" column="0">
+           <widget class="QLabel" name="gpsTimeOffsetLabel">
+            <property name="text">
+             <string>Time offset</string>
+            </property>
+           </widget>
+          </item>
+          <item row="3" column="1">
+           <widget class="QDoubleSpinBox" name="gpsTimeOffsetSpinBox">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="minimum">
+             <double>-1000000000.000000000000000</double>
+            </property>
+            <property name="maximum">
+             <double>1000000000.000000000000000</double>
+            </property>
+           </widget>
+          </item>
+         </layout>
         </item>
-        <item row="1" column="1">
-         <widget class="QDoubleSpinBox" name="GpsRollSpinBox">
-          <property name="alignment">
-           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+        <item>
+         <spacer name="horizontalSpacer_6">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
           </property>
-          <property name="minimum">
-           <double>-180.000000000000000</double>
-          </property>
-          <property name="maximum">
-           <double>180.000000000000000</double>
+          <property name="sizeType">
+           <enum>QSizePolicy::Fixed</enum>
           </property>
-          <property name="enabled">
-           <bool>false</bool>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>12</width>
+            <height>20</height>
+           </size>
           </property>
-         </widget>
+         </spacer>
         </item>
-        <item row="2" column="0">
-         <widget class="QLabel" name="GpsPitchLabel">
-          <property name="text">
-           <string>Pitch</string>
-          </property>
-         </widget>
+        <item>
+         <layout class="QFormLayout">
+          <property name="fieldGrowthPolicy">
+           <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
+          </property>
+          <item row="1" column="0">
+           <widget class="QLabel" name="GpsRollLabel">
+            <property name="text">
+             <string>Roll</string>
+            </property>
+           </widget>
+          </item>
+          <item row="1" column="1">
+           <widget class="QDoubleSpinBox" name="GpsRollSpinBox">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="alignment">
+             <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+            </property>
+            <property name="minimum">
+             <double>-180.000000000000000</double>
+            </property>
+            <property name="maximum">
+             <double>180.000000000000000</double>
+            </property>
+           </widget>
+          </item>
+          <item row="2" column="0">
+           <widget class="QLabel" name="GpsPitchLabel">
+            <property name="text">
+             <string>Pitch</string>
+            </property>
+           </widget>
+          </item>
+          <item row="2" column="1">
+           <widget class="QDoubleSpinBox" name="GpsPitchSpinBox">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="alignment">
+             <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+            </property>
+            <property name="minimum">
+             <double>-90.000000000000000</double>
+            </property>
+            <property name="maximum">
+             <double>90.000000000000000</double>
+            </property>
+           </widget>
+          </item>
+          <item row="4" column="0">
+           <widget class="QLabel" name="GpsYawLabel">
+            <property name="text">
+             <string>Yaw</string>
+            </property>
+           </widget>
+          </item>
+          <item row="4" column="1">
+           <widget class="QDoubleSpinBox" name="GpsYawSpinBox">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="alignment">
+             <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+            </property>
+            <property name="minimum">
+             <double>-360.000000000000000</double>
+            </property>
+            <property name="maximum">
+             <double>360.000000000000000</double>
+            </property>
+           </widget>
+          </item>
+         </layout>
         </item>
-        <item row="2" column="1">
-         <widget class="QDoubleSpinBox" name="GpsPitchSpinBox">
-          <property name="alignment">
-           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-          </property>
-          <property name="minimum">
-           <double>-90.000000000000000</double>
-          </property>
-          <property name="maximum">
-           <double>90.000000000000000</double>
-          </property>
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-         </widget>
-        </item>
-        <item row="4" column="0">
-         <widget class="QLabel" name="GpsYawLabel">
-          <property name="text">
-           <string>Yaw</string>
-          </property>
-         </widget>
-        </item>
-        <item row="4" column="1">
-         <widget class="QDoubleSpinBox" name="GpsYawSpinBox">
-          <property name="alignment">
-           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-          </property>
-          <property name="minimum">
-           <double>-360.000000000000000</double>
-          </property>
-          <property name="maximum">
-           <double>360.000000000000000</double>
-          </property>
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-         </widget>
+        <item>
+         <spacer name="horizontalSpacer_4">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>20</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
         </item>
        </layout>
       </item>
+     </layout>
+    </widget>
+   </item>
+   <item row="0" column="0" colspan="3">
+    <widget class="QGroupBox" name="InterpreterBox">
+     <property name="title">
+      <string>GroupBox</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout">
       <item>
-       <spacer name="horizontalSpacer_4">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
+       <widget class="QRadioButton" name="interpreterRadio_velodyne">
+        <property name="text">
+         <string>Velodyne Interpreter</string>
         </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>20</width>
-          <height>20</height>
-         </size>
+        <property name="checked">
+         <bool>true</bool>
         </property>
-       </spacer>
+       </widget>
+      </item>
+      <item>
+       <widget class="QRadioButton" name="interpreterRadio_hesai">
+        <property name="text">
+         <string>Hesai Interpreter</string>
+        </property>
+       </widget>
       </item>
      </layout>
-     </item>
-     </layout>
-    </widget>
-   </item>
-   <item row="6" column="0" colspan="3">
-    <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>
diff --git a/Application/Ui/lqUpdateCalibrationReaction.cxx b/Application/Ui/lqUpdateCalibrationReaction.cxx
index 7dec467b3..466ab68c9 100644
--- a/Application/Ui/lqUpdateCalibrationReaction.cxx
+++ b/Application/Ui/lqUpdateCalibrationReaction.cxx
@@ -109,6 +109,7 @@ void lqUpdateCalibrationReaction::setNetworkCalibration(vtkSMProxy * proxy, doub
 
 //-----------------------------------------------------------------------------
 void lqUpdateCalibrationReaction::setCalibrationFileAndDefaultInterpreter(vtkSMProxy * proxy,
+                                                                          QString interpreterName,
                                                                           QString calibrationFile)
 {
   if(IsLidarProxy(proxy))
@@ -123,21 +124,42 @@ void lqUpdateCalibrationReaction::setCalibrationFileAndDefaultInterpreter(vtkSMP
     vtkSMProxyProperty* proxyProperty =  vtkSMProxyProperty::SafeDownCast(interpreterProp);
     if (!proxyProperty)
     {
+      qCritical() << "LidarProxy has no Interpreter Property";
       return;
     }
 
     vtkSMProxyListDomain * proxyListDomain = vtkSMProxyListDomain::SafeDownCast(proxyProperty->FindDomain("vtkSMProxyListDomain"));
     if (!proxyListDomain)
     {
+      qCritical() << "LidarProxy Interpreter has no proxyListDomain";
       return;
     }
 
-    vtkSMProxy* defaultProxy = proxyListDomain->FindProxy("LidarPacketInterpreter", "VelodyneMetaPacketInterpreter");
-    if ((calibrationFile.contains("velarray", Qt::CaseInsensitive)))
-    {
-      defaultProxy = proxyListDomain->FindProxy("LidarPacketInterpreter", "VelodyneSpecialVelarrayPacketInterpreter");
+    // Choose Interpreter
+    // WIP Dawn of the Heterogeneous Sensors Features
+    // probably should detect Plugin loading state
+    vtkSMProxy* defaultProxy = nullptr;
+    if      (interpreterName == "interpreterRadio_hesai"){
+      // Set General Packet Interpreter based on SDK as default
+      defaultProxy = proxyListDomain->FindProxy("LidarPacketInterpreter", "HesaiGeneralPacketInterpreter");
+      // Set Custom Interpreter for Pandar128 if name implies it
+      if ((calibrationFile.contains("Pandar128", Qt::CaseInsensitive)))
+      {
+        defaultProxy = proxyListDomain->FindProxy("LidarPacketInterpreter", "HesaiPacketInterpreter");
+      }
+    }else if(interpreterName == "interpreterRadio_velodyne"){
+      // Set Meta Interpreter as Default
+      defaultProxy = proxyListDomain->FindProxy("LidarPacketInterpreter", "VelodyneMetaPacketInterpreter");
+      // Use SpecialVelarray if name implies it
+      if ((calibrationFile.contains("velarray", Qt::CaseInsensitive)))
+      {
+        defaultProxy = proxyListDomain->FindProxy("LidarPacketInterpreter", "VelodyneSpecialVelarrayPacketInterpreter");
+      }
+    }else{
+      qCritical() << "Unknown Interpreter Type";
+      return;
     }
-
+    
     // Set the found proxy in the proxy list domain to the lidar property
     // This allows to update the "drop down" menu in the interpreter ui property
     vtkSMPropertyHelper(interpreterProp).Set(defaultProxy);
@@ -158,7 +180,7 @@ void lqUpdateCalibrationReaction::UpdateCalibration(pqPipelineSource* & lidarSou
   }
 
   // Set the calibration File and the lidar interpreter
-  lqUpdateCalibrationReaction::setCalibrationFileAndDefaultInterpreter(lidarProxy, dialog.selectedCalibrationFile());
+  lqUpdateCalibrationReaction::setCalibrationFileAndDefaultInterpreter(lidarProxy, dialog.selectedInterpreterName(), dialog.selectedCalibrationFile());
 
 
   // Set the transform of the lidar Sensor
diff --git a/Application/Ui/lqUpdateCalibrationReaction.h b/Application/Ui/lqUpdateCalibrationReaction.h
index 7a2e62dbf..ebafde9f4 100644
--- a/Application/Ui/lqUpdateCalibrationReaction.h
+++ b/Application/Ui/lqUpdateCalibrationReaction.h
@@ -29,7 +29,7 @@ public:
                                     bool isForwarding, QString ipAddressForwarding,
                                     bool isCrashAnalysing, bool multiSensors);
 
-  static void setCalibrationFileAndDefaultInterpreter(vtkSMProxy * proxy, QString calibrationFile);
+  static void setCalibrationFileAndDefaultInterpreter(vtkSMProxy * proxy, QString interpreterName ,QString calibrationFile);
 
 
   static void UpdateCalibration(pqPipelineSource* & lidarSource,
-- 
GitLab