From 89087e7ec95b42d2b5a749b9c7daeb6cb0507aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sofus=20Albert=20H=C3=B8gsbro=20Rose?= Date: Mon, 19 Feb 2024 16:03:32 +0100 Subject: [PATCH] feat: Added accel socket, fixed default units. --- .../node_trees/maxwell_sim_nodes/contracts.py | 6 ++--- .../sockets/physical/accel_socket.py | 27 +++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/blender_maxwell/node_trees/maxwell_sim_nodes/contracts.py b/blender_maxwell/node_trees/maxwell_sim_nodes/contracts.py index 6a5c06f..6a55df7 100644 --- a/blender_maxwell/node_trees/maxwell_sim_nodes/contracts.py +++ b/blender_maxwell/node_trees/maxwell_sim_nodes/contracts.py @@ -221,7 +221,7 @@ SocketType_to_units = { }, SocketType.PhysicalMass: { - "default": "UM", + "default": "UG", "values": { "E_REST": spu.electron_rest_mass, "DAL": spu.dalton, @@ -234,7 +234,7 @@ SocketType_to_units = { }, SocketType.PhysicalSpeed: { - "default": "UM", + "default": "UM_S", "values": { "PM_S": spu.picometer / spu.second, "NM_S": spu.nanometer / spu.second, @@ -248,7 +248,7 @@ SocketType_to_units = { }, }, SocketType.PhysicalAccel: { - "default": "UM", + "default": "UM_S_SQ", "values": { "PM_S_SQ": spu.picometer / spu.second**2, "NM_S_SQ": spu.nanometer / spu.second**2, diff --git a/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/accel_socket.py b/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/accel_socket.py index c2d5d83..deba94e 100644 --- a/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/accel_socket.py +++ b/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/accel_socket.py @@ -1,5 +1,6 @@ import typing as typ +import bpy import pydantic as pyd from .. import base @@ -11,17 +12,39 @@ from ... import contracts class PhysicalAccelBLSocket(base.BLSocket): socket_type = contracts.SocketType.PhysicalAccel bl_label = "PhysicalAccel" + use_units = True + + #################### + # - Properties + #################### + raw_value: bpy.props.FloatProperty( + name="Unitless Acceleration", + description="Represents the unitless part of the acceleration", + default=0.0, + precision=6, + ) + + #################### + # - Socket UI + #################### + def draw_label_row(self, label_col_row: bpy.types.UILayout, text: str) -> None: + label_col_row.label(text=text) + label_col_row.prop(self, "raw_unit", text="") + + def draw_value(self, col: bpy.types.UILayout) -> None: + col_row = col.row(align=True) + col_row.prop(self, "raw_value", text="") #################### # - Default Value #################### @property def default_value(self) -> None: - pass + return self.raw_value * self.unit @default_value.setter def default_value(self, value: typ.Any) -> None: - pass + self.raw_value = self.value_as_unit(value) #################### # - Socket Configuration