<commit_before>#include <gameplay/GameplayModule.hpp>
#include "MainWindow.hpp"
#include "Configuration.hpp"
#include "radio/Radio.hpp"
#include <Utils.hpp>
#include <Robot.hpp>
#include <joystick/Joystick.hpp>
#include "RobotStatusWidget.hpp"
#include "BatteryProfile.hpp"
#include <Network.hpp>
#include "git_version.hpp"

#include <QInputDialog>
#include <QFileDialog>
#include <QActionGroup>
#include <QMessageBox>

#include <QFile>
#include <QDir>
#include <QDateTime>
#include <QString>

#include <iostream>
#include <ctime>
#include <string>

#include <google/protobuf/descriptor.h>

using namespace std;
using namespace boost;
using namespace google::protobuf;
using namespace Packet;
using namespace Eigen;

static const std::vector<QString> defaultHiddenLayers{
    "MotionControl", "Global Obstacles", "Local Obstacles",
    "Planning0",     "Planning1",        "Planning2",
    "Planning3",     "Planning4",        "Planning5"};

void calcMinimumWidth(QWidget* widget, QString text) {
    QRect rect = QFontMetrics(widget->font()).boundingRect(text);
    widget->setMinimumWidth(rect.width());
}

MainWindow::MainWindow(Processor* processor, QWidget* parent)
    : QMainWindow(parent),
      _updateCount(0),
      _autoExternalReferee(true),
      _doubleFrameNumber(-1),
      _lastUpdateTime(RJ::now()),
      _history(2 * 60),
      _processor(processor) {
    qRegisterMetaType<QVector<int>>("QVector<int>");

    _ui.setupUi(this);
    _ui.fieldView->history(&_history);

    _ui.logTree->history(&_history);
    _ui.logTree->mainWindow = this;
    _ui.logTree->updateTimer = &updateTimer;

    // Initialize live/non-live control styles

    _currentPlay = new QLabel(this);
    _currentPlay->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
    _currentPlay->setToolTip("Current Play");
    _currentPlay->setAlignment(Qt::AlignCenter);
    _currentPlay->setObjectName("current_play_name");
    calcMinimumWidth(_currentPlay, "XXXXXXXXXXXXXXXX");
    statusBar()->addPermanentWidget(_currentPlay);

    _logFile = new QLabel(this);
    _logFile->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
    _logFile->setToolTip("Log File");
    statusBar()->addPermanentWidget(_logFile);

    _viewFPS = new QLabel(this);
    _viewFPS->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
    _viewFPS->setToolTip("Display Framerate");
    calcMinimumWidth(_viewFPS, "View: 00.0 fps");
    statusBar()->addPermanentWidget(_viewFPS);

    _procFPS = new QLabel(this);
    _procFPS->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
    _procFPS->setToolTip("Processing Framerate");
    calcMinimumWidth(_procFPS, "Proc: 00.0 fps");
    statusBar()->addPermanentWidget(_procFPS);

    _logMemory = new QLabel(this);
    _logMemory->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
    _logMemory->setToolTip("Log Memory Usage");
    _logMemory->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    calcMinimumWidth(_logMemory, "Log: 000000/000000 000000 kiB");
    statusBar()->addPermanentWidget(_logMemory);

    _frameNumberItem = new QTreeWidgetItem(_ui.logTree);
    _frameNumberItem->setText(ProtobufTree::Column_Field, "Frame");
    _frameNumberItem->setData(ProtobufTree::Column_Tag, Qt::DisplayRole, -2);

    _elapsedTimeItem = new QTreeWidgetItem(_ui.logTree);
    _elapsedTimeItem->setText(ProtobufTree::Column_Field, "Elapsed Time");
    _elapsedTimeItem->setData(ProtobufTree::Column_Tag, Qt::DisplayRole, -1);

    _ui.debugLayers->setContextMenuPolicy(Qt::CustomContextMenu);

    QActionGroup* teamGroup = new QActionGroup(this);
    teamGroup->addAction(_ui.actionTeamBlue);
    teamGroup->addAction(_ui.actionTeamYellow);
    qActionGroups.push_back(teamGroup);

    QActionGroup* goalGroup = new QActionGroup(this);
    goalGroup->addAction(_ui.actionDefendMinusX);
    goalGroup->addAction(_ui.actionDefendPlusX);
    qActionGroups.push_back(goalGroup);

    QActionGroup* rotateGroup = new QActionGroup(this);
    rotateGroup->addAction(_ui.action0);
    rotateGroup->addAction(_ui.action90);
    rotateGroup->addAction(_ui.action180);
    rotateGroup->addAction(_ui.action270);
    qActionGroups.push_back(rotateGroup);

    auto visionChannelGroup = new QActionGroup(this);
    visionChannelGroup->addAction(_ui.actionVisionPrimary_Half);
    visionChannelGroup->addAction(_ui.actionVisionSecondary_Half);
    visionChannelGroup->addAction(_ui.actionVisionFull_Field);
    qActionGroups.push_back(visionChannelGroup);

    auto radioGroup = new QActionGroup(this);
    radioGroup->addAction(_ui.action916MHz);
    radioGroup->addAction(_ui.action918MHz);
    qActionGroups.push_back(radioGroup);

    connect(_ui.manualID, SIGNAL(currentIndexChanged(int)), this,
            SLOT(on_manualID_currentIndexChanged(int)));

    //    channel(0);

    // put all log playback buttons into a vector for easy access later
    _logPlaybackButtons.push_back(_ui.logPlaybackRewind);
    _logPlaybackButtons.push_back(_ui.logPlaybackPrevFrame);
    _logPlaybackButtons.push_back(_ui.logPlaybackPause);
    _logPlaybackButtons.push_back(_ui.logPlaybackNextFrame);
    _logPlaybackButtons.push_back(_ui.logPlaybackPlay);
    _logPlaybackButtons.push_back(_ui.logPlaybackLive);

    // Get the item model from the goalieID boxes so we can disable them
    // properly
    goalieModel =
        qobject_cast<const QStandardItemModel*>(_ui.goalieID->model());

    // Append short Git hash to the main window title with an asterisk if the
    // current Git index is dirty
    setWindowTitle(windowTitle() + " @ " + git_version_short_hash +
                   (git_version_dirty ? "*" : ""));
}

