<commit_before>//Copyright (c) 2018 <NAME>.
//CuraEngine is released under the terms of the AGPLv3 or higher.

#ifdef ARCUS

#include <Arcus/Socket.h> //The socket to communicate to.
#include <sstream> //For ostringstream.
#include <thread> //To sleep while waiting for the connection.
#include <unordered_map> //To map settings to their extruder numbers for limit_to_extruder.

#include "ArcusCommunication.h"
#include "Listener.h" //To listen to the Arcus socket.
#include "SliceDataStruct.h" //To store sliced layer data.
#include "../Application.h" //To get and set the current slice command.
#include "../FffProcessor.h" //To start a slice.
#include "../PrintFeature.h"
#include "../Slice.h" //To process slices.
#include "../settings/types/LayerIndex.h" //To point to layers.
#include "../settings/types/Velocity.h" //To send to layer view how fast stuff is printing.
#include "../utils/logoutput.h"

namespace cura
{

//Forward declarations for compilation speed.
class MeshGroup;

class ArcusCommunication::Private
{
public:
    Private()
        : socket(nullptr)
        , object_count(0)
        , last_sent_progress(-1)
        , slice_count(0)
    { }

    /*
     * Get the optimised layer data for a specific layer.
     * \param layer_nr The layer number to get the optimised layer data for.
     * \return The optimised layer data for that layer.
     */
    std::shared_ptr<cura::proto::LayerOptimized> getOptimizedLayerById(LayerIndex layer_nr)
    {
        layer_nr += optimized_layers.current_layer_offset;
        std::unordered_map<int, std::shared_ptr<proto::LayerOptimized>>::iterator find_result = optimized_layers.slice_data.find(layer_nr);

        if (find_result != optimized_layers.slice_data.end()) //Load layer from the cache.
        {
            return find_result->second;
        }
        else //Not in the cache yet. Create an empty layer.
        {
            std::shared_ptr<proto::LayerOptimized> layer = std::make_shared<proto::LayerOptimized>();
            layer->set_id(layer_nr);
            optimized_layers.current_layer_count++;
            optimized_layers.slice_data[layer_nr] = layer;
            return layer;
        }
    }

    /*
     * Reads the global settings from a Protobuf message.
     *
     * The global settings are stored in the current scene.
     * \param global_settings_message The global settings message.
     */
    void readGlobalSettingsMessage(const cura::proto::SettingList& global_settings_message)
    {
        Slice* slice = Application::getInstance().current_slice;
        for (const cura::proto::Setting& setting_message : global_settings_message.settings())
        {
            slice->scene.settings.add(setting_message.name(), setting_message.value());
        }
    }
    
    void readExtruderSettingsMessage(const google::protobuf::RepeatedPtrField<cura::proto::Extruder>& extruder_message)
    {
        Slice* slice = Application::getInstance().current_slice;
        const size_t extruder_count = slice->scene.settings.get<size_t>("machine_extruder_count");
        for (size_t extruder_nr = 0; extruder_nr < extruder_count; extruder_nr++)
        {
            slice->scene.extruders.emplace_back(extruder_nr, &slice->scene.settings);
        }
        for (const cura::proto::Extruder& extruder_message : extruder_message)
        {
            const int32_t extruder_nr = extruder_message.id(); //Cast from proto::int to int32_t!
            if (extruder_nr < 0 || extruder_nr >= static_cast<int32_t>(extruder_count))
            {
                logWarning("Received extruder index that is out of range: %i", extruder_nr);
                continue;<commit_msg>Disambiguate variable names<commit_after>//Copyright (c) 2018 <NAME>.
//CuraEngine is released under the terms of the AGPLv3 or higher.

#ifdef ARCUS

#include <Arcus/Socket.h> //The socket to communicate to.
#include <sstream> //For ostringstream.
#include <thread> //To sleep while waiting for the connection.
#include <unordered_map> //To map settings to their extruder numbers for limit_to_extruder.

#include "ArcusCommunication.h"
#include "Listener.h" //To listen to the Arcus socket.
#include "SliceDataStruct.h" //To store sliced layer data.
#include "../Application.h" //To get and set the current slice command.
#include "../FffProcessor.h" //To start a slice.
#include "../PrintFeature.h"
#include "../Slice.h" //To process slices.
#include "../settings/types/LayerIndex.h" //To point to layers.
#include "../settings/types/Velocity.h" //To send to layer view how fast stuff is printing.
#include "../utils/logoutput.h"

namespace cura
{

//Forward declarations for compilation speed.
class MeshGroup;

class ArcusCommunication::Private
{
public:
    Private()
        : socket(nullptr)
        , object_count(0)
        , last_sent_progress(-1)
        , slice_count(0)
    { }

    /*
     * Get the optimised layer data for a specific layer.
     * \param layer_nr The layer number to get the optimised layer data for.
     * \return The optimised layer data for that layer.
     */
    std::shared_ptr<cura::proto::LayerOptimized> getOptimizedLayerById(LayerIndex layer_nr)
    {
        layer_nr += optimized_layers.current_layer_offset;
        std::unordered_map<int, std::shared_ptr<proto::LayerOptimized>>::iterator find_result = optimized_layers.slice_data.find(layer_nr);

        if (find_result != optimized_layers.slice_data.end()) //Load layer from the cache.
        {
            return find_result->second;
        }
        else //Not in the cache yet. Create an empty layer.
        {
            std::shared_ptr<proto::LayerOptimized> layer = std::make_shared<proto::LayerOptimized>();
            layer->set_id(layer_nr);
            optimized_layers.current_layer_count++;
            optimized_layers.slice_data[layer_nr] = layer;
            return layer;
        }
    }

    /*
     * Reads the global settings from a Protobuf message.
     *
     * The global settings are stored in the current scene.
     * \param global_settings_message The global settings message.
     */
    void readGlobalSettingsMessage(const cura::proto::SettingList& global_settings_message)
    {
        Slice* slice = Application::getInstance().current_slice;
        for (const cura::proto::Setting& setting_message : global_settings_message.settings())
        {
            slice->scene.settings.add(setting_message.name(), setting_message.value());
        }
    }
    
    void readExtruderSettingsMessage(const google::protobuf::RepeatedPtrField<cura::proto::Extruder>& extruder_messages)
    {
        Slice* slice = Application::getInstance().current_slice;
        const size_t extruder_count = slice->scene.settings.get<size_t>("machine_extruder_count");
        for (size_t extruder_nr = 0; extruder_nr < extruder_count; extruder_nr++)
        {
            slice->scene.extruders.emplace_back(extruder_nr, &slice->scene.settings);
        }
        for (const cura::proto::Extruder& extruder_message : extruder_messages)
        {
            const int32_t extruder_nr = extruder_message.id(); //Cast from proto::int to int32_t!
            if (extruder_nr < 0 || extruder_nr >= static_cast<int32_t>(extruder_count))
            {
                logWarning("Received extruder index that is out of range: %i", extruder_nr);
                continue;
{'fraction_non_alphanumeric': 0.11026408930029949, 'fraction_numerical': 0.004356112169888375, 'mean_word_length': 3.0213464696223316, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 43, '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': '3003886', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2121, 'n_words': 559}