feat: Custom units, def. all SocketType units.

Sofus Albert Høgsbro Rose 2024-02-19 15:58:39 +01:00
parent 14891cd7cc
commit af23eab628
2 changed files with 178 additions and 106 deletions

View File

@ -14,6 +14,7 @@ import bpy
from ...utils.blender_type_enum import ( from ...utils.blender_type_enum import (
BlenderTypeEnum, append_cls_name_to_values, wrap_values_in_MT BlenderTypeEnum, append_cls_name_to_values, wrap_values_in_MT
) )
from ...utils import extra_sympy_units as spuex
#################### ####################
# - String Types # - String Types
@ -145,170 +146,204 @@ class SocketType(BlenderTypeEnum):
SocketType_to_units = { SocketType_to_units = {
SocketType.PhysicalTime: { SocketType.PhysicalTime: {
"default": "UM", "default": "PS",
"values": { "values": {
"UM": spu.um, "PS": spu.picosecond,
"NS": spu.nanosecond,
"MS": spu.microsecond,
"MLSEC": spu.millisecond,
"SEC": spu.second,
"MIN": spu.minute,
"HOUR": spu.hour,
"DAY": spu.day,
}, },
}, },
SocketType.PhysicalAngle: { SocketType.PhysicalAngle: {
"default": "UM", "default": "RADIAN",
"values": { "values": {
"UM": spu.um, "RADIAN": spu.radian,
"DEGREE": spu.degree,
"STERAD": spu.steradian,
"ANGMIL": spu.angular_mil,
}, },
}, },
SocketType.PhysicalLength: { SocketType.PhysicalLength: {
"default": "UM", "default": "UM",
"values": { "values": {
"UM": spu.um, "PM": spu.picometer,
"A": spu.angstrom,
"NM": spu.nanometer,
"UM": spu.micrometer,
"MM": spu.millimeter,
"CM": spu.centimeter,
"M": spu.meter,
"INCH": spu.inch,
"FOOT": spu.foot,
"YARD": spu.yard,
"MILE": spu.mile,
}, },
}, },
SocketType.PhysicalArea: { SocketType.PhysicalArea: {
"default": "UM_SQ", "default": "UM_SQ",
"values": { "values": {
"PM_SQ": spu.pm**2, "PM_SQ": spu.picometer**2,
"A_SQ": spu.angstrom**2, "A_SQ": spu.angstrom**2,
"NM_SQ": spu.nm**2, "NM_SQ": spu.nanometer**2,
"UM_SQ": spu.um**2, "UM_SQ": spu.micrometer**2,
"MM_SQ": spu.mm**2, "MM_SQ": spu.millimeter**2,
"CM_SQ": spu.cm**2, "CM_SQ": spu.centimeter**2,
"M_SQ": spu.m**2, "M_SQ": spu.meter**2,
"INCH_SQ": spu.inch**2,
"FOOT_SQ": spu.foot**2,
"YARD_SQ": spu.yard**2,
"MILE_SQ": spu.mile**2,
}, },
}, },
SocketType.PhysicalVolume: { SocketType.PhysicalVolume: {
"default": "UM_CB", "default": "UM_CB",
"values": { "values": {
"PM_CB": spu.pm**3, "PM_CB": spu.picometer**3,
"A_CB": spu.angstrom**3, "A_CB": spu.angstrom**3,
"NM_CB": spu.nm**3, "NM_CB": spu.nanometer**3,
"UM_CB": spu.um**3, "UM_CB": spu.micrometer**3,
"MM_CB": spu.mm**3, "MM_CB": spu.millimeter**3,
"CM_CB": spu.cm**3, "CM_CB": spu.centimeter**3,
"M_CB": spu.m**3, "M_CB": spu.meter**3,
"ML": spu.milliliter, "ML": spu.milliliter,
"L": spu.liter, "L": spu.liter,
"INCH_CB": spu.inch**3,
"FOOT_CB": spu.foot**3,
"YARD_CB": spu.yard**3,
"MILE_CB": spu.mile**3,
}, },
}, },
SocketType.PhysicalMass: { SocketType.PhysicalMass: {
"default": "UM", "default": "UM",
"values": { "values": {
"UM": spu.um, "E_REST": spu.electron_rest_mass,
"DAL": spu.dalton,
"UG": spu.microgram,
"MG": spu.milligram,
"G": spu.gram,
"KG": spu.kilogram,
"TON": spu.metric_ton,
}, },
}, },
SocketType.PhysicalSpeed: { SocketType.PhysicalSpeed: {
"default": "UM", "default": "UM",
"values": { "values": {
"UM": spu.um, "PM_S": spu.picometer / spu.second,
"NM_S": spu.nanometer / spu.second,
"UM_S": spu.micrometer / spu.second,
"MM_S": spu.millimeter / spu.second,
"M_S": spu.meter / spu.second,
"KM_S": spu.kilometer / spu.second,
"KM_H": spu.kilometer / spu.hour,
"FT_S": spu.feet / spu.second,
"MI_H": spu.mile / spu.hour,
}, },
}, },
SocketType.PhysicalAccel: { SocketType.PhysicalAccel: {
"default": "UM", "default": "UM",
"values": { "values": {
"UM": spu.um, "PM_S_SQ": spu.picometer / spu.second**2,
"NM_S_SQ": spu.nanometer / spu.second**2,
"UM_S_SQ": spu.micrometer / spu.second**2,
"MM_S_SQ": spu.millimeter / spu.second**2,
"M_S_SQ": spu.meter / spu.second**2,
"KM_S_SQ": spu.kilometer / spu.second**2,
"FT_S_SQ": spu.feet / spu.second**2,
}, },
}, },
SocketType.PhysicalForce: { SocketType.PhysicalForce: {
"default": "UM", "default": "UNEWT",
"values": { "values": {
"UM": spu.um, "KG_M_S_SQ": spu.kg * spu.m/spu.second**2,
}, "NNEWT": spuex.nanonewton,
}, "UNEWT": spuex.micronewton,
"MNEWT": spuex.millinewton,
SocketType.PhysicalPol: { "NEWT": spu.newton,
"default": "UM",
"values": {
"UM": spu.um,
}, },
}, },
SocketType.PhysicalFreq: { SocketType.PhysicalFreq: {
"default": "UM", "default": "THZ",
"values": { "values": {
"UM": spu.um, "HZ": spu.hertz,
}, "KHZ": spuex.kilohertz,
}, "MHZ": spuex.megahertz,
SocketType.PhysicalSpecPowerDist: { "GHZ": spuex.gigahertz,
"default": "UM", "THZ": spuex.terahertz,
"values": { "PHZ": spuex.petahertz,
"UM": spu.um, #"EHZ": spu.exahertz,
}, "VAC_PM": spu.picometer, ## c(vac) = wl*freq
}, "VAC_A": spu.angstrom,
SocketType.PhysicalSpecRelPermDist: { "VAC_NM": spu.nanometer,
"default": "UM", "VAC_UM": spu.micrometer,
"values": { "VAC_MM": spu.millimeter,
"UM": spu.um, "VAC_CM": spu.centimeter,
"VAC_M": spu.meter,
}, },
}, },
} }
SocketType_to_color = { SocketType_to_color = {
SocketType.Any: (0.5, 0.5, 0.5, 1.0), # Basic
SocketType.Text: (0.5, 0.5, 0.5, 1.0), SocketType.Any: (0.8, 0.8, 0.8, 1.0), # Light Grey
SocketType.FilePath: (0.5, 0.5, 0.5, 1.0), SocketType.Text: (0.7, 0.7, 0.7, 1.0), # Medium Light Grey
SocketType.FilePath: (0.6, 0.6, 0.6, 1.0), # Medium Grey
# Mathematical # Number
SocketType.IntegerNumber: (0.5, 0.5, 0.5, 1.0), SocketType.IntegerNumber: (0.5, 0.5, 1.0, 1.0), # Light Blue
SocketType.RationalNumber: (0.5, 0.5, 0.5, 1.0), SocketType.RationalNumber: (0.4, 0.4, 0.9, 1.0), # Medium Light Blue
SocketType.RealNumber: (0.5, 0.5, 0.5, 1.0), SocketType.RealNumber: (0.3, 0.3, 0.8, 1.0), # Medium Blue
SocketType.ComplexNumber: (0.5, 0.5, 0.5, 1.0), SocketType.ComplexNumber: (0.2, 0.2, 0.7, 1.0), # Dark Blue
SocketType.Real2DVector: (0.5, 0.5, 0.5, 1.0), # Vector
SocketType.Complex2DVector: (0.5, 0.5, 0.5, 1.0), SocketType.Real2DVector: (0.5, 1.0, 0.5, 1.0), # Light Green
SocketType.Complex2DVector: (0.4, 0.9, 0.4, 1.0), # Medium Light Green
SocketType.Real3DVector: (0.5, 0.5, 0.5, 1.0), SocketType.Real3DVector: (0.3, 0.8, 0.3, 1.0), # Medium Green
SocketType.Complex3DVector: (0.5, 0.5, 0.5, 1.0), SocketType.Complex3DVector: (0.2, 0.7, 0.2, 1.0), # Dark Green
# Physical # Physical
SocketType.PhysicalTime: (0.5, 0.5, 0.5, 1.0), SocketType.PhysicalTime: (1.0, 0.5, 0.5, 1.0), # Light Red
SocketType.PhysicalAngle: (0.9, 0.45, 0.45, 1.0), # Medium Light Red
SocketType.PhysicalAngle: (0.5, 0.5, 0.5, 1.0), SocketType.PhysicalLength: (0.8, 0.4, 0.4, 1.0), # Medium Red
SocketType.PhysicalArea: (0.7, 0.35, 0.35, 1.0), # Medium Dark Red
SocketType.PhysicalLength: (0.5, 0.5, 0.5, 1.0), SocketType.PhysicalVolume: (0.6, 0.3, 0.3, 1.0), # Dark Red
SocketType.PhysicalArea: (0.5, 0.5, 0.5, 1.0), SocketType.PhysicalMass: (0.9, 0.6, 0.4, 1.0), # Light Orange
SocketType.PhysicalVolume: (0.5, 0.5, 0.5, 1.0), SocketType.PhysicalSpeed: (0.8, 0.55, 0.35, 1.0), # Medium Light Orange
SocketType.PhysicalAccel: (0.7, 0.5, 0.3, 1.0), # Medium Orange
SocketType.PhysicalMass: (0.5, 0.5, 0.5, 1.0), SocketType.PhysicalForce: (0.6, 0.45, 0.25, 1.0), # Medium Dark Orange
SocketType.PhysicalPol: (0.5, 0.4, 0.2, 1.0), # Dark Orange
SocketType.PhysicalSpeed: (0.5, 0.5, 0.5, 1.0), SocketType.PhysicalFreq: (1.0, 0.7, 0.5, 1.0), # Light Peach
SocketType.PhysicalAccel: (0.5, 0.5, 0.5, 1.0), SocketType.PhysicalSpecPowerDist: (0.9, 0.65, 0.45, 1.0), # Medium Light Peach
SocketType.PhysicalForce: (0.5, 0.5, 0.5, 1.0), SocketType.PhysicalSpecRelPermDist: (0.8, 0.6, 0.4, 1.0), # Medium Peach
SocketType.PhysicalPol: (0.5, 0.5, 0.5, 1.0),
SocketType.PhysicalFreq: (0.5, 0.5, 0.5, 1.0),
SocketType.PhysicalSpecPowerDist: (0.5, 0.5, 0.5, 1.0),
SocketType.PhysicalSpecRelPermDist: (0.5, 0.5, 0.5, 1.0),
# Blender # Blender
SocketType.BlenderObject: (0.5, 0.5, 0.5, 1.0), SocketType.BlenderObject: (0.7, 0.5, 1.0, 1.0), # Light Purple
SocketType.BlenderCollection: (0.5, 0.5, 0.5, 1.0), SocketType.BlenderCollection: (0.6, 0.45, 0.9, 1.0), # Medium Light Purple
SocketType.BlenderImage: (0.5, 0.4, 0.8, 1.0), # Medium Purple
SocketType.BlenderImage: (0.5, 0.5, 0.5, 1.0), SocketType.BlenderVolume: (0.4, 0.35, 0.7, 1.0), # Medium Dark Purple
SocketType.BlenderVolume: (0.5, 0.5, 0.5, 1.0), SocketType.BlenderGeoNodes: (0.3, 0.3, 0.6, 1.0), # Dark Purple
SocketType.BlenderText: (0.5, 0.5, 0.75, 1.0), # Light Lavender
SocketType.BlenderGeoNodes: (0.5, 0.5, 0.5, 1.0),
SocketType.BlenderText: (0.5, 0.5, 0.5, 1.0),
# Maxwell # Maxwell
SocketType.MaxwellSource: (0.5, 0.5, 0.5, 1.0), SocketType.MaxwellSource: (1.0, 1.0, 0.5, 1.0), # Light Yellow
SocketType.MaxwellTemporalShape: (0.5, 0.5, 0.5, 1.0), SocketType.MaxwellTemporalShape: (0.9, 0.9, 0.45, 1.0), # Medium Light Yellow
SocketType.MaxwellMedium: (0.8, 0.8, 0.4, 1.0), # Medium Yellow
SocketType.MaxwellMedium: (0.5, 0.5, 0.5, 1.0), SocketType.MaxwellMediumNonLinearity: (0.7, 0.7, 0.35, 1.0), # Medium Dark Yellow
SocketType.MaxwellMediumNonLinearity: (0.5, 0.5, 0.5, 1.0), SocketType.MaxwellStructure: (0.6, 0.6, 0.3, 1.0), # Dark Yellow
SocketType.MaxwellBoundBox: (0.9, 0.8, 0.5, 1.0), # Light Gold
SocketType.MaxwellStructure: (0.5, 0.5, 0.5, 1.0), SocketType.MaxwellBoundFace: (0.8, 0.7, 0.45, 1.0), # Medium Light Gold
SocketType.MaxwellMonitor: (0.7, 0.6, 0.4, 1.0), # Medium Gold
SocketType.MaxwellBoundBox: (0.5, 0.5, 0.5, 1.0), SocketType.MaxwellFDTDSim: (0.6, 0.5, 0.35, 1.0), # Medium Dark Gold
SocketType.MaxwellBoundFace: (0.5, 0.5, 0.5, 1.0), SocketType.MaxwellSimGrid: (0.5, 0.4, 0.3, 1.0), # Dark Gold
SocketType.MaxwellSimGridAxis: (0.4, 0.3, 0.25, 1.0), # Darkest Gold
SocketType.MaxwellMonitor: (0.5, 0.5, 0.5, 1.0),
SocketType.MaxwellFDTDSim: (0.5, 0.5, 0.5, 1.0),
SocketType.MaxwellSimGrid: (0.5, 0.5, 0.5, 1.0),
SocketType.MaxwellSimGridAxis: (0.5, 0.5, 0.5, 1.0),
} }
#################### ####################

