From cccfebcc8edfc370a593885d2e67aa5f8fc078fc Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Fri, 19 May 2023 13:33:05 +0200 Subject: [PATCH] Allow Cura front-end to set plugins (port & address) This can currently be done by setting the environment variables: - SIMPLIFY_ENABLE: default disabled, setting this to any value will enable the plugin - SIMPLIFY_ADDRESS: defaults to localhost - SIMPLIFY_PORT: defaults to 33700 - POSTPROCESS_ENABLE: default disabled, setting this to any value will enable the plugin - POSTPROCESS_ADDRESS: defaults to localhost - POSTPROCESS_PORT: defaults to 33701 Hacky for now Contributes to CURA-10475 --- plugins/CuraEngineBackend/Cura.proto | 13 +++++++++++++ plugins/CuraEngineBackend/StartSliceJob.py | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/plugins/CuraEngineBackend/Cura.proto b/plugins/CuraEngineBackend/Cura.proto index b420a6ecc2..4953531a64 100644 --- a/plugins/CuraEngineBackend/Cura.proto +++ b/plugins/CuraEngineBackend/Cura.proto @@ -8,12 +8,25 @@ message ObjectList repeated Setting settings = 2; // meshgroup settings (for one-at-a-time printing) } +enum SlotID { + SIMPLIFY = 0; + POSTPROCESS = 1; +} + +message EnginePlugin +{ + SlotID id = 1; + optional string address = 2; + optional uint32 port = 3; +} + message Slice { repeated ObjectList object_lists = 1; // The meshgroups to be printed one after another SettingList global_settings = 2; // The global settings used for the whole print job repeated Extruder extruders = 3; // The settings sent to each extruder object repeated SettingExtruder limit_to_extruder = 4; // From which stack the setting would inherit if not defined per object + repeated EnginePlugin engine_plugins = 5; } message Extruder diff --git a/plugins/CuraEngineBackend/StartSliceJob.py b/plugins/CuraEngineBackend/StartSliceJob.py index d06136a2b4..4f320a3a79 100644 --- a/plugins/CuraEngineBackend/StartSliceJob.py +++ b/plugins/CuraEngineBackend/StartSliceJob.py @@ -1,5 +1,6 @@ # Copyright (c) 2021-2022 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +import os import numpy from string import Formatter @@ -301,6 +302,22 @@ class StartSliceJob(Job): for extruder_stack in global_stack.extruderList: self._buildExtruderMessage(extruder_stack) + # EnginePlugins + # TODO: don't hardcode them + # Ports: are chosen based on https://stackoverflow.com/questions/10476987/best-tcp-port-number-range-for-internal-applications + + plugins = { + 0: {"address": os.environ.get("SIMPLIFY_ADDRESS", "localhost"), "port": os.environ.get("SIMPLIFY_PORT", 33700)} if os.environ.get("SIMPLIFY_ENABLE") is not None else None, + 1: {"address": os.environ.get("POSTPROCESS_ADDRESS", "localhost"), "port": os.environ.get("POSTPROCESS_PORT", 33701)} if os.environ.get("POSTPROCESS_ENABLE") is not None else None, + } + + for plugin, connection in plugins.items(): + plugin_message = self._slice_message.addRepeatedMessage("engine_plugins") + plugin_message.id = plugin + if connection: + plugin_message.address = connection["address"] + plugin_message.port = connection["port"] + for group in filtered_object_groups: group_message = self._slice_message.addRepeatedMessage("object_lists") parent = group[0].getParent()