refactor: Renamed DataFlowKind to FlowKind

main
Sofus Albert Høgsbro Rose 2024-04-17 16:06:24 +02:00
parent dfeb65feec
commit 76d15b0c92
Signed by: so-rose
GPG Key ID: AD901CB0F3701434
16 changed files with 61 additions and 61 deletions

View File

@ -54,7 +54,7 @@ from .managed_obj_type import ManagedObjType
# - Data Flows # - Data Flows
#################### ####################
from .data_flows import ( from .data_flows import (
DataFlowKind, FlowKind,
DataCapabilities, DataCapabilities,
DataValue, DataValue,
DataValueArray, DataValueArray,
@ -89,7 +89,7 @@ __all__ = [
'NodeCategory', 'NodeCategory',
'NODE_CAT_LABELS', 'NODE_CAT_LABELS',
'ManagedObjType', 'ManagedObjType',
'DataFlowKind', 'FlowKind',
'DataCapabilities', 'DataCapabilities',
'DataValue', 'DataValue',
'DataValueArray', 'DataValueArray',

View File

@ -103,7 +103,7 @@ class MapMathNode(base.MaxwellSimNode):
'Data', 'Data',
props={'active_socket_set', 'operation'}, props={'active_socket_set', 'operation'},
input_sockets={'Data', 'Mapper'}, input_sockets={'Data', 'Mapper'},
input_socket_kinds={'Mapper': ct.DataFlowKind.LazyValue}, input_socket_kinds={'Mapper': ct.FlowKind.LazyValue},
input_sockets_optional={'Mapper': True}, input_sockets_optional={'Mapper': True},
) )
def compute_data(self, props: dict, input_sockets: dict): def compute_data(self, props: dict, input_sockets: dict):

View File

@ -81,7 +81,7 @@ class ReduceMathNode(base.MaxwellSimNode):
'Data', 'Data',
props={'operation'}, props={'operation'},
input_sockets={'Data', 'Axis', 'Reducer'}, input_sockets={'Data', 'Axis', 'Reducer'},
input_socket_kinds={'Reducer': ct.DataFlowKind.LazyValue}, input_socket_kinds={'Reducer': ct.FlowKind.LazyValue},
input_sockets_optional={'Reducer': True}, input_sockets_optional={'Reducer': True},
) )
def compute_data(self, props: dict, input_sockets: dict): def compute_data(self, props: dict, input_sockets: dict):

View File