View File

@ -0,0 +1,37 @@
import sympy as sp
import sympy.physics.units as spu
####################
# - Force
####################
# Newton
nanonewton = nN = spu.Quantity("nanonewton", abbrev="nN")
nanonewton.set_global_relative_scale_factor(spu.nano, spu.newton)
micronewton = uN = spu.Quantity("micronewton", abbrev="μN")
micronewton.set_global_relative_scale_factor(spu.micro, spu.newton)
millinewton = mN = spu.Quantity("micronewton", abbrev="mN")
micronewton.set_global_relative_scale_factor(spu.milli, spu.newton)
####################
# - Frequency
####################
# Hertz
kilohertz = kHz = spu.Quantity("kilohertz", abbrev="kHz")
kilohertz.set_global_relative_scale_factor(spu.kilo, spu.hertz)
megahertz = MHz = spu.Quantity("megahertz", abbrev="MHz")
kilohertz.set_global_relative_scale_factor(spu.kilo, spu.hertz)
gigahertz = GHz = spu.Quantity("gigahertz", abbrev="GHz")
gigahertz.set_global_relative_scale_factor(spu.giga, spu.hertz)
terahertz = THz = spu.Quantity("terahertz", abbrev="THz")
terahertz.set_global_relative_scale_factor(spu.tera, spu.hertz)
petahertz = PHz = spu.Quantity("petahertz", abbrev="PHz")
petahertz.set_global_relative_scale_factor(spu.peta, spu.hertz)
exahertz = EHz = spu.Quantity("exahertz", abbrev="EHz")
exahertz.set_global_relative_scale_factor(spu.exa, spu.hertz)