void MainWindow::configuration(Configuration* config) {<commit_msg>Simulator dropdown menu is now disabled when not in simulation<commit_after>#include <gameplay/GameplayModule.hpp>
#include "MainWindow.hpp"
#include "Configuration.hpp"
#include "radio/Radio.hpp"
#include <Utils.hpp>
#include <Robot.hpp>
#include <joystick/Joystick.hpp>
#include "RobotStatusWidget.hpp"
#include "BatteryProfile.hpp"
#include <Network.hpp>
#include "git_version.hpp"

#include <QInputDialog>
#include <QFileDialog>
#include <QActionGroup>
#include <QMessageBox>

#include <QFile>
#include <QDir>
#include <QDateTime>
#include <QString>

#include <iostream>
#include <ctime>
#include <string>

#include <google/protobuf/descriptor.h>

using namespace std;
using namespace boost;
using namespace google::protobuf;
using namespace Packet;
using namespace Eigen;

static const std::vector<QString> defaultHiddenLayers{
    "MotionControl", "Global Obstacles", "Local Obstacles",
    "Planning0",     "Planning1",        "Planning2",
    "Planning3",     "Planning4",        "Planning5"};

void calcMinimumWidth(QWidget* widget, QString text) {
    QRect rect = QFontMetrics(widget->font()).boundingRect(text);
    widget->setMinimumWidth(rect.width());
}

MainWindow::MainWindow(Processor* processor, QWidget* parent)
    : QMainWindow(parent),
      _updateCount(0),
      _autoExternalReferee(true),
      _doubleFrameNumber(-1),
      _lastUpdateTime(RJ::now()),
      _history(2 * 60),
      _processor(processor) {
    qRegisterMetaType<QVector<int>>("QVector<int>");

    _ui.setupUi(this);
    _ui.fieldView->history(&_history);

    _ui.logTree->history(&_history);
    _ui.logTree->mainWindow = this;
    _ui.logTree->updateTimer = &updateTimer;

    // Initialize live/non-live control styles

    _currentPlay = new QLabel(this);
    _currentPlay->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
    _currentPlay->setToolTip("Current Play");
    _currentPlay->setAlignment(Qt::AlignCenter);
    _currentPlay->setObjectName("current_play_name");
    calcMinimumWidth(_currentPlay, "XXXXXXXXXXXXXXXX");
    statusBar()->addPermanentWidget(_currentPlay);

    _logFile = new QLabel(this);
    _logFile->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
    _logFile->setToolTip("Log File");
    statusBar()->addPermanentWidget(_logFile);

    _viewFPS = new QLabel(this);
    _viewFPS->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
    _viewFPS->setToolTip("Display Framerate");
    calcMinimumWidth(_viewFPS, "View: 00.0 fps");
    statusBar()->addPermanentWidget(_viewFPS);

    _procFPS = new QLabel(this);
    _procFPS->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
    _procFPS->setToolTip("Processing Framerate");
    calcMinimumWidth(_procFPS, "Proc: 00.0 fps");
    statusBar()->addPermanentWidget(_procFPS);

    _logMemory = new QLabel(this);
    _logMemory->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
    _logMemory->setToolTip("Log Memory Usage");
    _logMemory->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    calcMinimumWidth(_logMemory, "Log: 000000/000000 000000 kiB");
    statusBar()->addPermanentWidget(_logMemory);

    _frameNumberItem = new QTreeWidgetItem(_ui.logTree);
    _frameNumberItem->setText(ProtobufTree::Column_Field, "Frame");
    _frameNumberItem->setData(ProtobufTree::Column_Tag, Qt::DisplayRole, -2);

    _elapsedTimeItem = new QTreeWidgetItem(_ui.logTree);
    _elapsedTimeItem->setText(ProtobufTree::Column_Field, "Elapsed Time");
    _elapsedTimeItem->setData(ProtobufTree::Column_Tag, Qt::DisplayRole, -1);

    _ui.debugLayers->setContextMenuPolicy(Qt::CustomContextMenu);

    QActionGroup* teamGroup = new QActionGroup(this);
    teamGroup->addAction(_ui.actionTeamBlue);
    teamGroup->addAction(_ui.actionTeamYellow);
    qActionGroups.push_back(teamGroup);

    QActionGroup* goalGroup = new QActionGroup(this);
    goalGroup->addAction(_ui.actionDefendMinusX);
    goalGroup->addAction(_ui.actionDefendPlusX);
    qActionGroups.push_back(goalGroup);

    QActionGroup* rotateGroup = new QActionGroup(this);
    rotateGroup->addAction(_ui.action0);
    rotateGroup->addAction(_ui.action90);
    rotateGroup->addAction(_ui.action180);
    rotateGroup->addAction(_ui.action270);
    qActionGroups.push_back(rotateGroup);

    auto visionChannelGroup = new QActionGroup(this);
    visionChannelGroup->addAction(_ui.actionVisionPrimary_Half);
    visionChannelGroup->addAction(_ui.actionVisionSecondary_Half);
    visionChannelGroup->addAction(_ui.actionVisionFull_Field);
    qActionGroups.push_back(visionChannelGroup);

    auto radioGroup = new QActionGroup(this);
    radioGroup->addAction(_ui.action916MHz);
    radioGroup->addAction(_ui.action918MHz);
    qActionGroups.push_back(radioGroup);

    connect(_ui.manualID, SIGNAL(currentIndexChanged(int)), this,
            SLOT(on_manualID_currentIndexChanged(int)));

    //    channel(0);

    // put all log playback buttons into a vector for easy access later
    _logPlaybackButtons.push_back(_ui.logPlaybackRewind);
    _logPlaybackButtons.push_back(_ui.logPlaybackPrevFrame);
    _logPlaybackButtons.push_back(_ui.logPlaybackPause);
    _logPlaybackButtons.push_back(_ui.logPlaybackNextFrame);
    _logPlaybackButtons.push_back(_ui.logPlaybackPlay);
    _logPlaybackButtons.push_back(_ui.logPlaybackLive);

    // Get the item model from the goalieID boxes so we can disable them
    // properly
    goalieModel =
        qobject_cast<const QStandardItemModel*>(_ui.goalieID->model());

    // Append short Git hash to the main window title with an asterisk if the
    // current Git index is dirty
    setWindowTitle(windowTitle() + " @ " + git_version_short_hash +
                   (git_version_dirty ? "*" : ""));

    if (!_processor->simulation()) {
        _ui.menu_Simulator->setEnabled(false);
    }
}

void MainWindow::configuration(Configuration* config) {
{'fraction_non_alphanumeric': 0.1242629205688519, 'fraction_numerical': 0.009191814082552896, 'mean_word_length': 5.092445853143159, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4081504', 'n_tokens_mistral': 3784, 'n_tokens_neox': 3605, 'n_words': 592}