From 125952db1c6e4f61b749801f15e51d6883845c48 Mon Sep 17 00:00:00 2001
From: Melanie <melanie.carriere@kitware.com>
Date: Mon, 16 Nov 2020 12:33:19 +0100
Subject: [PATCH] [feature] Add Reaction to enable/disable interpreter's
 advanced arrays option

When opening Lidarview, the default action should be "EnableAdvancedArrays"
Then when the user click on the button, the enable advanced arrays are ON.
The buttons should now represent the action "Disable advanced arrays"
The Reaction update the icon and the tooltip according to that.
---
 ApplicationComponents/CMakeLists.txt          |   2 +
 .../Icons/DisableAdvancedArrays.png           | Bin 0 -> 306 bytes
 .../Icons/EnableAdvancedArrays.png            | Bin 0 -> 337 bytes
 .../lqEnableAdvancedArraysReaction.cxx        |  92 ++++++++++++++++++
 .../lqEnableAdvancedArraysReaction.h          |  39 ++++++++
 ApplicationComponents/lqResources.qrc         |   2 +
 6 files changed, 135 insertions(+)
 create mode 100644 ApplicationComponents/Icons/DisableAdvancedArrays.png
 create mode 100644 ApplicationComponents/Icons/EnableAdvancedArrays.png
 create mode 100644 ApplicationComponents/lqEnableAdvancedArraysReaction.cxx
 create mode 100644 ApplicationComponents/lqEnableAdvancedArraysReaction.h

