From 9cb58509a9ab75eb097ef407a76c8966ff764cbd Mon Sep 17 00:00:00 2001
From: beuchatp <beuchatp@control.ee.ethz.ch>
Date: Tue, 18 Dec 2018 16:32:03 +0100
Subject: [PATCH] Added menu items to hide show controller tabs and buttons.
 The functions should be genrealised a bit to make adding more controllers
 easier

---
 .../flyingAgentGUI/forms/controllertabs.ui    |  5 +-
 .../GUI_Qt/flyingAgentGUI/forms/mainwindow.ui | 57 ++++++++++++
 .../flyingAgentGUI/include/controllertabs.h   |  6 ++
 .../include/enablecontrollerloadyamlbar.h     |  6 ++
 .../flyingAgentGUI/include/mainwindow.h       |  9 ++
 .../flyingAgentGUI/src/controllertabs.cpp     | 88 ++++++++++++++++++-
 .../flyingAgentGUI/src/coordinatorrow.cpp     |  4 +
 .../src/enablecontrollerloadyamlbar.cpp       | 29 ++++++
 .../GUI_Qt/flyingAgentGUI/src/mainwindow.cpp  | 32 +++++++
 .../GUI_Qt/flyingAgentGUI/src/topbanner.cpp   |  2 +
 10 files changed, 235 insertions(+), 3 deletions(-)

diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/forms/controllertabs.ui b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/forms/controllertabs.ui
index b847e036..b4718911 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/forms/controllertabs.ui
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/forms/controllertabs.ui
@@ -28,7 +28,10 @@
    <item row="0" column="0">
     <widget class="QTabWidget" name="controller_tabs_widget">
      <property name="currentIndex">
-      <number>2</number>
+      <number>0</number>
+     </property>
+     <property name="movable">
+      <bool>true</bool>
      </property>
      <widget class="QWidget" name="default_tab">
       <attribute name="title">
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/forms/mainwindow.ui b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/forms/mainwindow.ui
index 832f4f81..90eb9f73 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/forms/mainwindow.ui
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/forms/mainwindow.ui
@@ -206,8 +206,18 @@
     <addaction name="action_LoadYAML_BatteryMonitor"/>
     <addaction name="action_LoadYAML_ClientConfig"/>
    </widget>
+   <widget class="QMenu" name="menuControllers">
+    <property name="title">
+     <string>Controllers</string>
+    </property>
+    <addaction name="action_showHideController_default"/>
+    <addaction name="action_showHideController_student"/>
+    <addaction name="action_showHideController_picker"/>
+    <addaction name="action_showHideController_safe"/>
+   </widget>
    <addaction name="menuFile"/>
    <addaction name="menuLoad_YAML"/>
+   <addaction name="menuControllers"/>
   </widget>
   <widget class="QToolBar" name="mainToolBar">
    <attribute name="toolBarArea">
@@ -233,6 +243,53 @@
     <string>ClientConfig</string>
    </property>
   </action>
+  <action name="action_showHideController_default">
+   <property name="checkable">
+    <bool>true</bool>
+   </property>
+   <property name="checked">
+    <bool>true</bool>
+   </property>
+   <property name="enabled">
+    <bool>true</bool>
+   </property>
+   <property name="text">
+    <string>Default</string>
+   </property>
+  </action>
+  <action name="action_showHideController_student">
+   <property name="checkable">
+    <bool>true</bool>
+   </property>
+   <property name="checked">
+    <bool>true</bool>
+   </property>
+   <property name="text">
+    <string>Student</string>
+   </property>
+  </action>
+  <action name="action_showHideController_picker">
+   <property name="checkable">
+    <bool>true</bool>
+   </property>
+   <property name="checked">
+    <bool>true</bool>
+   </property>
+   <property name="text">
+    <string>Picker</string>
+   </property>
+  </action>
+  <action name="action_showHideController_safe">
+   <property name="checkable">
+    <bool>true</bool>
+   </property>
+   <property name="checked">
+    <bool>true</bool>
+   </property>
+   <property name="text">
+    <string>Safe</string>
+   </property>
+  </action>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
  <customwidgets>
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/controllertabs.h b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/controllertabs.h
index a4d11624..9dcd6bbd 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/controllertabs.h
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/controllertabs.h
@@ -45,6 +45,12 @@ public:
     explicit ControllerTabs(QWidget *parent = 0);
     ~ControllerTabs();
 