@ -273,7 +273,7 @@ class MaxwellSimNode(bpy.types.Node):
msg = f'Tried to set preset socket/value pair ({socket_name}={socket_value}), but socket is not in active input sockets ({self.inputs})' msg = f'Tried to set preset socket/value pair ({socket_name}={socket_value}), but socket is not in active input sockets ({self.inputs})'
raise ValueError(msg) raise ValueError(msg)
## TODO: Account for DataFlowKind ## TODO: Account for FlowKind
bl_socket.value = socket_value bl_socket.value = socket_value
@events.on_show_preview() @events.on_show_preview()
@ -558,7 +558,7 @@ class MaxwellSimNode(bpy.types.Node):
def _compute_input( def _compute_input(
self, self,
input_socket_name: ct.SocketName, input_socket_name: ct.SocketName,
kind: ct.DataFlowKind = ct.DataFlowKind.Value, kind: ct.FlowKind = ct.FlowKind.Value,
unit_system: dict[ct.SocketType, sp.Expr] | None = None, unit_system: dict[ct.SocketType, sp.Expr] | None = None,
optional: bool = False, optional: bool = False,
) -> typ.Any: ) -> typ.Any:
@ -574,7 +574,7 @@ class MaxwellSimNode(bpy.types.Node):
""" """
if (bl_socket := self.inputs.get(input_socket_name)) is not None: if (bl_socket := self.inputs.get(input_socket_name)) is not None:
return ( return (
ct.DataFlowKind.scale_to_unit_system( ct.FlowKind.scale_to_unit_system(
kind, kind,
bl_socket.compute_data(kind=kind), bl_socket.compute_data(kind=kind),
bl_socket.socket_type, bl_socket.socket_type,
@ -599,14 +599,14 @@ class MaxwellSimNode(bpy.types.Node):
def compute_output( def compute_output(
self, self,
output_socket_name: ct.SocketName, output_socket_name: ct.SocketName,
kind: ct.DataFlowKind = ct.DataFlowKind.Value, kind: ct.FlowKind = ct.FlowKind.Value,
optional: bool = False, optional: bool = False,
) -> typ.Any: ) -> typ.Any:
"""Computes the value of an output socket. """Computes the value of an output socket.
Parameters: Parameters:
output_socket_name: The name declaring the output socket, for which this method computes the output. output_socket_name: The name declaring the output socket, for which this method computes the output.
kind: The DataFlowKind to use when computing the output socket value. kind: The FlowKind to use when computing the output socket value.
Returns: Returns:
The value of the output socket, as computed by the dedicated method The value of the output socket, as computed by the dedicated method

View File

@ -26,16 +26,16 @@ class InfoDataChanged:
@dataclasses.dataclass(kw_only=True, frozen=True) @dataclasses.dataclass(kw_only=True, frozen=True)
class InfoOutputRequested: class InfoOutputRequested:
output_socket_name: ct.SocketName output_socket_name: ct.SocketName
kind: ct.DataFlowKind kind: ct.FlowKind
depon_props: set[str] depon_props: set[str]
depon_input_sockets: set[ct.SocketName] depon_input_sockets: set[ct.SocketName]
depon_input_socket_kinds: dict[ct.SocketName, ct.DataFlowKind] depon_input_socket_kinds: dict[ct.SocketName, ct.FlowKind]
depon_all_loose_input_sockets: bool depon_all_loose_input_sockets: bool
depon_output_sockets: set[ct.SocketName] depon_output_sockets: set[ct.SocketName]
depon_output_socket_kinds: dict[ct.SocketName, ct.DataFlowKind] depon_output_socket_kinds: dict[ct.SocketName, ct.FlowKind]
depon_all_loose_output_sockets: bool depon_all_loose_output_sockets: bool
@ -58,10 +58,10 @@ def event_decorator(
props: set[PropName] = frozenset(), props: set[PropName] = frozenset(),
input_sockets: set[ct.SocketName] = frozenset(), input_sockets: set[ct.SocketName] = frozenset(),
input_sockets_optional: dict[ct.SocketName, bool] = MappingProxyType({}), input_sockets_optional: dict[ct.SocketName, bool] = MappingProxyType({}),
input_socket_kinds: dict[ct.SocketName, ct.DataFlowKind] = MappingProxyType({}), input_socket_kinds: dict[ct.SocketName, ct.FlowKind] = MappingProxyType({}),
output_sockets: set[ct.SocketName] = frozenset(), output_sockets: set[ct.SocketName] = frozenset(),
output_sockets_optional: dict[ct.SocketName, bool] = MappingProxyType({}), output_sockets_optional: dict[ct.SocketName, bool] = MappingProxyType({}),
output_socket_kinds: dict[ct.SocketName, ct.DataFlowKind] = MappingProxyType({}), output_socket_kinds: dict[ct.SocketName, ct.FlowKind] = MappingProxyType({}),
all_loose_input_sockets: bool = False, all_loose_input_sockets: bool = False,
all_loose_output_sockets: bool = False, all_loose_output_sockets: bool = False,
# Request Unit System Scaling # Request Unit System Scaling
@ -81,8 +81,8 @@ def event_decorator(
Other methods defined on the same node will still run. Other methods defined on the same node will still run.
managed_objs: Set of `managed_objs` to retrieve, then pass to the decorated method. managed_objs: Set of `managed_objs` to retrieve, then pass to the decorated method.
input_sockets: Set of `input_sockets` to compute, then pass to the decorated method. input_sockets: Set of `input_sockets` to compute, then pass to the decorated method.
input_socket_kinds: The `ct.DataFlowKind` to compute per-input-socket. input_socket_kinds: The `ct.FlowKind` to compute per-input-socket.
If an input socket isn't specified, it defaults to `ct.DataFlowKind.Value`. If an input socket isn't specified, it defaults to `ct.FlowKind.Value`.
output_sockets: Set of `output_sockets` to compute, then pass to the decorated method. output_sockets: Set of `output_sockets` to compute, then pass to the decorated method.
all_loose_input_sockets: Whether to compute all loose input sockets and pass them to the decorated method. all_loose_input_sockets: Whether to compute all loose input sockets and pass them to the decorated method.
Used when the names of the loose input sockets are unknown, but all of their values are needed. Used when the names of the loose input sockets are unknown, but all of their values are needed.
@ -157,7 +157,7 @@ def event_decorator(
input_socket_name: node._compute_input( input_socket_name: node._compute_input(
input_socket_name, input_socket_name,
kind=input_socket_kinds.get( kind=input_socket_kinds.get(
input_socket_name, ct.DataFlowKind.Value input_socket_name, ct.FlowKind.Value
), ),
unit_system=( unit_system=(
unit_system := unit_systems.get( unit_system := unit_systems.get(
@ -179,10 +179,10 @@ def event_decorator(
method_kw_args |= ( method_kw_args |= (
{ {
'output_sockets': { 'output_sockets': {
output_socket_name: ct.DataFlowKind.scale_to_unit_system( output_socket_name: ct.FlowKind.scale_to_unit_system(
( (
output_socket_kind := output_socket_kinds.get( output_socket_kind := output_socket_kinds.get(
output_socket_name, ct.DataFlowKind.Value output_socket_name, ct.FlowKind.Value
) )
), ),
node.compute_output( node.compute_output(
@ -201,7 +201,7 @@ def event_decorator(
else node.compute_output( else node.compute_output(
output_socket_name, output_socket_name,
kind=output_socket_kinds.get( kind=output_socket_kinds.get(
output_socket_name, ct.DataFlowKind.Value output_socket_name, ct.FlowKind.Value
), ),
optional=output_sockets_optional.get( optional=output_sockets_optional.get(
output_socket_name, False output_socket_name, False
@ -316,7 +316,7 @@ def on_value_changed(
## TODO: Change name to 'on_output_requested' ## TODO: Change name to 'on_output_requested'
def computes_output_socket( def computes_output_socket(
output_socket_name: ct.SocketName | None, output_socket_name: ct.SocketName | None,
kind: ct.DataFlowKind = ct.DataFlowKind.Value, kind: ct.FlowKind = ct.FlowKind.Value,
**kwargs, **kwargs,
): ):
return event_decorator( return event_decorator(

View File

@ -38,7 +38,7 @@ class WaveConstantNode(base.MaxwellSimNode):
#################### ####################
@events.computes_output_socket( @events.computes_output_socket(
'WL', 'WL',
kind=ct.DataFlowKind.Value, kind=ct.FlowKind.Value,
# Data # Data
input_sockets={'WL', 'Freq'}, input_sockets={'WL', 'Freq'},
input_sockets_optional={'WL': True, 'Freq': True}, input_sockets_optional={'WL': True, 'Freq': True},
@ -55,7 +55,7 @@ class WaveConstantNode(base.MaxwellSimNode):
@events.computes_output_socket( @events.computes_output_socket(
'Freq', 'Freq',
kind=ct.DataFlowKind.Value, kind=ct.FlowKind.Value,
# Data # Data
input_sockets={'WL', 'Freq'}, input_sockets={'WL', 'Freq'},
input_sockets_optional={'WL': True, 'Freq': True}, input_sockets_optional={'WL': True, 'Freq': True},
@ -73,7 +73,7 @@ class WaveConstantNode(base.MaxwellSimNode):
@events.computes_output_socket( @events.computes_output_socket(
'WL', 'WL',
kind=ct.DataFlowKind.LazyValueRange, kind=ct.FlowKind.LazyValueRange,
# Data # Data
input_sockets={'WL', 'Freq'}, input_sockets={'WL', 'Freq'},
input_sockets_optional={'WL': True, 'Freq': True}, input_sockets_optional={'WL': True, 'Freq': True},
@ -92,12 +92,12 @@ class WaveConstantNode(base.MaxwellSimNode):
@events.computes_output_socket( @events.computes_output_socket(
'Freq', 'Freq',
kind=ct.DataFlowKind.LazyValueRange, kind=ct.FlowKind.LazyValueRange,
# Data # Data
input_sockets={'WL', 'Freq'}, input_sockets={'WL', 'Freq'},
input_socket_kinds={ input_socket_kinds={
'WL': ct.DataFlowKind.LazyValueRange, 'WL': ct.FlowKind.LazyValueRange,
'Freq': ct.DataFlowKind.LazyValueRange, 'Freq': ct.FlowKind.LazyValueRange,
}, },
input_sockets_optional={'WL': True, 'Freq': True}, input_sockets_optional={'WL': True, 'Freq': True},
) )

View File

@ -67,7 +67,7 @@ class EHFieldMonitorNode(base.MaxwellSimNode):
'Freqs', 'Freqs',
}, },
input_socket_kinds={ input_socket_kinds={
'Freqs': ct.DataFlowKind.LazyValueRange, 'Freqs': ct.FlowKind.LazyValueRange,
}, },
unit_systems={'Tidy3DUnits': ct.UNITS_TIDY3D}, unit_systems={'Tidy3DUnits': ct.UNITS_TIDY3D},
scale_input_sockets={ scale_input_sockets={

View File

@ -67,7 +67,7 @@ class PowerFluxMonitorNode(base.MaxwellSimNode):
'Direction', 'Direction',
}, },
input_socket_kinds={ input_socket_kinds={
'Freqs': ct.DataFlowKind.LazyValueRange, 'Freqs': ct.FlowKind.LazyValueRange,
}, },
unit_systems={'Tidy3DUnits': ct.UNITS_TIDY3D}, unit_systems={'Tidy3DUnits': ct.UNITS_TIDY3D},
scale_input_sockets={ scale_input_sockets={

View File

@ -35,7 +35,7 @@ class FDTDSimNode(base.MaxwellSimNode):
#################### ####################
@events.computes_output_socket( @events.computes_output_socket(
'FDTD Sim', 'FDTD Sim',
kind=ct.DataFlowKind.Value, kind=ct.FlowKind.Value,
input_sockets={'Sources', 'Structures', 'Domain', 'BCs', 'Monitors'}, input_sockets={'Sources', 'Structures', 'Domain', 'BCs', 'Monitors'},
) )
def compute_fdtd_sim(self, input_sockets: dict) -> sp.Expr: def compute_fdtd_sim(self, input_sockets: dict) -> sp.Expr:

View File

@ -8,7 +8,7 @@
#class MaxwellSimProp(bpy.types.PropertyGroup): #class MaxwellSimProp(bpy.types.PropertyGroup):
# """A Blender property usable in nodes and sockets.""" # """A Blender property usable in nodes and sockets."""
# name: str = "" # name: str = ""
# data_flow_kind: ct.DataFlowKind # data_flow_kind: ct.FlowKind
# #
# value: dict[str, tuple[bpy.types.Property, dict]] | None = None # value: dict[str, tuple[bpy.types.Property, dict]] | None = None
# #

View File

@ -138,7 +138,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
cls.__annotations__['active_kind'] = bpy.props.StringProperty( cls.__annotations__['active_kind'] = bpy.props.StringProperty(
name='Active Kind', name='Active Kind',
description='The active Data Flow Kind', description='The active Data Flow Kind',
default=str(ct.DataFlowKind.Value), default=str(ct.FlowKind.Value),
update=lambda self, _: self.sync_active_kind(), update=lambda self, _: self.sync_active_kind(),
) )
@ -226,15 +226,15 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
def sync_active_kind(self): def sync_active_kind(self):
"""Called when the active data flow kind of the socket changes. """Called when the active data flow kind of the socket changes.
Alters the shape of the socket to match the active DataFlowKind, then triggers `ct.DataFlowAction.DataChanged` on the current socket. Alters the shape of the socket to match the active FlowKind, then triggers `ct.DataFlowAction.DataChanged` on the current socket.
""" """
self.display_shape = { self.display_shape = {
ct.DataFlowKind.Value: ct.SOCKET_SHAPES[self.socket_type], ct.FlowKind.Value: ct.SOCKET_SHAPES[self.socket_type],
ct.DataFlowKind.ValueArray: 'SQUARE', ct.FlowKind.ValueArray: 'SQUARE',
ct.DataFlowKind.ValueSpectrum: 'SQUARE', ct.FlowKind.ValueSpectrum: 'SQUARE',
ct.DataFlowKind.LazyValue: ct.SOCKET_SHAPES[self.socket_type], ct.FlowKind.LazyValue: ct.SOCKET_SHAPES[self.socket_type],
ct.DataFlowKind.LazyValueRange: 'SQUARE', ct.FlowKind.LazyValueRange: 'SQUARE',
ct.DataFlowKind.LazyValueSpectrum: 'SQUARE', ct.FlowKind.LazyValueSpectrum: 'SQUARE',
}[self.active_kind] + ('_DOT' if self.use_units else '') }[self.active_kind] + ('_DOT' if self.use_units else '')
self.trigger_action(ct.DataFlowAction.DataChanged) self.trigger_action(ct.DataFlowAction.DataChanged)
@ -360,19 +360,19 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
#################### ####################
def _compute_data( def _compute_data(
self, self,
kind: ct.DataFlowKind = ct.DataFlowKind.Value, kind: ct.FlowKind = ct.FlowKind.Value,
) -> typ.Any: ) -> typ.Any:
"""Computes the internal data of this socket, ONLY. """Computes the internal data of this socket, ONLY.
**NOTE**: Low-level method. Use `compute_data` instead. **NOTE**: Low-level method. Use `compute_data` instead.
""" """
return { return {
ct.DataFlowKind.Value: lambda: self.value, ct.FlowKind.Value: lambda: self.value,
ct.DataFlowKind.ValueArray: lambda: self.value_array, ct.FlowKind.ValueArray: lambda: self.value_array,
ct.DataFlowKind.ValueSpectrum: lambda: self.value_spectrum, ct.FlowKind.ValueSpectrum: lambda: self.value_spectrum,
ct.DataFlowKind.LazyValue: lambda: self.lazy_value, ct.FlowKind.LazyValue: lambda: self.lazy_value,
ct.DataFlowKind.LazyValueRange: lambda: self.lazy_value_range, ct.FlowKind.LazyValueRange: lambda: self.lazy_value_range,
ct.DataFlowKind.LazyValueSpectrum: lambda: self.lazy_value_spectrum, ct.FlowKind.LazyValueSpectrum: lambda: self.lazy_value_spectrum,
}[kind]() }[kind]()
msg = f'socket._compute_data was called with invalid kind "{kind}"' msg = f'socket._compute_data was called with invalid kind "{kind}"'
@ -380,7 +380,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
def compute_data( def compute_data(
self, self,
kind: ct.DataFlowKind = ct.DataFlowKind.Value, kind: ct.FlowKind = ct.FlowKind.Value,
): ):
"""Computes the value of this socket, including all relevant factors. """Computes the value of this socket, including all relevant factors.
@ -463,10 +463,10 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
Can be overridden if more specific logic is required. Can be overridden if more specific logic is required.
""" """
if self.active_kind == ct.DataFlowKind.Value: if self.active_kind == ct.FlowKind.Value:
self.value = self.value / self.unit * self.prev_unit self.value = self.value / self.unit * self.prev_unit
elif self.active_kind == ct.DataFlowKind.LazyValueRange: elif self.active_kind == ct.FlowKind.LazyValueRange:
lazy_value_range = self.lazy_value_range lazy_value_range = self.lazy_value_range
self.lazy_value_range = ( self.lazy_value_range = (
lazy_value_range.start / self.unit * self.prev_unit, lazy_value_range.start / self.unit * self.prev_unit,
@ -565,12 +565,12 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
# Data Column(s) # Data Column(s)
col = row.column(align=True) col = row.column(align=True)
{ {
ct.DataFlowKind.Value: self.draw_value, ct.FlowKind.Value: self.draw_value,
ct.DataFlowKind.ValueArray: self.draw_value_array, ct.FlowKind.ValueArray: self.draw_value_array,
ct.DataFlowKind.ValueSpectrum: self.draw_value_spectrum, ct.FlowKind.ValueSpectrum: self.draw_value_spectrum,
ct.DataFlowKind.LazyValue: self.draw_lazy_value, ct.FlowKind.LazyValue: self.draw_lazy_value,
ct.DataFlowKind.LazyValueRange: self.draw_lazy_value_range, ct.FlowKind.LazyValueRange: self.draw_lazy_value_range,
ct.DataFlowKind.LazyValueSpectrum: self.draw_lazy_value_spectrum, ct.FlowKind.LazyValueSpectrum: self.draw_lazy_value_spectrum,
}[self.active_kind](col) }[self.active_kind](col)
def draw_output( def draw_output(
@ -598,7 +598,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
row.label(text=text) row.label(text=text)
#################### ####################
# - DataFlowKind draw() Methods # - FlowKind draw() Methods
#################### ####################
def draw_value(self, col: bpy.types.UILayout) -> None: def draw_value(self, col: bpy.types.UILayout) -> None:
pass pass

View File

@ -18,7 +18,7 @@ class MaxwellMonitorSocketDef(base.SocketDef):
def init(self, bl_socket: MaxwellMonitorBLSocket) -> None: def init(self, bl_socket: MaxwellMonitorBLSocket) -> None:
if self.is_list: if self.is_list:
bl_socket.active_kind = ct.DataFlowKind.ValueArray bl_socket.active_kind = ct.FlowKind.ValueArray
#################### ####################

View File

@ -18,7 +18,7 @@ class MaxwellSourceSocketDef(base.SocketDef):
def init(self, bl_socket: MaxwellSourceBLSocket) -> None: def init(self, bl_socket: MaxwellSourceBLSocket) -> None:
if self.is_list: if self.is_list:
bl_socket.active_kind = ct.DataFlowKind.ValueArray bl_socket.active_kind = ct.FlowKind.ValueArray
#################### ####################

View File

@ -18,7 +18,7 @@ class MaxwellStructureSocketDef(base.SocketDef):
def init(self, bl_socket: MaxwellStructureBLSocket) -> None: def init(self, bl_socket: MaxwellStructureBLSocket) -> None:
if self.is_list: if self.is_list:
bl_socket.active_kind = ct.DataFlowKind.ValueArray bl_socket.active_kind = ct.FlowKind.ValueArray
#################### ####################

View File

@ -111,7 +111,7 @@ class PhysicalFreqSocketDef(base.SocketDef):
bl_socket.value = self.default_value bl_socket.value = self.default_value
if self.is_array: if self.is_array:
bl_socket.active_kind = ct.DataFlowKind.LazyValueRange bl_socket.active_kind = ct.FlowKind.LazyValueRange
bl_socket.lazy_value_range = (self.min_freq, self.max_freq, self.steps) bl_socket.lazy_value_range = (self.min_freq, self.max_freq, self.steps)

View File

@ -112,7 +112,7 @@ class PhysicalLengthSocketDef(base.SocketDef):
bl_socket.value = self.default_value bl_socket.value = self.default_value
if self.is_array: if self.is_array:
bl_socket.active_kind = ct.DataFlowKind.LazyValueRange bl_socket.active_kind = ct.FlowKind.LazyValueRange
bl_socket.lazy_value_range = (self.min_len, self.max_len, self.steps) bl_socket.lazy_value_range = (self.min_len, self.max_len, self.steps)