186 lines
6.6 KiB
Python
186 lines
6.6 KiB
Python
from __future__ import annotations
|
|
from typing import Any
|
|
import bpy
|
|
from bpy.props import PointerProperty, StringProperty, FloatProperty, IntProperty, EnumProperty
|
|
|
|
from ...registry import register_class
|
|
from ...infra.blender_slice_nodes_generic import SliceNodeSocket
|
|
from ..slice import SlicePaths
|
|
|
|
from .tree import notify_tree_changed
|
|
|
|
class LabelNodeSocket(SliceNodeSocket):
|
|
default = ""
|
|
def draw(self, context: Any, layout: Any, node: Any, text: str | None):
|
|
assert layout
|
|
layout.label(text=text or self.name)
|
|
|
|
class InputNodeSocket(SliceNodeSocket):
|
|
def draw(self, context: Any, layout: Any, node: Any, text: str | None):
|
|
assert layout
|
|
if not self.is_output and self.is_linked:
|
|
layout.label(text=text or self.name)
|
|
else:
|
|
layout.prop(self, "value", text=text or self.name)
|
|
|
|
def _draw_as_ro(self, context: Any, layout: Any, node: Any, text: str | None):
|
|
layout.label(text=text or self.name)
|
|
|
|
def _draw_as_rw(self, context: Any, layout: Any, node: Any, text: str | None):
|
|
layout.prop(self, "value", text=text or self.name)
|
|
|
|
class ReadonlySocket():
|
|
def draw(self, context: Any, layout: Any, node: Any, text: str | None):
|
|
return self._draw_as_ro(context, layout, node, text) # pyright: ignore[reportAttributeAccessIssue]
|
|
|
|
@register_class
|
|
class SLICESOCK_Object(InputNodeSocket):
|
|
bl_label = "Object"
|
|
|
|
value: PointerProperty(
|
|
name="Object",
|
|
type=bpy.types.Object,
|
|
update=notify_tree_changed
|
|
) # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (0.9, 0.7, 0.2, 1.0)
|
|
|
|
|
|
class SLICESOCK_Float_Common(InputNodeSocket):
|
|
bl_label = "Float"
|
|
|
|
value: FloatProperty(name="Float", default=0, update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (161/255, 161/255, 161/255, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_FloatRo(ReadonlySocket, SLICESOCK_Float_Common): ...
|
|
@register_class
|
|
class SLICESOCK_Float(SLICESOCK_Float_Common): ...
|
|
|
|
|
|
class SLICESOCK_Int_Common(InputNodeSocket):
|
|
bl_label = "Integer"
|
|
|
|
value: IntProperty(name="Int", default=0, update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (161/255, 161/255, 161/255, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_Int(SLICESOCK_Int_Common): ...
|
|
@register_class
|
|
class SLICESOCK_IntRo(ReadonlySocket, SLICESOCK_Int_Common): ...
|
|
|
|
|
|
@register_class
|
|
class SLICESOCK_String(InputNodeSocket):
|
|
bl_label = "String"
|
|
|
|
value: StringProperty(name="String", default="", update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (0.4, 0.7, 1.0, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_FilePath(InputNodeSocket):
|
|
bl_label = "Filepath"
|
|
|
|
value: StringProperty(name="Filepath", default="", subtype='FILE_PATH', update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (0.4, 0.7, 1.0, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_VectorRotation_Common(InputNodeSocket):
|
|
bl_label = "VectorRotation"
|
|
|
|
value: bpy.props.FloatVectorProperty(name="Vector", size=3, default=(0.0, 0.0, 0.0), subtype='EULER', update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (0.39, 0.39, 0.78, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_VectorRotation(SLICESOCK_VectorRotation_Common): ...
|
|
@register_class
|
|
class SLICESOCK_VectorRotationRo(ReadonlySocket, SLICESOCK_VectorRotation_Common): ...
|
|
|
|
@register_class
|
|
class SLICESOCK_Mesh(LabelNodeSocket):
|
|
bl_label = "Mesh"
|
|
default = None
|
|
bl_color = (0, 214/255, 163/255, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_Paths(LabelNodeSocket):
|
|
bl_label = "Paths"
|
|
default = SlicePaths()
|
|
bl_color = (214/255, 0, 120/255, 1.0)
|
|
|
|
class SLICESOCK_Gcode_Common(InputNodeSocket):
|
|
bl_label = "Gcode"
|
|
value: StringProperty(name="Gcode", default="", update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (1., 1., 1., 1.)
|
|
|
|
@register_class
|
|
class SLICESOCK_Gcode(SLICESOCK_Gcode_Common): ...
|
|
@register_class
|
|
class SLICESOCK_GcodeRo(ReadonlySocket, SLICESOCK_Gcode_Common): ...
|
|
|
|
@register_class
|
|
class SLICESOCK_Intrinsics(LabelNodeSocket):
|
|
bl_label = "Intrinsics"
|
|
default = None
|
|
bl_color = (0.2, 0.2, 0.2, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_PrusaslicerConf(LabelNodeSocket):
|
|
bl_label = "PrusaSlicer Config"
|
|
default = None
|
|
bl_color = (0.95, 0.42, 0.13, 1.0) # #F26C21
|
|
|
|
@register_class
|
|
class SLICESOCK_ExecutionLink(LabelNodeSocket):
|
|
bl_label = "Execution Link"
|
|
default = None
|
|
bl_color = (0.5, 0.0, 0.5, 1.0) # Purple
|
|
|
|
@register_class
|
|
class SLICESOCK_Printer(InputNodeSocket):
|
|
bl_label = "Printer"
|
|
|
|
host: StringProperty(name="Host", default="localhost", update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
port: IntProperty(name="Port", default=80, min=1, max=65535, update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
prefix: StringProperty(name="Prefix", default="", update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
label: StringProperty(name="Label", default="Printer", update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
username: StringProperty(name="Username", default="", update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
password: StringProperty(name="Password", default="", subtype='PASSWORD', update=notify_tree_changed) # pyright: ignore[reportInvalidTypeForm]
|
|
|
|
host_type: EnumProperty(
|
|
name="Type",
|
|
items=[
|
|
('PRUSALINK', "PrusaLink", "PrusaLink API"),
|
|
('CREALITY', "Creality", "Creality Cloud API"),
|
|
('MOONRAKER', "Moonraker", "Moonraker (Klipper) API"),
|
|
],
|
|
default='PRUSALINK',
|
|
update=notify_tree_changed
|
|
) # pyright: ignore[reportInvalidTypeForm]
|
|
|
|
bl_color = (1.0, 0.45, 0.1, 1.0) # Orange
|
|
|
|
def draw(self, context, layout, node, text):
|
|
if self.is_output or self.is_linked:
|
|
layout.label(text=text or self.name)
|
|
else:
|
|
col = layout.column(align=True)
|
|
col.prop(self, "label", text="")
|
|
col.prop(self, "host_type", text="")
|
|
col.prop(self, "host")
|
|
col.prop(self, "port")
|
|
col.prop(self, "prefix")
|
|
col.prop(self, "username")
|
|
col.prop(self, "password")
|
|
|
|
@property
|
|
def value(self) -> Any:
|
|
from ...infra.printer_backends import PrinterConfig
|
|
return PrinterConfig(
|
|
host=self.host,
|
|
port=self.port,
|
|
prefix=self.prefix,
|
|
label=self.label,
|
|
username=self.username,
|
|
password=self.password,
|
|
host_type=self.host_type
|
|
)
|