diff --git a/ApplicationComponents/CMakeLists.txt b/ApplicationComponents/CMakeLists.txt
index 2530060dc..e1fd159c6 100644
--- a/ApplicationComponents/CMakeLists.txt
+++ b/ApplicationComponents/CMakeLists.txt
@@ -37,6 +37,8 @@ add_library(lqApplicationComponents
   LidarCameraToolbar/lqLidarCameraToolbar.cxx
   LidarCameraToolbar/lqLidarCameraToolbar.h
   LidarCameraToolbar/lqLidarCameraToolbar.ui
+  lqEnableAdvancedArraysReaction.cxx
+  lqEnableAdvancedArraysReaction.h
   lqResources.qrc
   )
 target_include_directories(lqApplicationComponents PUBLIC
diff --git a/ApplicationComponents/Icons/DisableAdvancedArrays.png b/ApplicationComponents/Icons/DisableAdvancedArrays.png
new file mode 100644
index 0000000000000000000000000000000000000000..6eb6def7ac7a07d830ba92be67fec01df55837da
GIT binary patch
literal 306
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b
z3=G`DAk4@xYmNj^kiEpy*OmPVH!q)w{=IuYV}L^YJzX3_EKVn%(eL<k-hnY8F(D!0
z#Hkzy!J1!R7@N0jVe<1e_?dZGT4IKT28#|45G?nX2g?3@b+Wm4wwTU=#r}<rjSm@_
znVp%P>l~l_pKYGM=)v0C*WMma&#rS^VmsyEd8W_8MipOQ&1CQq<V%<kFVOjcsj8v&
z|HrR~k8qyme^kf_rk{zs7+pBW+9o_rUO|NUIk(bEk=`474tR7i-q`ct?12Lv`cmqC
q5p@Rh8xsXwl#e!^@W?D<W0)mcrqO$H!U>>P7(8A5T-G@yGywozVsW<s

literal 0
HcmV?d00001

diff --git a/ApplicationComponents/Icons/EnableAdvancedArrays.png b/ApplicationComponents/Icons/EnableAdvancedArrays.png
new file mode 100644
index 0000000000000000000000000000000000000000..f016635d46f6c2b0358aabc4b3146e1b0d1363cc
GIT binary patch
literal 337
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b
z3=G`DAk4@xYmNj^kiEpy*OmPVH!q(Sn}=@Pd!W!gPZ!4!i_^(x^gI5XcVJ9NOh`yL
zaVp0_u;$kn#^x<snEZSVer8^lmY5--!J@+h1k3&9fwDheoow!%Ev9o|v43M@<3mPf
zW@l#SI>#sfXPf6Qda(BPwYSI9v+Ep}*iQL(p6Ro&QN`C+GZ}mYnVFdnA9;TIq2HP5
zJtaV^3{L2GxKuFO9@zK)$FIakEl=4WGCkzj*(p3t9_XT$%SU!G-2LgYgW=@O6AWjq
zL%Q5@;uNkisLc?cuyMwWE9`Akd3p+Zc*2Yfo_V`j9XOIH(Xqru*|FgrugU?B%rZ8H
YLsjiN?|yu<8|YI8Pgg&ebxsLQ04VW-Jpcdz

literal 0
HcmV?d00001

diff --git a/ApplicationComponents/lqEnableAdvancedArraysReaction.cxx b/ApplicationComponents/lqEnableAdvancedArraysReaction.cxx
new file mode 100644
index 000000000..acd4647b1
--- /dev/null
+++ b/ApplicationComponents/lqEnableAdvancedArraysReaction.cxx
@@ -0,0 +1,92 @@
+#include "lqEnableAdvancedArraysReaction.h"
+
+#include "lqHelper.h"
+
+#include <QFileDialog>
+#include <QMessageBox>
+
+#include <pqApplicationCore.h>
+#include <pqFileDialog.h>
+#include <pqServerManagerModel.h>
+#include <pqPipelineSource.h>
+#include <vtkSMSourceProxy.h>
+#include <vtkSMPropertyHelper.h>
+
+//-----------------------------------------------------------------------------
+lqEnableAdvancedArraysReaction::lqEnableAdvancedArraysReaction(QAction *action)
+  : Superclass(action)
+{
+  this->parentAction()->setEnabled(false);
+  auto* core = pqApplicationCore::instance();
+
+  pqServerManagerModel* smmodel = core->getServerManagerModel();
+  this->connect(smmodel, SIGNAL(sourceAdded(pqPipelineSource*)), SLOT(onSourceAdded(pqPipelineSource*)));
+  this->connect(smmodel, SIGNAL(sourceRemoved(pqPipelineSource*)), SLOT(onSourceRemoved(pqPipelineSource*)));
+
+  foreach (pqPipelineSource* src, smmodel->findItems<pqPipelineSource*>())
+    this->onSourceAdded(src);
+
+  this->parentAction()->setCheckable(true);
+}
+
+//-----------------------------------------------------------------------------
+void lqEnableAdvancedArraysReaction::onTriggered()
+{
+  int booleanToSet = 0;
+  // Declare the value to set to the property
+  if(this->parentAction()->isChecked())
+  {
+    booleanToSet = 1; // the property should be set to "true"
+    // Change icon and tooltip of the button to disable advance array
+    this->parentAction()->setIcon(QIcon(":/lqResources/Icons/DisableAdvancedArrays.png"));
+    this->parentAction()->setToolTip(QString("Disable the interpreter's advanced arrays."));
+
+  }
+  else
+  {
+    booleanToSet = 0; // the property should be set to "false"
+    // Change icon and tooltip of the button to enable advance array
+    this->parentAction()->setIcon(QIcon(":/lqResources/Icons/EnableAdvancedArrays.png"));
+    this->parentAction()->setToolTip(QString("Enable the interpreter's advanced arrays."));
+  }
+
+  // Update all lidar proxy with the new property value
+  std::vector<vtkSMProxy*> lidarProxys = GetLidarsProxy();
+  for(vtkSMProxy* proxy : lidarProxys)
+  {
+    vtkSMProxy* interp = SearchProxyByGroupName(proxy, "LidarPacketInterpreter");
+    if(interp != nullptr)
+    {
+      vtkSMProperty* property = GetPropertyFromProxy(interp, "EnableAdvancedArrays");
+      vtkSMPropertyHelper(property).Set(booleanToSet);
+
+      //Update the proxy
+      proxy->UpdateSelfAndAllInputs();
+      vtkSMSourceProxy * sourcelidarProxy = vtkSMSourceProxy::SafeDownCast(proxy);
+      if(sourcelidarProxy)
+      {
+        sourcelidarProxy->UpdatePipelineInformation();
+      }
+      pqApplicationCore::instance()->render();
+    }
+  }
+}
+
+//-----------------------------------------------------------------------------
+void lqEnableAdvancedArraysReaction::onSourceAdded(pqPipelineSource *src)
+{
+  if (!this->parentAction()->isEnabled() && IsLidarProxy(src->getProxy()))
+  {
+    this->parentAction()->setEnabled(true);
+  }
+}
+
+//-----------------------------------------------------------------------------
+void lqEnableAdvancedArraysReaction::onSourceRemoved(pqPipelineSource * vtkNotUsed(src)){
+  if (this->parentAction()->isEnabled() && !HasLidarProxy())
+  {
+    this->parentAction()->setEnabled(false);
+    this->parentAction()->setChecked(false);
+    this->parentAction()->setIcon(QIcon(":/lqResources/Icons/EnableAdvancedArrays.png"));
+  }
+}
diff --git a/ApplicationComponents/lqEnableAdvancedArraysReaction.h b/ApplicationComponents/lqEnableAdvancedArraysReaction.h
new file mode 100644
index 000000000..c8bbde2c2
--- /dev/null
+++ b/ApplicationComponents/lqEnableAdvancedArraysReaction.h
@@ -0,0 +1,39 @@
+#ifndef LqEnableAdvancedArraysReaction_h
+#define LqEnableAdvancedArraysReaction_h
+
+#include <pqReaction.h>
+
+#include "lqapplicationcomponents_export.h"
+
+class pqPipelineSource;
+/**
+* @ingroup Reactions
+* Reaction to enable and disable advanced arrays
+*/
+class LQAPPLICATIONCOMPONENTS_EXPORT lqEnableAdvancedArraysReaction : public pqReaction
+{
+    Q_OBJECT
+    typedef pqReaction Superclass;
+
+public:
+  lqEnableAdvancedArraysReaction(QAction* action);
+
+public slots:
+  /**
+  * Called when the action is triggered.
+  */
+  void onTriggered() override;
+
+  /**
+   * Monitor the added/deleted source to enable/disable the QAction
+   */
+  void onSourceAdded(pqPipelineSource* src);
+  void onSourceRemoved(pqPipelineSource* src);
+
+
+private:
+  Q_DISABLE_COPY(lqEnableAdvancedArraysReaction)
+
+};
+
+#endif // LqEnableAdvancedArraysReaction_h
diff --git a/ApplicationComponents/lqResources.qrc b/ApplicationComponents/lqResources.qrc
index 4f936c2a5..a3a024864 100644
--- a/ApplicationComponents/lqResources.qrc
+++ b/ApplicationComponents/lqResources.qrc
@@ -13,5 +13,7 @@
         <file>Icons/pqRotateCameraCW.png</file>
         <file>Icons/pqZoomToData.png</file>
         <file>Icons/pqZoomToSelection.png</file>
+        <file>Icons/EnableAdvancedArrays.png</file>
+        <file>Icons/DisableAdvancedArrays.png</file>
     </qresource>
 </RCC>
-- 
GitLab