+    // PUBLIC METHODS FOR TOGGLING THE VISISBLE CONTROLLERS
+    void showHideController_default_changed();
+    void showHideController_student_changed();
+    void showHideController_picker_changed();
+    void showHideController_safe_changed();
+
 
 public slots:
     void setAgentIDsToCoordinate(QVector<int> agentIDs , bool shouldCoordinateAll);
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/enablecontrollerloadyamlbar.h b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/enablecontrollerloadyamlbar.h
index d04e939b..a5776823 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/enablecontrollerloadyamlbar.h
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/enablecontrollerloadyamlbar.h
@@ -60,6 +60,12 @@ public:
     explicit EnableControllerLoadYamlBar(QWidget *parent = 0);
     ~EnableControllerLoadYamlBar();
 
+    // PUBLIC METHODS FOR TOGGLING THE VISISBLE CONTROLLERS
+    void showHideController_default_changed();
+    void showHideController_student_changed();
+    void showHideController_picker_changed();
+    void showHideController_safe_changed();
+
 
 public slots:
     void setAgentIDsToCoordinate(QVector<int> agentIDs , bool shouldCoordinateAll);
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/mainwindow.h b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/mainwindow.h
index 5721fffd..d456f45d 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/mainwindow.h
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/mainwindow.h
@@ -35,6 +35,9 @@
 
 #include <QMainWindow>
 #include <QShortcut>
+#include <QMutex>
+
+#include <QTextStream>
 
 #ifdef CATKIN_MAKE
 #include <ros/ros.h>
@@ -120,6 +123,12 @@ private slots:
     void on_action_LoadYAML_BatteryMonitor_triggered();
     void on_action_LoadYAML_ClientConfig_triggered();
 
+    // FOR THE CONTROLLERS MENU
+    void on_action_showHideController_default_changed();
+    void on_action_showHideController_student_changed();
+    void on_action_showHideController_picker_changed();
+    void on_action_showHideController_safe_changed();
+
 };
 
 #endif // MAINWINDOW_H
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/controllertabs.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/controllertabs.cpp
index d7140128..1c974631 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/controllertabs.cpp
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/controllertabs.cpp
@@ -89,6 +89,88 @@ ControllerTabs::~ControllerTabs()
 
 
 
