2024-02-14 12:33:40 +01:00
|
|
|
import typing as typ
|
2024-03-10 11:56:37 +01:00
|
|
|
import typing_extensions as typx
|
2024-02-14 12:33:40 +01:00
|
|
|
|
|
|
|
import bpy
|
|
|
|
import pydantic as pyd
|
|
|
|
import tidy3d as td
|
|
|
|
|
|
|
|
from .. import base
|
2024-03-10 11:56:37 +01:00
|
|
|
from ... import contracts as ct
|
2024-02-14 12:33:40 +01:00
|
|
|
|
2024-03-10 11:56:37 +01:00
|
|
|
class MaxwellBoundFaceBLSocket(base.MaxwellSimSocket):
|
|
|
|
socket_type = ct.SocketType.MaxwellBoundFace
|
2024-02-19 14:28:35 +01:00
|
|
|
bl_label = "Maxwell Bound Face"
|
2024-02-14 12:33:40 +01:00
|
|
|
|
2024-02-26 16:16:06 +01:00
|
|
|
####################
|
|
|
|
# - Properties
|
|
|
|
####################
|
|
|
|
default_choice: bpy.props.EnumProperty(
|
|
|
|
name="Bound Face",
|
|
|
|
description="A choice of default boundary face",
|
|
|
|
items=[
|
|
|
|
("PML", "PML", "Perfectly matched layer"),
|
|
|
|
("PEC", "PEC", "Perfect electrical conductor"),
|
|
|
|
("PMC", "PMC", "Perfect magnetic conductor"),
|
|
|
|
("PERIODIC", "Periodic", "Infinitely periodic layer"),
|
|
|
|
],
|
|
|
|
default="PML",
|
2024-03-10 11:56:37 +01:00
|
|
|
update=(lambda self, context: self.sync_prop("default_choice", context)),
|
2024-02-26 16:16:06 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
####################
|
|
|
|
# - UI
|
|
|
|
####################
|
|
|
|
def draw_value(self, col: bpy.types.UILayout) -> None:
|
2024-03-10 11:56:37 +01:00
|
|
|
col.prop(self, "default_choice", text="")
|
2024-02-14 12:33:40 +01:00
|
|
|
|
|
|
|
####################
|
|
|
|
# - Computation of Default Value
|
|
|
|
####################
|
|
|
|
@property
|
2024-03-10 11:56:37 +01:00
|
|
|
def value(self) -> td.BoundarySpec:
|
2024-02-26 16:16:06 +01:00
|
|
|
return {
|
|
|
|
"PML": td.PML(num_layers=12),
|
|
|
|
"PEC": td.PECBoundary(),
|
|
|
|
"PMC": td.PMCBoundary(),
|
|
|
|
"PERIODIC": td.Periodic(),
|
|
|
|
}[self.default_choice]
|
2024-02-14 12:33:40 +01:00
|
|
|
|
2024-03-10 11:56:37 +01:00
|
|
|
@value.setter
|
|
|
|
def value(self, value: typx.Literal["PML", "PEC", "PMC", "PERIODIC"]) -> None:
|
|
|
|
self.default_choice = value
|
2024-02-14 12:33:40 +01:00
|
|
|
|
|
|
|
####################
|
|
|
|
# - Socket Configuration
|
|
|
|
####################
|
2024-02-19 14:28:35 +01:00
|
|
|
class MaxwellBoundFaceSocketDef(pyd.BaseModel):
|
2024-03-10 11:56:37 +01:00
|
|
|
socket_type: ct.SocketType = ct.SocketType.MaxwellBoundFace
|
2024-02-14 12:33:40 +01:00
|
|
|
|
2024-03-10 11:56:37 +01:00
|
|
|
default_choice: typx.Literal["PML", "PEC", "PMC", "PERIODIC"] = "PML"
|
2024-02-26 16:16:06 +01:00
|
|
|
|
2024-02-19 14:28:35 +01:00
|
|
|
def init(self, bl_socket: MaxwellBoundFaceBLSocket) -> None:
|
2024-03-10 11:56:37 +01:00
|
|
|
bl_socket.value = self.default_choice
|
2024-02-14 12:33:40 +01:00
|
|
|
|
|
|
|
####################
|
|
|
|
# - Blender Registration
|
|
|
|
####################
|
|
|
|
BL_REGISTER = [
|
2024-02-19 14:28:35 +01:00
|
|
|
MaxwellBoundFaceBLSocket,
|
2024-02-14 12:33:40 +01:00
|
|
|
]
|