<commit_before>#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <getopt.h>
#include <iostream>

#include <bot_vis/bot_vis.h>
#include <lcm/lcm.h>
#include <bot_core/bot_core.h>
#include <path_util/path_util.h>
#include <ConciseArgs>

#include <bot_frames/bot_frames_renderers.h>

//imported renderers
#include <bot_lcmgl_render/lcmgl_bot_renderer.h>
#include <laser_utils/renderer_laser.h>
#include <image_utils/renderer_cam_thumb.h>
#include <visualization/collections_renderer.hpp>
#include <octomap_utils/renderer_octomap.h>
#include <renderer_maps/MapsRenderer.hpp>
#include <renderer_data_control/DataControlRenderer.hpp>
// #include <renderer_annotated_camera/AnnotatedCameraRenderer.hpp>
#include <multisense/multisense_renderer.h>
#include <occ_map/occ_map_renderers.h>
// Individual Renderers:
#include <renderer_drc/renderer_scrollingplots.h>
#include <renderer_drc/renderer_driving.hpp>
#include <renderer_drc/renderer_walking.hpp>
#include <renderer_drc/renderer_status.hpp>
#include <renderer_drc/renderer_drcgrid.h>
#include <renderer_drc/renderer_recovery.hpp>
#include <renderer_drc/renderer_bdi.hpp>

// block of renderers
#include <renderer_robot_state/renderer_robot_state.hpp>
#include <renderer_robot_plan/renderer_robot_plan.hpp>
#include <renderer_crawling_plan/renderer_crawling_plan.hpp>
#include <renderer_affordances/renderer_affordances.hpp>
#include <renderer_sticky_feet/renderer_sticky_feet.hpp>
#include <renderer_end_effector_goal/renderer_end_effector_goal.hpp>

#include <tracker-renderer/TrackerRenderer.hpp>


#include "udp_util.h"
#include "RendererGroupUtil.hpp"
#include <lcmtypes/drc_lcmtypes.h>
#include <visualization_utils/keyboard_signal_utils.hpp>
#include <visualization_utils/affordance_utils/aff_trigger_signal_utils.hpp>

using namespace std;
using namespace visualization_utils;

// NOTE (Sisir, 8th Jul 13): We dont want to have individual keyboard event handlers in renderers
// as designed in lib-bot as the key events can be non-unique and the key handlers can conflict. 
// Using boost::signals to create a global keyboard signal. Each renderer creates a corresponding 
// slot to handle global key events. Using a shared ptr to the boost signal. Renderers that require access
// to keyboard signals will receive the signal ref as an argument in their setup function.
KeyboardSignalRef _keyboardSignalRef = KeyboardSignalRef(new KeyboardSignal()); 
AffTriggerSignalsRef _affTriggerSignalsRef = AffTriggerSignalsRef(new AffTriggerSignals()); 

static int
logplayer_remote_on_key_press(BotViewer *viewer, BotEventHandler *ehandler,
        const GdkEventKey *event)
{
    int keyval = event->keyval;
    //std::cout << "keyval: " << keyval << "\n";
    
    // emit global keyboard signal, second argument indicates that it is a keypress (if true)
    (*_keyboardSignalRef)(keyval,true); 
    
    switch (keyval)
    {
      case 'P':
      case 'p':
          udp_send_string("127.0.0.1", 53261, "PLAYPAUSETOGGLE");
          break;
      case 'N':
      case 'n':
          udp_send_string("127.0.0.1", 53261, "STEP");
          break;
      case '=':
      case '+':
          udp_send_string("127.0.0.1", 53261, "FASTER");
          break;
      case '_':
      case '-':
          udp_send_string("127.0.0.1", 53261, "SLOWER");
          break;
      case '[':
          udp_send_string("127.0.0.1", 53261, "BACK5");
          break;
      case ']':
          udp_send_string("127.0.0.1", 53261, "FORWARD5");
          break;
      case SHIFT_L:
      case SHIFT_R:
          //std::cout << "shift pressed\n";
          break;
      default:
          return 0;
    }

    return 1;
}

static int
on_key_release(BotViewer *viewer, BotEventHandler *ehandler,
        const GdkEventKey *event)
{
    int keyval = event->keyval;
    // emit global keyboard signal, second argument indicates that it is a keyrelease (if false)
    (*_keyboardSignalRef)(keyval,false); // emit global keyboard signal
    
    switch (keyval)
    {
      case SHIFT_L:
      case SHIFT_R:
          //std::cout << "shift released\n";
          break;
      default:
          return 0;
    }


    return 1;
}