+
+void ControllerTabs::showHideController_default_changed()
+{
+    // Get the current index of the tab
+    // > Note the this returns -1 if the tab is not found
+    int current_index_of_tab = ui->controller_tabs_widget->indexOf(ui->default_tab);
+
+    // Switch depending on whether the tab was found
+    if (current_index_of_tab < 0)
+    {
+        // Insert the tab
+        ui->controller_tabs_widget->addTab(ui->default_tab,"Default");
+    }
+    else
+    {
+        // Remove the tab
+        ui->controller_tabs_widget->removeTab(current_index_of_tab);
+    }
+}
+
+void ControllerTabs::showHideController_student_changed()
+{
+    // Get the current index of the tab
+    // > Note the this returns -1 if the tab is not found
+    int current_index_of_tab = ui->controller_tabs_widget->indexOf(ui->student_tab);
+
+    // Switch depending on whether the tab was found
+    if (current_index_of_tab < 0)
+    {
+        // Insert the tab
+        ui->controller_tabs_widget->addTab(ui->student_tab,"Student");
+    }
+    else
+    {
+        // Remove the tab
+        ui->controller_tabs_widget->removeTab(current_index_of_tab);
+    }
+}
+
+void ControllerTabs::showHideController_picker_changed()
+{
+    // Get the current index of the tab
+    // > Note the this returns -1 if the tab is not found
+    int current_index_of_tab = ui->controller_tabs_widget->indexOf(ui->picker_tab);
+
+    // Switch depending on whether the tab was found
+    if (current_index_of_tab < 0)
+    {
+        // Insert the tab
+        ui->controller_tabs_widget->addTab(ui->picker_tab,"Picker");
+    }
+    else
+    {
+        // Remove the tab
+        ui->controller_tabs_widget->removeTab(current_index_of_tab);
+    }
+}
+
+void ControllerTabs::showHideController_safe_changed()
+{
+    // Get the current index of the tab
+    // > Note the this returns -1 if the tab is not found
+    int current_index_of_tab = ui->controller_tabs_widget->indexOf(ui->safe_tab);
+
+    // Switch depending on whether the tab was found
+    if (current_index_of_tab < 0)
+    {
+        // Insert the tab
+        ui->controller_tabs_widget->addTab(ui->safe_tab,"Safe");
+    }
+    else
+    {
+        // Remove the tab
+        ui->controller_tabs_widget->removeTab(current_index_of_tab);
+    }
+}
+
+
+
+
+
+
 void ControllerTabs::setObjectNameForDisplayingPoseData( QString object_name )
 {
     if (object_name.isEmpty())
@@ -100,7 +182,9 @@ void ControllerTabs::setObjectNameForDisplayingPoseData( QString object_name )
         // Emit a signal to let the tabs know
         emit poseDataUnavailableSignal();
         // Inform the user
-        ROS_INFO("[CONTROLLER TABS GUI] No longer emitting pose data for any object.");
+        #ifdef CATKIN_MAKE
+            ROS_INFO("[CONTROLLER TABS GUI] No longer emitting pose data for any object.");
+        #endif
     }
     else
     {
@@ -264,4 +348,4 @@ bool ControllerTabs::getTypeAndIDParameters()
     // Return
     return return_was_successful;
 }
-#endif
\ No newline at end of file
+#endif
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/coordinatorrow.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/coordinatorrow.cpp
index 702388f2..3f9eb75c 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/coordinatorrow.cpp
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/coordinatorrow.cpp
@@ -644,6 +644,7 @@ void CoordinatorRow::loadCrazyflieContext()
 
 void CoordinatorRow::getCurrentFlyingState()
 {
+#ifdef CATKIN_MAKE
     d_fall_pps::IntIntService getFlyingStateCall;
     getFlyingStateCall.request.data = 0;
     getCurrentFlyingStateService.waitForExistence(ros::Duration(2.0));
@@ -655,6 +656,7 @@ void CoordinatorRow::getCurrentFlyingState()
     {
         setFlyingState(STATE_UNAVAILABLE);
     }
+#endif
 }
 
 
@@ -662,6 +664,7 @@ void CoordinatorRow::getCurrentFlyingState()
 
 void CoordinatorRow::getCurrentCrazyRadioState()
 {
+#ifdef CATKIN_MAKE
     d_fall_pps::IntIntService getCrazyRadioCall;
     getCrazyRadioCall.request.data = 0;
     getCurrentCrazyRadioStateService.waitForExistence(ros::Duration(2.0));
@@ -673,6 +676,7 @@ void CoordinatorRow::getCurrentCrazyRadioState()
     {
         setCrazyRadioStatus(CRAZY_RADIO_STATE_DISCONNECTED);
     }
+#endif
 }
 
 
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/enablecontrollerloadyamlbar.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/enablecontrollerloadyamlbar.cpp
index 135fab04..5458bcce 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/enablecontrollerloadyamlbar.cpp
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/enablecontrollerloadyamlbar.cpp
@@ -47,6 +47,35 @@ EnableControllerLoadYamlBar::~EnableControllerLoadYamlBar()
 
 
 
