254 lines
8.6 KiB
Python
254 lines
8.6 KiB
Python
from __future__ import annotations
|
|
from typing import Any
|
|
import bpy
|
|
from bpy.props import CollectionProperty
|
|
from .bpy_ns_types import NfStringProperty, NfFloatProperty, NfIntProperty, NfEnumProperty, NfPointerProperty, NfFloatVectorProperty
|
|
|
|
from ...registry import register_class
|
|
from ...infra.blender.blender_slice_nodes_generic import SliceNodeSocket
|
|
from ..slice import SlicePaths
|
|
|
|
from .bpy_ns_types 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 node and isinstance(node, bpy.types.NodeCustomGroup):
|
|
if self.is_output or self.is_linked:
|
|
layout.label(text=text or self.name)
|
|
else:
|
|
self._draw_prop(text, layout)
|
|
return
|
|
|
|
if not self.is_output and self.is_linked:
|
|
layout.label(text=text or self.name)
|
|
else:
|
|
self._draw_prop(text, layout)
|
|
|
|
def _draw_prop(self, text, layout):
|
|
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]
|
|
|
|
class SLICESOCK_ObjectCommon(InputNodeSocket):
|
|
bl_label = "Object"
|
|
|
|
value: NfPointerProperty(
|
|
name="Object",
|
|
type=bpy.types.Object,
|
|
update=notify_tree_changed
|
|
) # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (0.9, 0.7, 0.2, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_ObjectRo(ReadonlySocket, SLICESOCK_ObjectCommon): ...
|
|
@register_class
|
|
class SLICESOCK_Object(SLICESOCK_ObjectCommon): ...
|
|
|
|
class SLICESOCK_Float_Common(InputNodeSocket):
|
|
bl_label = "Float"
|
|
|
|
value: NfFloatProperty(name="Float", default=0) # 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: NfIntProperty(name="Int", default=0) # 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: NfStringProperty(name="String", default="") # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (0.4, 0.7, 1.0, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_FilePath(InputNodeSocket):
|
|
bl_label = "Filepath"
|
|
|
|
value: NfStringProperty(name="Filepath", default="", subtype='FILE_PATH') # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (0.4, 0.7, 1.0, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_DirPath(InputNodeSocket):
|
|
bl_label = "Filepath"
|
|
|
|
value: NfStringProperty(name="Folder", default="", subtype='DIR_PATH') # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (0.4, 0.7, 1.0, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_VectorRotation_Common(InputNodeSocket):
|
|
bl_label = "VectorRotation"
|
|
|
|
value: NfFloatVectorProperty(name="Vector", size=3, default=(0.0, 0.0, 0.0), subtype='EULER') # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (166/255, 99/255, 199/255, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_VectorRotation(SLICESOCK_VectorRotation_Common): ...
|
|
@register_class
|
|
class SLICESOCK_VectorRotationRo(ReadonlySocket, SLICESOCK_VectorRotation_Common): ...
|
|
|
|
@register_class
|
|
class SLICESOCK_Vector_Common(InputNodeSocket):
|
|
bl_label = "Vector"
|
|
|
|
value: NfFloatVectorProperty(name="Vector", size=3, default=(0.0, 0.0, 0.0)) # pyright: ignore[reportInvalidTypeForm]
|
|
bl_color = (0.39, 0.39, 0.78, 1.0)
|
|
|
|
@register_class
|
|
class SLICESOCK_Vector(SLICESOCK_Vector_Common): ...
|
|
@register_class
|
|
class SLICESOCK_VectorRo(ReadonlySocket, SLICESOCK_Vector_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: NfStringProperty(name="Gcode", default="") # 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., 0., 1.0) # #F26C21
|
|
|
|
@register_class
|
|
class SettingItem(bpy.types.PropertyGroup):
|
|
field: NfStringProperty(name="Field", default="") # pyright: ignore[reportInvalidTypeForm]
|
|
value_str: NfStringProperty(name="Value", default="") # pyright: ignore[reportInvalidTypeForm]
|
|
|
|
@property
|
|
def is_active(self):
|
|
return bool(self.field) or bool(self.value_str)
|
|
|
|
def draw_item(self, layout):
|
|
row = layout.row(align=True)
|
|
row.prop(self, "field", text="")
|
|
row.prop(self, "value_str", text="")
|
|
|
|
from ...infra.blender.mixins import CollectionMixin
|
|
class SLICESOCK_Settings_Common(CollectionMixin, InputNodeSocket):
|
|
bl_label = "Settings"
|
|
|
|
items: CollectionProperty(type=SettingItem) # pyright: ignore[reportInvalidTypeForm]
|
|
|
|
bl_color = (1.0, 1.0, 0.0, 1.0) # Yellow
|
|
|
|
@property
|
|
def value(self) -> dict[str, str]:
|
|
overrides = {}
|
|
for item in self.items:
|
|
if item.field:
|
|
overrides[item.field] = item.value_str
|
|
return overrides
|
|
|
|
@register_class
|
|
class SLICESOCK_Settings(SLICESOCK_Settings_Common): ...
|
|
@register_class
|
|
class SLICESOCK_SettingsRo(ReadonlySocket, SLICESOCK_Settings_Common): ...
|
|
|
|
@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: NfStringProperty(name="Host", default="localhost") # pyright: ignore[reportInvalidTypeForm]
|
|
port: NfIntProperty(name="Port", default=80, min=1, max=65535) # pyright: ignore[reportInvalidTypeForm]
|
|
prefix: NfStringProperty(name="Prefix", default="") # pyright: ignore[reportInvalidTypeForm]
|
|
label: NfStringProperty(name="Label", default="Printer") # pyright: ignore[reportInvalidTypeForm]
|
|
username: NfStringProperty(name="Username", default="") # pyright: ignore[reportInvalidTypeForm]
|
|
password: NfStringProperty(name="Password", default="", subtype='PASSWORD') # pyright: ignore[reportInvalidTypeForm]
|
|
|
|
host_type: NfEnumProperty(
|
|
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.networking.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
|
|
)
|