static void on_collapse_all_clicked(GtkToggleToolButton *tb, void *user_data)
{
  BotViewer *viewer = (BotViewer*) user_data;
  for (unsigned int i = 0; i < viewer->renderers->len; ++i) {
    BotRenderer* renderer =
      (BotRenderer*)g_ptr_array_index(viewer->renderers, i);

    renderer->expanded = FALSE;
    if (renderer->expander) {
      gtk_expander_set_expanded (GTK_EXPANDER (renderer->expander),
                                 renderer->expanded);
    }
  }
}

// TBD - correct location for this code?
static void on_top_view_clicked(GtkToggleToolButton *tb, void *user_data)
{<commit_msg>Basic Renderer Foviation Via Function Keys<commit_after>#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <getopt.h>
#include <iostream>

#include <bot_vis/bot_vis.h>
#include <lcm/lcm.h>
#include <bot_core/bot_core.h>
#include <path_util/path_util.h>
#include <ConciseArgs>

#include <bot_frames/bot_frames_renderers.h>

//imported renderers
#include <bot_lcmgl_render/lcmgl_bot_renderer.h>
#include <laser_utils/renderer_laser.h>
#include <image_utils/renderer_cam_thumb.h>
#include <visualization/collections_renderer.hpp>
#include <octomap_utils/renderer_octomap.h>
#include <renderer_maps/MapsRenderer.hpp>
#include <renderer_data_control/DataControlRenderer.hpp>
// #include <renderer_annotated_camera/AnnotatedCameraRenderer.hpp>
#include <multisense/multisense_renderer.h>
#include <occ_map/occ_map_renderers.h>
// Individual Renderers:
#include <renderer_drc/renderer_scrollingplots.h>
#include <renderer_drc/renderer_driving.hpp>
#include <renderer_drc/renderer_walking.hpp>
#include <renderer_drc/renderer_status.hpp>
#include <renderer_drc/renderer_drcgrid.h>
#include <renderer_drc/renderer_recovery.hpp>
#include <renderer_drc/renderer_bdi.hpp>

// block of renderers
#include <renderer_robot_state/renderer_robot_state.hpp>
#include <renderer_robot_plan/renderer_robot_plan.hpp>
#include <renderer_crawling_plan/renderer_crawling_plan.hpp>
#include <renderer_affordances/renderer_affordances.hpp>
#include <renderer_sticky_feet/renderer_sticky_feet.hpp>
#include <renderer_end_effector_goal/renderer_end_effector_goal.hpp>

#include <tracker-renderer/TrackerRenderer.hpp>


#include "udp_util.h"
#include "RendererGroupUtil.hpp"
#include <lcmtypes/drc_lcmtypes.h>
#include <visualization_utils/keyboard_signal_utils.hpp>
#include <visualization_utils/affordance_utils/aff_trigger_signal_utils.hpp>

using namespace std;
using namespace visualization_utils;

// NOTE (Sisir, 8th Jul 13): We dont want to have individual keyboard event handlers in renderers
// as designed in lib-bot as the key events can be non-unique and the key handlers can conflict. 
// Using boost::signals to create a global keyboard signal. Each renderer creates a corresponding 
// slot to handle global key events. Using a shared ptr to the boost signal. Renderers that require access
// to keyboard signals will receive the signal ref as an argument in their setup function.
KeyboardSignalRef _keyboardSignalRef = KeyboardSignalRef(new KeyboardSignal()); 
AffTriggerSignalsRef _affTriggerSignalsRef = AffTriggerSignalsRef(new AffTriggerSignals()); 

static int
logplayer_remote_on_key_press(BotViewer *viewer, BotEventHandler *ehandler,
        const GdkEventKey *event)
{
    int keyval = event->keyval;
    //std::cout << "keyval: " << keyval << "\n";
    
    // emit global keyboard signal, second argument indicates that it is a keypress (if true)
    (*_keyboardSignalRef)(keyval,true); 
    
    switch (keyval)
    {
      case 'P':
      case 'p':
          udp_send_string("127.0.0.1", 53261, "PLAYPAUSETOGGLE");
          break;
      case 'N':
      case 'n':
          udp_send_string("127.0.0.1", 53261, "STEP");
          break;
      case '=':
      case '+':
          udp_send_string("127.0.0.1", 53261, "FASTER");
          break;
      case '_':
      case '-':
          udp_send_string("127.0.0.1", 53261, "SLOWER");
          break;
      case '[':
          udp_send_string("127.0.0.1", 53261, "BACK5");
          break;
      case ']':
          udp_send_string("127.0.0.1", 53261, "FORWARD5");
          break;
      case SHIFT_L:
      case SHIFT_R:
          //std::cout << "shift pressed\n";
          break;
      default:
          return 0;
    }

    return 1;
}

static int
on_key_release(BotViewer *viewer, BotEventHandler *ehandler,
        const GdkEventKey *event)
{
    int keyval = event->keyval;
    // emit global keyboard signal, second argument indicates that it is a keyrelease (if false)
    (*_keyboardSignalRef)(keyval,false); // emit global keyboard signal
    //cout << keyval << endl;
    
    // TODO: Do this more elegantly via mouse right double click to signal broadcast to automatic renderer foviation
    string foviate_renderer = " "; // Focus view on renderers based on function keys
    
    switch (keyval)
    {
      case SHIFT_L:
      case SHIFT_R:
          //std::cout << "shift released\n";
          break;
      case ESC: 
        for (unsigned int ridx = 0; ridx < viewer->renderers->len; ridx++) {
          BotRenderer *renderer = (BotRenderer*)g_ptr_array_index(viewer->renderers, ridx);
          renderer->enabled = 1;
         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(renderer->cmi), renderer->enabled);
         }   
         break;  
      case F1:
       foviate_renderer = "Affordances & StickyHands/Feet";
       break;
      case F2:
       foviate_renderer = "Robot Plan Display";
       break;
      case F3:
       foviate_renderer = "Robot State Display"; 
       break;
      case F4:
       foviate_renderer = "Walking";
       break; 
      case F5:
       foviate_renderer = "FootStep Plans & Sticky Feet";
       break; 
      case F6:
       foviate_renderer = "Maps";
       break;
      case F7:
       foviate_renderer = "Laser";
       break;
      case F8:
       foviate_renderer = "Data Control";
       break;
    
      default:
          return 0;
    }
    
    if((keyval>=F1)&&(keyval<=F12))
    {
      cout << "\n\nRenderer Foviation Via Function Keys: \n";
      cout << "------------------------------------------\n";
      cout << "ESC-All\n";
      cout << "F1-Affordances & StickyHands/Feet\n";
      cout << "F2-Robot Plan Display\n";
      cout << "F3-Robot State Display\n";  
      cout << "F4-Walking\n";
      cout << "F5-FootStep Plans & Sticky Feet\n";
      cout << "F6-Maps\n";  
      cout << "F7-Laser\n";
      cout << "F8-DataControl\n";
    
        
        for (unsigned int ridx = 0; ridx < viewer->renderers->len; ridx++) {
          BotRenderer *renderer = (BotRenderer*)g_ptr_array_index(viewer->renderers, ridx);
          string name(renderer->name);
          bool always_enabled_renderers = ((name=="Advanced Grid")||(name=="BOT_FRAMES")||(name=="LCM GL")||(name=="System Status"));
          if((name==foviate_renderer)||always_enabled_renderers){
            renderer->enabled = 1;
            gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(renderer->cmi), renderer->enabled);
            if(name==foviate_renderer) {
              renderer->expanded = TRUE;
              gtk_expander_set_expanded (GTK_EXPANDER (renderer->expander),
                                         renderer->expanded);
            }  
          }
          else{
            renderer->enabled = 0;
            gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(renderer->cmi), renderer->enabled);
            renderer->expanded = FALSE;
            if (renderer->expander) {
              gtk_expander_set_expanded (GTK_EXPANDER (renderer->expander),
                                         renderer->expanded);
            }            
          }
         }               
    }

    return 1;
}


static void on_collapse_all_clicked(GtkToggleToolButton *tb, void *user_data)
{
  BotViewer *viewer = (BotViewer*) user_data;
  for (unsigned int i = 0; i < viewer->renderers->len; ++i) {
    BotRenderer* renderer =
      (BotRenderer*)g_ptr_array_index(viewer->renderers, i);

    renderer->expanded = FALSE;
    if (renderer->expander) {
      gtk_expander_set_expanded (GTK_EXPANDER (renderer->expander),
                                 renderer->expanded);
    }
  }
}

// TBD - correct location for this code?
static void on_top_view_clicked(GtkToggleToolButton *tb, void *user_data)
{
{'fraction_non_alphanumeric': 0.11612851662404092, 'fraction_numerical': 0.014066496163682864, 'mean_word_length': 3.117472852912142, 'pattern_counts': {'":': 0, '<': 130, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 12, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1348083', 'n_tokens_mistral': 4238, 'n_tokens_neox': 4180, 'n_words': 891}