+void EnableControllerLoadYamlBar::showHideController_default_changed()
+{
+    ui->enable_default_button   ->setHidden( !(ui->enable_default_button->isHidden()) );
+    ui->load_yaml_default_button->setHidden( !(ui->load_yaml_default_button->isHidden()) );
+}
+
+void EnableControllerLoadYamlBar::showHideController_student_changed()
+{
+    ui->enable_student_button   ->setHidden( !(ui->enable_student_button->isHidden()) );
+    ui->load_yaml_student_button->setHidden( !(ui->load_yaml_student_button->isHidden()) );
+}
+
+void EnableControllerLoadYamlBar::showHideController_picker_changed()
+{
+    ui->enable_demo_button   ->setHidden(    !(ui->enable_demo_button->isHidden()) );
+    ui->load_yaml_demo_button->setHidden( !(ui->load_yaml_demo_button->isHidden()) );
+}
+
+void EnableControllerLoadYamlBar::showHideController_safe_changed()
+{
+    ui->enable_safe_button   ->setHidden( !(ui->enable_safe_button->isHidden()) );
+    ui->load_yaml_safe_button->setHidden( !(ui->load_yaml_safe_button->isHidden()) );
+}
+
+
+
+
+
+
 // ENABLE CONTROLLER BUTTONS ON-CLICK CALLBACK
 
 void EnableControllerLoadYamlBar::on_enable_safe_button_clicked()
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/mainwindow.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/mainwindow.cpp
index 58f17f9d..5479a6d6 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/mainwindow.cpp
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/mainwindow.cpp
@@ -199,6 +199,38 @@ void MainWindow::on_action_LoadYAML_ClientConfig_triggered()
 
 
 
+void MainWindow::on_action_showHideController_default_changed()
+{
+    // Notify the UI elements of this change
+    ui->customWidget_enableControllerLoadYamlBar->showHideController_default_changed();
+    ui->customWidget_controller_tabs->showHideController_default_changed();
+}
+
+
+void MainWindow::on_action_showHideController_student_changed()
+{
+    // Notify the UI elements of this change
+    ui->customWidget_enableControllerLoadYamlBar->showHideController_student_changed();
+    ui->customWidget_controller_tabs->showHideController_student_changed();
+}
+
+
+void MainWindow::on_action_showHideController_picker_changed()
+{
+    // Notify the UI elements of this change
+    ui->customWidget_enableControllerLoadYamlBar->showHideController_picker_changed();
+    ui->customWidget_controller_tabs->showHideController_picker_changed();
+}
+
+void MainWindow::on_action_showHideController_safe_changed()
+{
+    // Notify the UI elements of this change
+    ui->customWidget_enableControllerLoadYamlBar->showHideController_safe_changed();
+    ui->customWidget_controller_tabs->showHideController_safe_changed();
+}
+
+
+
 //    ----------------------------------------------------------------------------------
 //    III  DDDD       &&&      TTTTT  Y   Y  PPPP   EEEEE
 //     I   D   D     &           T     Y Y   P   P  E
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/topbanner.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/topbanner.cpp
index b0e31846..9a77f018 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/topbanner.cpp
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/topbanner.cpp
@@ -154,7 +154,9 @@ void TopBanner::databaseChangedCallback(const std_msgs::Int32& msg)
 void TopBanner::emitObjectNameForDisplayingPoseDataValueChanged()
 {
     emit objectNameForDisplayingPoseDataValueChanged( m_object_name_for_emitting_pose_data );
+#ifdef CATKIN_MAKE
     ROS_INFO_STREAM("[TOP BANNER GUI] Object name \"" << m_object_name_for_emitting_pose_data.toStdString() << "\" emitted for the controller tabs.");
+#endif
 }
 
 
-- 
GitLab