<commit_before>#include "ui/simulation_scene.hpp"

#include "engine/simulation_instance.hpp"

#include "ui/connection_item.hpp"
#include "ui/station_item.hpp"

#include <QKeyEvent>


SimulationScene::SimulationScene(QObject* parent)
 : QGraphicsScene(parent)
 , m_newConnection(nullptr)
{
}

SimulationScene::~SimulationScene()
{
}

void SimulationScene::clear()
{
    QList<QGraphicsItem*> items = QGraphicsScene::items();
    for (QGraphicsItem* item : items)
    {
        removeItem(item);
        delete item;
    }

    m_connectionItems.clear();
    m_stationItems.clear();
}

void SimulationScene::setSimulationInstance(const SimulationInstance& simulationInstance)
{
    clear();

    for (const Station& station : simulationInstance.stations)
    {
        addStation(station);
    }

    for (const Connection& connection : simulationInstance.connections)
    {
        addConnection(connection);
    }
}

void SimulationScene::addStation(const Station& station)
{
    Q_ASSERT(getStationItemById(station.id) == nullptr);

    StationItem* stationItem = new StationItem(station);
    addItem(stationItem);
    stationItem->setPos(station.position);
    m_stationItems.append(stationItem);
}

void SimulationScene::addConnection(const Connection& connection)
{
    Q_ASSERT(getConnectionItemByIds(connection.from, connection.to) == nullptr);

    StationItem* source = getStationItemById(connection.from);
    Q_ASSERT(source != nullptr);

    StationItem* destination = getStationItemById(connection.to);
    Q_ASSERT(destination != nullptr);

    ConnectionItem* connectionItem = new ConnectionItem(source, destination);
    addItem(connectionItem);

    m_connectionItems.append(connectionItem);<commit_msg>Fix bug with connection weight in interface<commit_after>#include "ui/simulation_scene.hpp"

#include "engine/simulation_instance.hpp"

#include "ui/connection_item.hpp"
#include "ui/station_item.hpp"

#include <QKeyEvent>


SimulationScene::SimulationScene(QObject* parent)
 : QGraphicsScene(parent)
 , m_newConnection(nullptr)
{
}

SimulationScene::~SimulationScene()
{
}

void SimulationScene::clear()
{
    QList<QGraphicsItem*> items = QGraphicsScene::items();
    for (QGraphicsItem* item : items)
    {
        removeItem(item);
        delete item;
    }

    m_connectionItems.clear();
    m_stationItems.clear();
}

void SimulationScene::setSimulationInstance(const SimulationInstance& simulationInstance)
{
    clear();

    for (const Station& station : simulationInstance.stations)
    {
        addStation(station);
    }

    for (const Connection& connection : simulationInstance.connections)
    {
        addConnection(connection);
    }
}

void SimulationScene::addStation(const Station& station)
{
    Q_ASSERT(getStationItemById(station.id) == nullptr);

    StationItem* stationItem = new StationItem(station);
    addItem(stationItem);
    stationItem->setPos(station.position);
    m_stationItems.append(stationItem);
}

void SimulationScene::addConnection(const Connection& connection)
{
    Q_ASSERT(getConnectionItemByIds(connection.from, connection.to) == nullptr);

    StationItem* source = getStationItemById(connection.from);
    Q_ASSERT(source != nullptr);

    StationItem* destination = getStationItemById(connection.to);
    Q_ASSERT(destination != nullptr);

    ConnectionItem* connectionItem = new ConnectionItem(source, destination);
    connectionItem->updateWeight(connection.weight);
    addItem(connectionItem);

    m_connectionItems.append(connectionItem);
{'fraction_non_alphanumeric': 0.11126880499574227, 'fraction_numerical': 0.0, 'mean_word_length': 4.9326599326599325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '746566', 'n_tokens_mistral': 1019, 'n_tokens_neox': 1002, 'n_words': 172}