refactor: Prepare for deeper refactor

uv-refactor
Sofus Albert Høgsbro Rose 2024-10-02 09:02:27 +02:00
parent ad548b8f03
commit 514b49160e
Signed by: so-rose
GPG Key ID: AD901CB0F3701434
85 changed files with 370 additions and 1232 deletions

View File

@ -14,21 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# oscillode Copyright (C) 2024 oscillode Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""A visual DSL for electromagnetic simulation design and analysis implemented as a Blender node editor.""" """A visual DSL for electromagnetic simulation design and analysis implemented as a Blender node editor."""
from . import assets, node_trees, operators, preferences, registration from . import assets, node_trees, operators, preferences, registration

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import geonodes from . import geonodes
BL_REGISTER = [ BL_REGISTER = [

View File

@ -14,29 +14,12 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Provides for the linking and/or appending of geometry nodes trees from vendored libraries included in Blender maxwell.""" """Provides for the linking and/or appending of geometry nodes trees from vendored libraries included in Blender maxwell."""
import enum import enum
from pathlib import Path from pathlib import Path
import bpy import bpy
from blender_maxwell import contracts as ct from blender_maxwell import contracts as ct
from blender_maxwell.utils import logger from blender_maxwell.utils import logger
@ -401,7 +384,7 @@ class GeoNodesToStructureNode(bpy.types.Operator):
#################### ####################
def invoke( def invoke(
self, context: bpy.types.Context, _: bpy.types.Event self, context: bpy.types.Context, _: bpy.types.Event
) -> set[ct.BLOperatorStatus]: ) -> ct.BLOperatorStatus:
"""Commences the drag-and-drop of a GeoNodes asset. """Commences the drag-and-drop of a GeoNodes asset.
- Starts the modal timer, which listens for a mouse-release event. - Starts the modal timer, which listens for a mouse-release event.

View File

@ -14,21 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Independent constants and types, which represent a kind of 'social contract' governing communication between all components of the addon."""
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import addon from . import addon
from .bl import ( from .bl import (
@ -53,13 +39,18 @@ from .bl import (
PropName, PropName,
SocketName, SocketName,
) )
from .bl_types import BLEnumStrEnum from .icons import Icon
from .mobj_types import ManagedObjType
from .node_tree_types import (
NodeTreeType,
)
from .operator_types import ( from .operator_types import (
OperatorType, OperatorType,
) )
from .panel_types import ( from .panel_types import (
PanelType, PanelType,
) )
from .unit_systems import UNITS_BLENDER, UNITS_TIDY3D
__all__ = [ __all__ = [
'addon', 'addon',
@ -80,12 +71,16 @@ __all__ = [
'BLSpaceType', 'BLSpaceType',
'KeymapItemDef', 'KeymapItemDef',
'ManagedObjName', 'ManagedObjName',
'ManagedObjType',
'PresetName', 'PresetName',
'PropName', 'PropName',
'SocketName', 'SocketName',
'BLEnumStrEnum', 'Icon',
'BLInstance', 'BLInstance',
'InstanceID', 'InstanceID',
'NodeTreeType',
'OperatorType', 'OperatorType',
'PanelType', 'PanelType',
'UNITS_BLENDER',
'UNITS_TIDY3D',
] ]

View File

@ -62,8 +62,8 @@ def operator(
raise ValueError(msg) raise ValueError(msg)
# Run Operator # Run Operator
operator = getattr(getattr(bpy.ops, NAME), operator_name) bl_operator = getattr(getattr(bpy.ops, NAME), operator_name)
operator(*operator_args, **operator_kwargs) bl_operator(*operator_args, **operator_kwargs)
## TODO: Can't we constrain 'name' to be an OperatorType somehow? ## TODO: Can't we constrain 'name' to be an OperatorType somehow?

View File

@ -14,21 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Explicit type annotations for Blender objects, making it easier to guarantee correctness in communications with Blender."""
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import typing as typ import typing as typ

View File

@ -1,44 +0,0 @@
# oscillode
# Copyright (C) 2024 oscillode Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import typing as typ
####################
# - Blender Enum (w/EnumProperty support)
####################
class BLEnumStrEnum(typ.Protocol):
@staticmethod
def to_name(value: typ.Self) -> str: ...
@staticmethod
def to_icon(value: typ.Self) -> str: ...

View File

@ -14,26 +14,14 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Provides an enum that semantically constrains the use of icons throughout the addon."""
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum
class Icon(enum.StrEnum): class Icon(enum.StrEnum):
"""Identifiers for icons used throughout this addon."""
# Node Tree # Node Tree
SimNodeEditor = 'MOD_SIMPLEDEFORM' SimNodeEditor = 'MOD_SIMPLEDEFORM'

View File

@ -30,12 +30,16 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Provides identifiers for objects in Blender that are managed on behalf of the user, for use by the addon, in order to provide a safe and streamlined integration of more complex data representations that flow between the addon and Blender."""
import enum import enum
from blender_maxwell.utils import blender_type_enum from blender_maxwell.utils import blender_type_enum
class ManagedObjType(blender_type_enum.BlenderTypeEnum): class ManagedObjType(blender_type_enum.BlenderTypeEnum):
"""Identifiers for 'managed objects', which encapsulates a particular Blender object and provides alternative semantics more suited to the needs of this addon."""
ManagedBLImage = enum.auto() ManagedBLImage = enum.auto()
ManagedBLCollection = enum.auto() ManagedBLCollection = enum.auto()

View File

@ -0,0 +1,28 @@
# oscillode
# Copyright (C) 2024 oscillode Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Provides identifiers for node trees defined by this addon."""
import enum
from oscillode.utils import blender_type_enum
@blender_type_enum.append_cls_name_to_values
class NodeTreeType(blender_type_enum.BlenderTypeEnum):
"""Identifiers for addon-defined node trees."""
MaxwellSim = enum.auto()

View File

@ -14,27 +14,12 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Provides identifiers for Blender operators defined by this addon."""
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Defines Operator Types as an enum, making it easy for any part of the addon to refer to any operator."""
import enum import enum
from ..utils import blender_type_enum from oscillode.utils import blender_type_enum
from .addon import NAME as ADDON_NAME from .addon import NAME as ADDON_NAME

View File

@ -14,27 +14,11 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Defines Panel Types as an enum, making it easy for any part of the addon to refer to any panel.""" """Defines Panel Types as an enum, making it easy for any part of the addon to refer to any panel."""
import enum import enum
from blender_maxwell.nodeps.utils import blender_type_enum from oscillode.utils import blender_type_enum
from .addon import NAME as ADDON_NAME from .addon import NAME as ADDON_NAME

View File

@ -14,23 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Provides particular pre-defined unit systems for use by the addon.
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Specifies unit systems for use in the node tree.
Attributes: Attributes:
UNITS_BLENDER: A unit system that serves as a reasonable default for the a 3D workspace that interprets the results of electromagnetic simulations. UNITS_BLENDER: A unit system that serves as a reasonable default for the a 3D workspace that interprets the results of electromagnetic simulations.
@ -45,7 +29,7 @@ import typing as typ
import sympy.physics.units as spu import sympy.physics.units as spu
from frozendict import frozendict from frozendict import frozendict
from blender_maxwell.utils import sympy_extra as spux from oscillode.utils import sympy_extra as spux
#################### ####################
# - Unit Systems # - Unit Systems

View File

@ -14,29 +14,10 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Provides various useful managed objects, which enables the clean and safe use of objects external to this addon."""
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .base import ManagedObj from .base import ManagedObj
# from .managed_bl_empty import ManagedBLEmpty
from .managed_bl_image import ManagedBLImage from .managed_bl_image import ManagedBLImage
# from .managed_bl_collection import ManagedBLCollection
# from .managed_bl_object import ManagedBLObject
from .managed_bl_mesh import ManagedBLMesh from .managed_bl_mesh import ManagedBLMesh
# from .managed_bl_volume import ManagedBLVolume # from .managed_bl_volume import ManagedBLVolume
@ -44,13 +25,8 @@ from .managed_bl_modifier import ManagedBLModifier
__all__ = [ __all__ = [
'ManagedObj', 'ManagedObj',
#'ManagedBLEmpty',
'ManagedBLImage', 'ManagedBLImage',
#'ManagedBLCollection',
#'ManagedBLObject',
'ManagedBLMesh', 'ManagedBLMesh',
#'ManagedBLVolume', #'ManagedBLVolume',
'ManagedBLModifier', 'ManagedBLModifier',
] ]
## REMEMBER: Add the appropriate entry to the bl_cache.DECODER

View File

@ -0,0 +1,125 @@
# oscillode
# Copyright (C) 2024 oscillode Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Provides the base protocol on which all ManagedObjs are derived, as well as explicit protocols describing common features supported by some `ManagedObjs`."""
import abc
import typing as typ
from blender_maxwell.utils import logger, serialize
from .. import contracts as ct
log = logger.get(__name__)
class ManagedObj(typ.Protocol):
"""A weak name-based reference to some kind of object external to this software.
While the object doesn't have to come from Blender's `bpy.types`, that is the driving motivation for this class: To encapsulate access to the powerful visual tools granted by Blender's 3D viewport, image editor, and UI.
Through extensive trial-and-error, this transparently-cached immediate-mode interface has emerged as the best compromise.
While not suited to all use cases, the `ManagedObj` paradigm is ideal for the common situation of 'node ownership of external logic'.
For example, a plotting node needs access to its own image buffer; however, for it to be displayable, that image buffer must be owned by Blender.
This is where `ManagedObj` provides the ability of the plotting node to "loosely own" a particular Blender image, which both allows the user to see/interact with the image as a typical Blender image, but also allows the node to drive ex. lifecycle (like removing the image plot when the node is deleted).
This approach of loose name-coupling is not perfect. To name a few examples:
- A particular challenge is that of identifying and namespacing managed datablocks. The user may, for example, change the name of an object - and what do we do then? Is generating new data under the now-vacant name a feature? Or is it a systematic memory leak backed by dangling fake-owned datablocks?
- The precise definition of "loose ownership" is itself a matter of taste. Stronger ownership presumptions allow for stronger guarantees and simpler caching - but at the cost of more brittle breaks when the underlying objects are manipulated in ways we don't expect.
- `.blend` persistance is not the default when it comes to certain Blender objects, which raises deeper UX questions about how opinionated we should be about where users put data.
- Solving this doesn't help actually deal with data. There's a lot of very specific nuance in every single data pipeline, and that complexity is only added to watever this approach incurs.
This abstract base class serves to provide a few of the most basic of commonly-available operations.
In particular, implementations of `dump_as_msgspec`/`parse_as_msgspec` are enforced, for use with `oscillode.utils.serialize`.
This way, ex. opening a `.blend` file will allow a newly-deserialized `ManagedObj` to re-attach transparently to the also-persisted underlying datablock.
Parameters:
managed_obj_type: Enum identifier indicating which of the `ct.ManagedObjType` the instance should declare itself as.
"""
managed_obj_type: ct.ManagedObjType
@abc.abstractmethod
def __init__(self, name: ct.ManagedObjName, prev_name: str | None = None):
"""Initializes the managed object with a unique name.
Use `prev_name` to indicate that the managed object will initially be avaiable under `prev_name`, but that it should be renamed to `name`.
"""
####################
# - Properties
####################
@property
@abc.abstractmethod
def name(self) -> str:
"""Retrieve the name of the managed object."""
@name.setter
@abc.abstractmethod
def name(self, value: str) -> None:
"""Retrieve the name of the managed object."""
####################
# - Methods
####################
@abc.abstractmethod
def free(self) -> None:
"""Cleanup the resources managed by the managed object."""
@abc.abstractmethod
def hide_preview(self) -> None:
"""Hide any active preview of the managed object, if it exists, and if such an operation makes sense."""
####################
# - Serialization
####################
def dump_as_msgspec(self) -> serialize.NaiveRepresentation:
"""Bijectively transform this managed object into a 'naive representation' that uses only basic Python types, which may be serialized cleanly."""
return [
serialize.TypeID.ManagedObj,
self.__class__.__name__,
self.name,
]
@staticmethod
def parse_as_msgspec(obj: serialize.NaiveRepresentation) -> typ.Self:
"""Bijectively construct an instance of this managed object from the 'naive representation', which may have been deserialized into."""
return next(
subclass(obj[2])
for subclass in ManagedObj.__subclasses__()
if subclass.__name__ == obj[1]
)
####################
# - Support Flags
####################
class SupportsBlenderSelect(typ.Protocol):
"""Protocol guaranteeing the ability to select the object in Blender."""
def bl_select(self) -> None:
"""Select the managed object in Blender."""
class Supportsreview(typ.Protocol):
"""Protocol guaranteeing support for previewing the object."""
def show_preview(self) -> None:
"""Shows a preview of the managed object."""
def hide_preview(self) -> None:
"""Hide any active preview of the managed object, if it exists."""

View File

@ -32,12 +32,12 @@
import bpy import bpy
from blender_maxwell.utils import logger from oscillode.utils import logger
log = logger.get(__name__) log = logger.get(__name__)
MANAGED_COLLECTION_NAME = 'BLMaxwell' MANAGED_COLLECTION_NAME = 'Oscillode'
PREVIEW_COLLECTION_NAME = 'BLMaxwell Visible' PREVIEW_COLLECTION_NAME = 'Oscillode Visible'
#################### ####################

View File

@ -14,23 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Declares an object encapsulating access to a Blender image datablock from this addon."""
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Declares `ManagedBLImage`."""
import time import time
import typing as typ import typing as typ
@ -39,15 +23,17 @@ import bpy
import matplotlib.axis as mpl_ax import matplotlib.axis as mpl_ax
import numpy as np import numpy as np
from blender_maxwell.utils import image_ops, logger from oscillode.utils import image_ops, logger
from .. import contracts as ct from .. import contracts as ct
from . import base from . import base
log = logger.get(__name__) log = logger.get(__name__)
AREA_TYPE = 'IMAGE_EDITOR' AREA_TYPE: ct.BLSpaceType = (
SPACE_TYPE = 'IMAGE_EDITOR' 'IMAGE_EDITOR' ##TODO: Is SpaceType different than AreaType?
)
SPACE_TYPE: ct.BLSpaceType = 'IMAGE_EDITOR'
#################### ####################
@ -60,7 +46,7 @@ class ManagedBLImage(base.ManagedObj):
name: The name of the image. name: The name of the image.
""" """
managed_obj_type = ct.ManagedObjType.ManagedBLImage managed_obj_type: str = ct.ManagedObjType.ManagedBLImage
_bl_image_name: str _bl_image_name: str
def __init__(self, name: str, prev_name: str | None = None): def __init__(self, name: str, prev_name: str | None = None):
@ -186,6 +172,7 @@ class ManagedBLImage(base.ManagedObj):
#################### ####################
# - Methods # - Methods
#################### ####################
## TODO: Rename to show_preview()
def bl_select(self) -> None: def bl_select(self) -> None:
"""Selects the image by loading it into an on-screen UI area/space. """Selects the image by loading it into an on-screen UI area/space.

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import contextlib import contextlib
import bmesh import bmesh
@ -37,7 +21,7 @@ import bpy
import jax import jax
import numpy as np import numpy as np
from blender_maxwell.utils import logger from oscillode.utils import logger
from .. import contracts as ct from .. import contracts as ct
from . import base from . import base

View File

@ -14,31 +14,17 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""A managed Blender modifier, associated with some Blender object.""" """A managed Blender modifier, associated with some Blender object."""
## TODO: Make a common core for modifier manipulation, then specify each modifier as a seperate ManagedObj.
import typing as typ import typing as typ
import bpy import bpy
import jax import jax
import numpy as np import numpy as np
from blender_maxwell.utils import logger from oscillode.utils import logger
from .. import bl_socket_map from .. import bl_socket_map
from .. import contracts as ct from .. import contracts as ct
@ -170,6 +156,8 @@ def write_modifier(
# - ManagedObj # - ManagedObj
#################### ####################
class ManagedBLModifier(base.ManagedObj): class ManagedBLModifier(base.ManagedObj):
"""Manages a particular modifier attached to a Blender mesh also managed by this construction."""
managed_obj_type = ct.ManagedObjType.ManagedBLModifier managed_obj_type = ct.ManagedObjType.ManagedBLModifier
_modifier_name: str | None = None _modifier_name: str | None = None
twin_bl_mesh: ManagedBLMesh | None = None twin_bl_mesh: ManagedBLMesh | None = None

View File

@ -14,32 +14,13 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Declares `ManagedBLText`.""" """Declares `ManagedBLText`."""
import time
import typing as typ import typing as typ
import bpy import bpy
import matplotlib.axis as mpl_ax
import numpy as np
from blender_maxwell.utils import image_ops, logger from oscillode.utils import logger
from .. import contracts as ct from .. import contracts as ct
from . import base from . import base
@ -54,10 +35,10 @@ SPACE_TYPE = 'IMAGE_EDITOR'
# - Managed BL Image # - Managed BL Image
#################### ####################
class ManagedBLText(base.ManagedObj): class ManagedBLText(base.ManagedObj):
"""Represents a Blender Image datablock, encapsulating various useful interactions with it. """Represents a Blender text datablock, encapsulating various useful interactions with it.
Attributes: Attributes:
name: The name of the image. name: The name of the text datablock.
""" """
managed_obj_type = ct.ManagedObjType.ManagedBLText managed_obj_type = ct.ManagedObjType.ManagedBLText

View File

@ -46,6 +46,8 @@ from . import sockets
log = _logger.get(__name__) log = _logger.get(__name__)
## TODO: Coordinate w/refactor of managed modifiers; for example, the contents of this file would be ideally specified as the implementation of a Protocol, for the particular case of this node tree.
#################### ####################
# - Blender -> Socket Def(s) # - Blender -> Socket Def(s)

View File

@ -38,6 +38,9 @@ import nodeitems_utils
from . import contracts as ct from . import contracts as ct
from .nodes import BL_NODES from .nodes import BL_NODES
## TODO: Completely refactor this file, and rename it to reflect that it doesn't define or implement any categories - it simply, dumbly, implements the menu.
## - Actually; we could delete this file by refactoring it, implementing the logic in a utils/ module, then running the dangling registration as a rote-registration matter in __init__.py.
DYNAMIC_SUBMENU_REGISTRATIONS = [] DYNAMIC_SUBMENU_REGISTRATIONS = []
@ -117,7 +120,7 @@ BL_REGISTER = [*DYNAMIC_SUBMENU_REGISTRATIONS] ## Must be run after, right now.
def menu_draw(self, context): def menu_draw(self, context):
if context.space_data.tree_type == ct.TreeType.MaxwellSim.value: if context.space_data.tree_type == ct.NodeTreeType.MaxwellSim.value:
for nodeitem_or_submenu in BL_NODE_CATEGORIES: for nodeitem_or_submenu in BL_NODE_CATEGORIES:
if isinstance(nodeitem_or_submenu, str): if isinstance(nodeitem_or_submenu, str):
submenu_id = nodeitem_or_submenu submenu_id = nodeitem_or_submenu

View File

@ -31,6 +31,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from blender_maxwell.contracts import ( from blender_maxwell.contracts import (
UNITS_BLENDER,
UNITS_TIDY3D,
BLClass, BLClass,
BLColorRGBA, BLColorRGBA,
BLEnumElement, BLEnumElement,
@ -45,8 +47,11 @@ from blender_maxwell.contracts import (
BLPropFlag, BLPropFlag,
BLRegionType, BLRegionType,
BLSpaceType, BLSpaceType,
Icon,
KeymapItemDef, KeymapItemDef,
ManagedObjName, ManagedObjName,
ManagedObjType,
NodeTreeType,
OperatorType, OperatorType,
PanelType, PanelType,
PresetName, PresetName,
@ -72,8 +77,6 @@ from .flow_kinds import (
ValueFlow, ValueFlow,
) )
from .flow_signals import FlowSignal from .flow_signals import FlowSignal
from .icons import Icon
from .mobj_types import ManagedObjType
from .node_types import NodeType from .node_types import NodeType
from .sim_types import ( from .sim_types import (
BoundCondType, BoundCondType,
@ -90,8 +93,6 @@ from .sim_types import (
) )
from .socket_colors import SOCKET_COLORS from .socket_colors import SOCKET_COLORS
from .socket_types import SocketType from .socket_types import SocketType
from .tree_types import TreeType
from .unit_systems import UNITS_BLENDER, UNITS_TIDY3D
__all__ = [ __all__ = [
'BLClass', 'BLClass',
@ -108,16 +109,17 @@ __all__ = [
'BLPropFlag', 'BLPropFlag',
'BLRegionType', 'BLRegionType',
'BLSpaceType', 'BLSpaceType',
'Icon',
'KeymapItemDef', 'KeymapItemDef',
'ManagedObjName', 'ManagedObjName',
'ManagedObjType',
'NodeTreeType',
'OperatorType', 'OperatorType',
'PanelType', 'PanelType',
'PresetName', 'PresetName',
'PropName', 'PropName',
'SocketName', 'SocketName',
'addon', 'addon',
'Icon',
'TreeType',
'SocketType', 'SocketType',
'SOCKET_COLORS', 'SOCKET_COLORS',
'SOCKET_SHAPES', 'SOCKET_SHAPES',
@ -139,7 +141,6 @@ __all__ = [
'manual_amp_time', 'manual_amp_time',
'NodeCategory', 'NodeCategory',
'NODE_CAT_LABELS', 'NODE_CAT_LABELS',
'ManagedObjType',
'FlowEvent', 'FlowEvent',
'ArrayFlow', 'ArrayFlow',
'CapabilitiesFlow', 'CapabilitiesFlow',

View File

@ -30,6 +30,8 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
## TODO: Unify w/category_types.py
from .category_types import NodeCategory as NC # noqa: N817 from .category_types import NodeCategory as NC # noqa: N817
NODE_CAT_LABELS = { NODE_CAT_LABELS = {

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum
from blender_maxwell.utils import blender_type_enum from blender_maxwell.utils import blender_type_enum

View File

@ -14,23 +14,9 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Socket base colors for Maxwell Sim sockets."""
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .socket_types import SocketType as ST from .socket_types import SocketType as ST # noqa: N817
## TODO: Don't just presume sRGB. ## TODO: Don't just presume sRGB.
SOCKET_COLORS = { SOCKET_COLORS = {

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum
from blender_maxwell.utils import blender_type_enum from blender_maxwell.utils import blender_type_enum
@ -37,6 +21,8 @@ from blender_maxwell.utils import blender_type_enum
@blender_type_enum.append_cls_name_to_values @blender_type_enum.append_cls_name_to_values
class SocketType(blender_type_enum.BlenderTypeEnum): class SocketType(blender_type_enum.BlenderTypeEnum):
"""Identifiers for valid sockets in Maxwell Sim node trees."""
Expr = enum.auto() Expr = enum.auto()
# Base # Base

View File

@ -1,40 +0,0 @@
# oscillode
# Copyright (C) 2024 oscillode Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum
from blender_maxwell.utils import blender_type_enum
@blender_type_enum.append_cls_name_to_values
class TreeType(blender_type_enum.BlenderTypeEnum):
MaxwellSim = enum.auto()

View File

@ -1,111 +0,0 @@
# oscillode
# Copyright (C) 2024 oscillode Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import abc
import typing as typ
from blender_maxwell.utils import logger, serialize
from .. import contracts as ct
log = logger.get(__name__)
class ManagedObj(abc.ABC):
"""A weak name-based reference to some kind of object external to this software.
While the object doesn't have to come from Blender's `bpy.types`, that is admittedly the driving motivation for this class: To encapsulate access to the powerful visual tools granted by Blender's 3D viewport, image editor, and UI.
Through extensive testing, the functionality of an implicitly-cached, semi-strictly immediate-mode interface, demanding only a weakly-referenced name as persistance, has emerged (with all of the associated tradeoffs).
While not suited to all use cases, the `ManagedObj` paradigm is perfect for many situations where a node needs to "loosely own" something external and non-trivial.
Intriguingly, the precise definition of "loose" has grown to vary greatly between subclasses, as it ends of demonstrating itself to be a matter of taste more than determinism.
This abstract base class serves to provide a few of the most basic of commonly-available - especially the `dump_as_msgspec`/`parse_as_msgspec` methods that allow it to be persisted using `blender_maxwell.utils.serialize`.
Parameters:
managed_obj_type: Enum identifier indicating which of the `ct.ManagedObjType` the instance should declare itself as.
"""
managed_obj_type: ct.ManagedObjType
@abc.abstractmethod
def __init__(self, name: ct.ManagedObjName, prev_name: str | None = None):
"""Initializes the managed object with a unique name.
Use `prev_name` to indicate that the managed object will initially be avaiable under `prev_name`, but that it should be renamed to `name`.
"""
####################
# - Properties
####################
@property
@abc.abstractmethod
def name(self) -> str:
"""Retrieve the name of the managed object."""
@name.setter
@abc.abstractmethod
def name(self, value: str) -> None:
"""Retrieve the name of the managed object."""
####################
# - Methods
####################
@abc.abstractmethod
def free(self) -> None:
"""Cleanup the resources managed by the managed object."""
@abc.abstractmethod
def bl_select(self) -> None:
"""Select the managed object in Blender, if such an operation makes sense."""
@abc.abstractmethod
def hide_preview(self) -> None:
"""Hide any active preview of the managed object, if it exists, and if such an operation makes sense."""
####################
# - Serialization
####################
def dump_as_msgspec(self) -> serialize.NaiveRepresentation:
return [
serialize.TypeID.ManagedObj,
self.__class__.__name__,
self.name,
]
@staticmethod
def parse_as_msgspec(obj: serialize.NaiveRepresentation) -> typ.Self:
return next(
subclass(obj[2])
for subclass in ManagedObj.__subclasses__()
if subclass.__name__ == obj[1]
)

View File

@ -1,32 +0,0 @@
# oscillode
# Copyright (C) 2024 oscillode Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

View File

@ -14,33 +14,17 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell # TODO: Factor this stuff into a dedicated utils/ module, so that this particular node tree becomes simple (aka. the deathly complicated logic is factored out, and can be ex. unit tested all on its own).
# Copyright (C) 2024 blender_maxwell Project Contributors ## - Then this file can focus on what is special about a Maxwell Sim node tree, as opposed to the lower-level details of how we've chosen to structure our node trees in general.
# ## - Right now there may not be a distinction. And there may never be. But it's a healthy way to think about the problem.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import contextlib
import functools
import queue import queue
import typing as typ import typing as typ
import bpy import bpy
from blender_maxwell.utils import logger
from blender_maxwell.utils import logger, serialize
from . import contracts as ct from . import contracts as ct
from .managed_objs.managed_bl_image import ManagedBLImage
log = logger.get(__name__) log = logger.get(__name__)
@ -320,7 +304,7 @@ class MaxwellSimTree(bpy.types.NodeTree):
In general, only one `MaxwellSimTree` should be active at a time. In general, only one `MaxwellSimTree` should be active at a time.
""" """
bl_idname = ct.TreeType.MaxwellSim.value bl_idname = ct.NodeTreeType.MaxwellSim.value
bl_label = 'Maxwell Sim Editor' bl_label = 'Maxwell Sim Editor'
bl_icon = ct.Icon.SimNodeEditor bl_icon = ct.Icon.SimNodeEditor
@ -552,7 +536,8 @@ def populate_missing_persistence(_) -> None:
for node_tree in [ for node_tree in [
_node_tree _node_tree
for _node_tree in bpy.data.node_groups for _node_tree in bpy.data.node_groups
if _node_tree.bl_idname == ct.TreeType.MaxwellSim.value and _node_tree.is_active if _node_tree.bl_idname == ct.NodeTreeType.MaxwellSim.value
and _node_tree.is_active
]: ]:
log.debug( log.debug(
'%s: Regenerating Dynamic Field Persistance for NodeTree nodes/sockets', '%s: Regenerating Dynamic Field Persistance for NodeTree nodes/sockets',

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import ( from . import (
analysis, analysis,
inputs, inputs,

View File

@ -1196,7 +1196,7 @@ class MaxwellSimNode(bpy.types.Node, bl_instance.BLInstance):
Returns: Returns:
Whether or not the node can be instantiated within the given node tree. Whether or not the node can be instantiated within the given node tree.
""" """
return node_tree.bl_idname == ct.TreeType.MaxwellSim.value return node_tree.bl_idname == ct.NodeTreeType.MaxwellSim
def init(self, _: bpy.types.Context) -> None: def init(self, _: bpy.types.Context) -> None:
"""Initialize the node instance, including ID, name, socket, presets, and the execution of any `on_value_changed` methods with the `run_on_init` keyword set. """Initialize the node instance, including ID, name, socket, presets, and the execution of any `on_value_changed` methods with the `run_on_init` keyword set.

View File

@ -146,7 +146,8 @@ def update_scene_node_after_frame_changed(
for node_tree in [ for node_tree in [
_node_tree _node_tree
for _node_tree in bpy.data.node_groups for _node_tree in bpy.data.node_groups
if _node_tree.bl_idname == ct.TreeType.MaxwellSim.value and _node_tree.is_active if _node_tree.bl_idname == ct.NodeTreeType.MaxwellSim.value
and _node_tree.is_active
]: ]:
for node in [ for node in [
_node _node

View File

@ -385,7 +385,7 @@ class ExprBLSocket(base.MaxwellSimSocket):
#################### ####################
lazy_range_name: sim_symbols.SimSymbolName = bl_cache.BLField( lazy_range_name: sim_symbols.SimSymbolName = bl_cache.BLField(
sim_symbols.SimSymbolName.Expr sim_symbols.SimSymbolName.Expr
) ) ## TODO: Delete (...what is it for?)
output_name: sim_symbols.SimSymbolName = bl_cache.BLField( output_name: sim_symbols.SimSymbolName = bl_cache.BLField(
sim_symbols.SimSymbolName.Constant sim_symbols.SimSymbolName.Constant
) )
@ -989,6 +989,7 @@ class ExprBLSocket(base.MaxwellSimSocket):
#################### ####################
# - FlowKind: Func (w/Params if Constant) # - FlowKind: Func (w/Params if Constant)
#################### ####################
## TODO: Consider some way of checking compatibility between the three.
@bl_cache.cached_bl_property(depends_on={'output_sym'}) @bl_cache.cached_bl_property(depends_on={'output_sym'})
def lazy_func(self) -> ct.FuncFlow: def lazy_func(self) -> ct.FuncFlow:
"""Returns a lazy value that computes the expression returned by `self.value`. """Returns a lazy value that computes the expression returned by `self.value`.
@ -1076,6 +1077,7 @@ class ExprBLSocket(base.MaxwellSimSocket):
#################### ####################
# - FlowKind: Capabilities # - FlowKind: Capabilities
#################### ####################
## TODO: Rename to 'capabilities_when_linked'
def linked_capabilities(self, info: ct.InfoFlow) -> ct.CapabilitiesFlow: def linked_capabilities(self, info: ct.InfoFlow) -> ct.CapabilitiesFlow:
"""When this socket is linked as an output socket, expose these capabilities instead of querying `self.capabilities`. """When this socket is linked as an output socket, expose these capabilities instead of querying `self.capabilities`.

View File

@ -14,21 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Blender operators that ship with Oscillode."""
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import connect_viewer from . import connect_viewer

View File

@ -14,74 +14,98 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Operator allowing the user to use the conventional CTRL+SHIFT+LMB to connect arbitrary node outputs to either an existing, or a new, viewer node."""
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import bpy import bpy
from blender_maxwell import contracts as ct from oscillode import contracts as ct
from blender_maxwell.utils import logger from oscillode.node_trees.maxwell_sim_nodes.contracts import node_types
from oscillode.utils import logger
log = logger.get(__name__) log = logger.get(__name__)
class ConnectViewerNode(bpy.types.Operator): class ConnectViewerNode(bpy.types.Operator):
"""Connecting the viewer node to the active node in a Maxwell Sim node tree, as defined by selection and mouse-cursor location.
If there is no active viewer node, then one is created.
"""
bl_idname = ct.OperatorType.ConnectViewerNode bl_idname = ct.OperatorType.ConnectViewerNode
bl_label = 'Connect Viewer to Active' bl_label = 'Connect Viewer to Active'
bl_description = 'Connect active node to Viewer Node' bl_description = 'Connect active node to Viewer Node'
bl_options = {'REGISTER', 'UNDO'} bl_options = frozenset({'REGISTER', 'UNDO'})
@classmethod @classmethod
def poll(cls, context): def poll(cls, context: bpy.types.Context) -> bool:
"""Require the active space to be a Maxwell Sim node tree defined by this addon.
Notes:
Run by Blender when determining whether the operator can run.
Returns:
Whether the operator can run.
"""
space = context.space_data space = context.space_data
return ( return (
space.type == 'NODE_EDITOR' space.type == 'NODE_EDITOR'
and space.node_tree is not None and space.node_tree is not None
and space.node_tree.bl_idname == 'MaxwellSimTreeType' and space.node_tree.bl_idname == ct.NodeTreeType.MaxwellSim
) )
def invoke(self, context, event): def invoke(
self, context: bpy.types.Context, event: bpy.types.Event
) -> ct.BLOperatorStatus:
"""Require the active space to be a particular node tree defined by this addon.
Notes:
Run by Blender when determining whether the operator can run.
Returns:
Whether the operator can run.
"""
node_tree = context.space_data.node_tree node_tree = context.space_data.node_tree
# Retrieve Mouse Location
mlocx = event.mouse_region_x mlocx = event.mouse_region_x
mlocy = event.mouse_region_y mlocy = event.mouse_region_y
# Select Node at Location
## - Deselect all other nodes.
bpy.ops.node.select( bpy.ops.node.select(
extend=False, extend=False,
location=(mlocx, mlocy), location=(mlocx, mlocy),
) )
select_node = context.selected_nodes[0] selected_node = context.selected_nodes[0]
# Find Viewer Node...
for node in node_tree.nodes: for node in node_tree.nodes:
if node.bl_idname == 'ViewerNodeType': # TODO: Support multiple viewer nodes.
if hasattr(node, 'node_type') and node.node_type is node_types.Viewer:
viewer_node = node viewer_node = node
break break
else:
viewer_node = node_tree.nodes.new('ViewerNodeType')
viewer_node.location.x = select_node.location.x + 250
viewer_node.location.y = select_node.location.y
select_node.select = False
new_link = True # ...OR: Create Viewer Node
else:
# TODO: Place viewer where it doesn't overlap other nodes.
viewer_node = node_tree.nodes.new(node_types.Viewer.value)
viewer_node.location.x = selected_node.location.x + 250
viewer_node.location.y = selected_node.location.y
selected_node.select = False
# Remove Input Links from Viewer
## - Unless the selected node is already linked to the viewer.
should_create_new_link = True
for link in viewer_node.inputs[0].links: for link in viewer_node.inputs[0].links:
if link.from_node.name == select_node.name: if link.from_node.name == selected_node.name:
new_link = False should_create_new_link = False
continue continue
node_tree.links.remove(link) node_tree.links.remove(link)
if new_link: # Create Link from Selected Node to Viewer
node_tree.links.new(select_node.outputs[0], viewer_node.inputs[0]) if should_create_new_link:
node_tree.links.new(selected_node.outputs[0], viewer_node.inputs[0])
return {'FINISHED'} return {'FINISHED'}

View File

@ -18,8 +18,6 @@
Attributes: Attributes:
_ADDON_KEYMAP: Addon-specific keymap used to register operator hotkeys. _ADDON_KEYMAP: Addon-specific keymap used to register operator hotkeys.
DELAYED_REGISTRATIONS: Currently pending registration operations, which can be realized with `run_delayed_registration()`.
REG__CLASSES: Currently registered Blender classes. REG__CLASSES: Currently registered Blender classes.
_REGISTERED_HOTKEYS: Currently registered Blender keymap items. _REGISTERED_HOTKEYS: Currently registered Blender keymap items.
""" """

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Defines a sane interface to the Tidy3D cloud, as constructed by reverse-engineering the official open-source `tidy3d` client library. """Defines a sane interface to the Tidy3D cloud, as constructed by reverse-engineering the official open-source `tidy3d` client library.
- SimulationTask: <https://github.com/flexcompute/tidy3d/blob/453055e89dcff6d619597120b47817e996f1c198/tidy3d/web/core/task_core.py> - SimulationTask: <https://github.com/flexcompute/tidy3d/blob/453055e89dcff6d619597120b47817e996f1c198/tidy3d/web/core/task_core.py>
@ -48,7 +32,7 @@ import bpy
import tidy3d as td import tidy3d as td
import tidy3d.web as td_web import tidy3d.web as td_web
from blender_maxwell.utils import logger from oscillode.utils import logger
log = logger.get(__name__) log = logger.get(__name__)

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Package providing various tools to handle cached data on Blender objects, especially nodes and node socket classes.""" """Package providing various tools to handle cached data on Blender objects, especially nodes and node socket classes."""
from ..keyed_cache import KeyedCache, keyed_cache from ..keyed_cache import KeyedCache, keyed_cache

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Implements various key caches on instances of Blender objects, especially nodes and sockets.""" """Implements various key caches on instances of Blender objects, especially nodes and sockets."""
import contextlib import contextlib
@ -39,8 +23,8 @@ import typing as typ
import bpy import bpy
from blender_maxwell import contracts as ct from oscillode import contracts as ct
from blender_maxwell.utils import bl_instance, logger from oscillode.utils import bl_instance, logger
from .bl_prop import BLProp from .bl_prop import BLProp
from .bl_prop_type import BLPropType from .bl_prop_type import BLPropType
@ -202,11 +186,12 @@ class BLField:
name: The name of the attribute that an instance of descriptor was assigned to. name: The name of the attribute that an instance of descriptor was assigned to.
""" """
prop_type = inspect.get_annotations(owner).get(name) prop_type = inspect.get_annotations(owner).get(name)
bl_prop_type = BLPropType.from_type(prop_type)
self.bl_prop = BLProp( self.bl_prop = BLProp(
name=name, name=name,
prop_info=self.prop_info, prop_info=self.prop_info,
prop_type=prop_type, prop_type=prop_type,
bl_prop_type=BLPropType.from_type(prop_type), bl_prop_type=bl_prop_type,
) )
# Initialize Field on BLClass # Initialize Field on BLClass

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Defines `BLProp`, a high-level wrapper for interacting with Blender properties.""" """Defines `BLProp`, a high-level wrapper for interacting with Blender properties."""
import dataclasses import dataclasses
@ -50,7 +34,7 @@ log = logger.get(__name__)
#################### ####################
@dataclasses.dataclass(kw_only=True, frozen=True) @dataclasses.dataclass(kw_only=True, frozen=True)
class BLProp: class BLProp:
"""A high-level wrapper encapsulating access to a Blender property. """A mid-level representation of a Blender property, which implements unsafe requests from flexible high-level fields using cache operations and normalized Blender type operations.
Attributes: Attributes:
name: The name of the Blender property, as one uses it. name: The name of the Blender property, as one uses it.

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Defines `BLPropType`, which provides stronger lower-level interfaces for interacting with data that can be conformed to work with Blender properties.""" """Defines `BLPropType`, which provides stronger lower-level interfaces for interacting with data that can be conformed to work with Blender properties."""
import builtins import builtins
@ -43,9 +27,9 @@ from pathlib import Path
import bpy import bpy
import numpy as np import numpy as np
from blender_maxwell import contracts as ct from oscillode import contracts as ct
from blender_maxwell.utils import logger, serialize from oscillode.utils import logger, serialize
from blender_maxwell.utils.staticproperty import staticproperty from oscillode.utils.staticproperty import staticproperty
from .signal import Signal from .signal import Signal
@ -106,7 +90,7 @@ def _is_bl_id_struct(T: type) -> bool: # noqa: N803
# - Blender Property Type # - Blender Property Type
#################### ####################
class BLPropType(enum.StrEnum): class BLPropType(enum.StrEnum):
"""A type identifier which can be directly associated with a Blender property. """A low-level identifier that maps directly to Blender property types.
For general use, the higher-level interface `BLProp` is more appropriate. For general use, the higher-level interface `BLProp` is more appropriate.

View File

@ -14,29 +14,13 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Implements various key caches on instances of Blender objects, especially nodes and sockets.""" """Implements various key caches on instances of Blender objects, especially nodes and sockets."""
import contextlib import contextlib
import inspect import inspect
import typing as typ import typing as typ
from blender_maxwell.utils import bl_instance, logger, serialize from oscillode.utils import bl_instance, logger, serialize
from .bl_prop import BLProp from .bl_prop import BLProp
from .bl_prop_type import BLPropType from .bl_prop_type import BLPropType

View File

@ -14,29 +14,13 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Implements various key caches on instances of Blender objects, especially nodes and sockets.""" """Implements various key caches on instances of Blender objects, especially nodes and sockets."""
## TODO: Note that persist=True on cached_bl_property may cause a draw method to try and write to a Blender property, which Blender disallows. ## TODO: Note that persist=True on cached_bl_property may cause a draw method to try and write to a Blender property, which Blender disallows.
import typing as typ import typing as typ
from blender_maxwell.utils import bl_instance, logger from oscillode.utils import bl_instance, logger
from .signal import Signal from .signal import Signal

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum
import uuid import uuid

View File

@ -14,30 +14,14 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import typing as typ import typing as typ
import uuid import uuid
from types import MappingProxyType from types import MappingProxyType
import bpy import bpy
from blender_maxwell.utils import bl_cache, logger from oscillode.utils import bl_cache, logger
from blender_maxwell.utils.keyed_cache import keyed_cache from oscillode.utils.keyed_cache import keyed_cache
InstanceID: typ.TypeAlias = str ## Stringified UUID4 InstanceID: typ.TypeAlias = str ## Stringified UUID4

View File

@ -24,8 +24,6 @@ import bpy
import jax import jax
import numpy as np import numpy as np
import pydantic as pyd import pydantic as pyd
import sympy as sp
from blender_maxwell.utils import logger from blender_maxwell.utils import logger
from blender_maxwell.utils import sympy_extra as spux from blender_maxwell.utils import sympy_extra as spux

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .array import ArrayFlow from .array import ArrayFlow
from .capabilities import CapabilitiesFlow from .capabilities import CapabilitiesFlow
from .flow_kinds import FlowKind from .flow_kinds import FlowKind

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import base64 import base64
import functools import functools
import io import io
@ -38,14 +22,13 @@ import typing as typ
import jax import jax
import jax.numpy as jnp import jax.numpy as jnp
import jaxtyping as jtyp import jaxtyping as jtyp
import numpy as np
import pydantic as pyd import pydantic as pyd
import sympy as sp import sympy as sp
from blender_maxwell.utils import logger from oscillode.utils import logger
from blender_maxwell.utils import sympy_extra as spux from oscillode.utils import sympy_extra as spux
from blender_maxwell.utils.jaxarray import JaxArrayBytes from oscillode.utils.jaxarray import JaxArrayBytes
from blender_maxwell.utils.lru_method import method_lru from oscillode.utils.lru_method import method_lru
log = logger.get(__name__) log = logger.get(__name__)

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import dataclasses import dataclasses
import typing as typ import typing as typ
from types import MappingProxyType from types import MappingProxyType

View File

@ -14,21 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell # TODO: Consider moving this to the new math system.
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import typing as typ import typing as typ

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum
import typing as typ import typing as typ

View File

@ -14,30 +14,14 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum
import functools import functools
import typing as typ import typing as typ
from blender_maxwell.contracts import BLEnumElement from oscillode.contracts import BLEnumElement
from blender_maxwell.utils import logger from oscillode.utils import logger
from blender_maxwell.utils import sympy_extra as spux from oscillode.utils import sympy_extra as spux
from blender_maxwell.utils.staticproperty import staticproperty from oscillode.utils.staticproperty import staticproperty
log = logger.get(__name__) log = logger.get(__name__)

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum
import typing as typ import typing as typ

View File

@ -36,10 +36,10 @@ import typing as typ
import pydantic as pyd import pydantic as pyd
from blender_maxwell.utils import logger, sim_symbols from oscillode.utils import logger, sim_symbols
from blender_maxwell.utils import sympy_extra as spux from oscillode.utils import sympy_extra as spux
from blender_maxwell.utils.frozendict import FrozenDict, frozendict from oscillode.utils.frozendict import FrozenDict, frozendict
from blender_maxwell.utils.lru_method import method_lru from oscillode.utils.lru_method import method_lru
from .array import ArrayFlow from .array import ArrayFlow
from .lazy_range import RangeFlow from .lazy_range import RangeFlow

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
r"""Implements the core of the math system via `FuncFlow`, which allows high-performance, fully-expressive workflows with data that can be "very large", and/or whose input parameters are not yet fully known. r"""Implements the core of the math system via `FuncFlow`, which allows high-performance, fully-expressive workflows with data that can be "very large", and/or whose input parameters are not yet fully known.
# Introduction # Introduction
@ -235,17 +219,16 @@ But above all, we hope that this math system is fun, practical, and maybe even i
import functools import functools
import typing as typ import typing as typ
from types import MappingProxyType
import jax import jax
import jaxtyping as jtyp import jaxtyping as jtyp
import pydantic as pyd import pydantic as pyd
import sympy as sp import sympy as sp
from blender_maxwell.utils import logger, sim_symbols from oscillode.utils import logger, sim_symbols
from blender_maxwell.utils import sympy_extra as spux from oscillode.utils import sympy_extra as spux
from blender_maxwell.utils.frozendict import FrozenDict, frozendict from oscillode.utils.frozendict import FrozenDict, frozendict
from blender_maxwell.utils.lru_method import method_lru from oscillode.utils.lru_method import method_lru
from .array import ArrayFlow from .array import ArrayFlow
from .info import InfoFlow from .info import InfoFlow

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum
import functools import functools
import typing as typ import typing as typ
@ -39,10 +23,10 @@ import jaxtyping as jtyp
import pydantic as pyd import pydantic as pyd
import sympy as sp import sympy as sp
from blender_maxwell.utils import logger, sim_symbols from oscillode.utils import logger, sim_symbols
from blender_maxwell.utils import sympy_extra as spux from oscillode.utils import sympy_extra as spux
from blender_maxwell.utils.frozendict import frozendict from oscillode.utils.frozendict import frozendict
from blender_maxwell.utils.lru_method import method_lru from oscillode.utils.lru_method import method_lru
from .array import ArrayFlow from .array import ArrayFlow

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import functools import functools
import typing as typ import typing as typ
from fractions import Fraction from fractions import Fraction
@ -39,10 +23,10 @@ import jaxtyping as jtyp
import pydantic as pyd import pydantic as pyd
import sympy as sp import sympy as sp
from blender_maxwell.utils import logger, sim_symbols from oscillode.utils import logger, sim_symbols
from blender_maxwell.utils import sympy_extra as spux from oscillode.utils import sympy_extra as spux
from blender_maxwell.utils.frozendict import FrozenDict, frozendict from oscillode.utils.frozendict import FrozenDict, frozendict
from blender_maxwell.utils.lru_method import method_lru from oscillode.utils.lru_method import method_lru
from .array import ArrayFlow from .array import ArrayFlow
from .expr_info import ExprInfo from .expr_info import ExprInfo

View File

@ -14,28 +14,12 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import typing as typ import typing as typ
import bpy import bpy
import pydantic as pyd import pydantic as pyd
from blender_maxwell.utils import logger from oscillode.utils import logger
IMAGE_AREA_TYPE = 'IMAGE_EDITOR' IMAGE_AREA_TYPE = 'IMAGE_EDITOR'
IMAGE_SPACE_TYPE = 'IMAGE_EDITOR' IMAGE_SPACE_TYPE = 'IMAGE_EDITOR'

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Implements a `pydantic`-compatible field, `FrozenDict`, which encapsulates a `frozendict` in a serializable way, with semantics identical to `dict`.""" """Implements a `pydantic`-compatible field, `FrozenDict`, which encapsulates a `frozendict` in a serializable way, with semantics identical to `dict`."""
import typing as typ import typing as typ

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Useful image processing operations for use in the addon.""" """Useful image processing operations for use in the addon."""
import enum import enum
@ -45,9 +29,9 @@ import matplotlib.figure
import seaborn as sns import seaborn as sns
import sympy as sp import sympy as sp
from blender_maxwell import contracts as ct from oscillode import contracts as ct
from blender_maxwell.utils import logger from oscillode.utils import logger
from blender_maxwell.utils import sympy_extra as spux from oscillode.utils import sympy_extra as spux
sns.set_theme() sns.set_theme()

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Implements a `pydantic`-compatible field, `JaxArray`, which encapsulates a `jax.Array` in a serializable way.""" """Implements a `pydantic`-compatible field, `JaxArray`, which encapsulates a `jax.Array` in a serializable way."""
import base64 import base64
@ -42,6 +26,9 @@ import numpy as np
import pydantic as pyd import pydantic as pyd
from pydantic_core import core_schema as pyd_core_schema from pydantic_core import core_schema as pyd_core_schema
# TODO: It's possible this is all pointless.
# Is https://github.com/p2p-ld/numpydantic our lord and savior?
#################### ####################
# - Simple JAX Array # - Simple JAX Array

View File

@ -14,27 +14,11 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import functools import functools
import inspect import inspect
import typing as typ import typing as typ
from blender_maxwell.utils import logger, serialize from oscillode.utils import logger, serialize
log = logger.get(__name__) log = logger.get(__name__)

View File

@ -23,7 +23,8 @@ from pathlib import Path
import rich.console import rich.console
import rich.logging import rich.logging
import rich.traceback import rich.traceback
from blender_maxwell import contracts as ct
from oscillode import contracts as ct
from ..services import init_settings from ..services import init_settings

View File

@ -14,21 +14,10 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Provides a Least Recently Used cache for methods, which uses a weak reference to `self` to attach the cache to the object.
# Copyright (C) 2024 blender_maxwell Project Contributors
# This is a specialized construct to be used carefully and sparsely, when other tradeoffs have failed. Misuse can have serious consequences.
# This program is free software: you can redistribute it and/or modify """
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import functools import functools
import weakref import weakref

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Access `scipy.constants` using `sympy` units. """Access `scipy.constants` using `sympy` units.
Notes: Notes:

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""A fast, robust `msgspec`-based serialization tool providing for string-based persistance of many objects. """A fast, robust `msgspec`-based serialization tool providing for string-based persistance of many objects.
Blender provides for strong persistence guarantees based on its `bpy.types.Property` system. Blender provides for strong persistence guarantees based on its `bpy.types.Property` system.
@ -69,7 +53,6 @@ import typing as typ
import uuid import uuid
import msgspec import msgspec
import numpy as np
import sympy as sp import sympy as sp
import tidy3d as td import tidy3d as td

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Declares a useful, flexible symbolic representation.""" """Declares a useful, flexible symbolic representation."""
from .common import ( from .common import (
@ -114,4 +98,12 @@ __all__ = [
'int_min' 'int_min'
'mk_interval' 'mk_interval'
'unicode_superscript', 'unicode_superscript',
'SimSymbolName',
'SimSymbol',
'float_max',
'float_min',
'int_max',
'int_min',
'mk_interval',
'unicode_superscript',
] ]

View File

@ -14,29 +14,13 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum
import typing as typ import typing as typ
import sympy as sp import sympy as sp
from blender_maxwell.utils import logger from oscillode.utils import logger
from blender_maxwell.utils import sympy_extra as spux from oscillode.utils import sympy_extra as spux
from .name import SimSymbolName from .name import SimSymbolName
from .sim_symbol import SimSymbol from .sim_symbol import SimSymbol
@ -210,6 +194,7 @@ class CommonSimSymbol(enum.StrEnum):
), ),
) )
## TODO: Optimize; SimSymbol is constructed an enormous amount of times!
return { return {
CSS.Index: SimSymbol( CSS.Index: SimSymbol(
sym_name=self.name, sym_name=self.name,

View File

@ -14,27 +14,11 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum import enum
import string import string
import typing as typ import typing as typ
from blender_maxwell.utils import logger from oscillode.utils import logger
log = logger.get(__name__) log = logger.get(__name__)

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Implements `SimSymbol`, a convenient representation of a symbolic variable suiteable for use when describing various mathematical and numerical interfaces.""" """Implements `SimSymbol`, a convenient representation of a symbolic variable suiteable for use when describing various mathematical and numerical interfaces."""
import functools import functools
@ -45,10 +29,10 @@ import sympy as sp
import sympy.stats as sps import sympy.stats as sps
from sympy.tensor.array.expressions import ArraySymbol from sympy.tensor.array.expressions import ArraySymbol
from blender_maxwell.utils import logger, serialize from oscillode.utils import logger, serialize
from blender_maxwell.utils import sympy_extra as spux from oscillode.utils import sympy_extra as spux
from blender_maxwell.utils.frozendict import frozendict from oscillode.utils.frozendict import frozendict
from blender_maxwell.utils.lru_method import method_lru from oscillode.utils.lru_method import method_lru
from .name import SimSymbolName from .name import SimSymbolName
from .utils import unicode_superscript from .utils import unicode_superscript
@ -95,7 +79,7 @@ class SimSymbol(pyd.BaseModel):
physical_type: spux.PhysicalType = spux.PhysicalType.NonPhysical physical_type: spux.PhysicalType = spux.PhysicalType.NonPhysical
# Units # Units
## -> 'None' indicates that no particular unit has yet been chosen. ## -> 'None' indicates that no particular unit has (yet) been chosen.
## -> When 'self.physical_type' is NonPhysical, _no unit_ can be chosen. ## -> When 'self.physical_type' is NonPhysical, _no unit_ can be chosen.
unit: spux.Unit | None = None unit: spux.Unit | None = None
@ -768,7 +752,8 @@ class SimSymbol(pyd.BaseModel):
) -> typ.Self | None: ) -> typ.Self | None:
"""Deduce a `SimSymbol` that matches the output of a given expression (and unit expression). """Deduce a `SimSymbol` that matches the output of a given expression (and unit expression).
This is an essential method, allowing for the ded This is an essential method, allowing arbitrary expressions to be assigned a correct symbolic representation.
It is also a heuristic method of parsing, which does its best to interpret the expression - but does not guarantee the expected transcription in all cases.
Notes: Notes:
`PhysicalType` **cannot be set** from an expression in the generic sense. `PhysicalType` **cannot be set** from an expression in the generic sense.

View File

@ -14,22 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys import sys
from fractions import Fraction from fractions import Fraction

View File

@ -36,7 +36,6 @@ import dataclasses
import enum import enum
import functools import functools
import typing as typ import typing as typ
from fractions import Fraction
from pathlib import Path from pathlib import Path
import jax.numpy as jnp import jax.numpy as jnp
@ -45,13 +44,13 @@ import numpy as np
import polars as pl import polars as pl
import pydantic as pyd import pydantic as pyd
import tidy3d as td import tidy3d as td
from blender_maxwell.contracts import BLEnumElement from blender_maxwell.contracts import BLEnumElement
from blender_maxwell.services import tdcloud from blender_maxwell.services import tdcloud
from blender_maxwell.utils import logger, sim_symbols from blender_maxwell.utils import logger, sim_symbols
from blender_maxwell.utils import sympy_extra as spux from blender_maxwell.utils import sympy_extra as spux
from .flow_kinds.info import InfoFlow from .flow_kinds.info import InfoFlow
## TODO: Use a Protocol interface from data_pipelines/
log = logger.get(__name__) log = logger.get(__name__)

View File

@ -14,21 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# blender_maxwell """Provides a '@staticproperty', which is like '@property', but static. It can be very useful in specific situations."""
# Copyright (C) 2024 blender_maxwell Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class staticproperty(property): # noqa: N801 class staticproperty(property): # noqa: N801

View File

@ -49,9 +49,8 @@ import jax
import jax.numpy as jnp import jax.numpy as jnp
import pydantic as pyd import pydantic as pyd
import sympy as sp import sympy as sp
from sympy.sets.setexpr import SetExpr
from blender_maxwell.utils.lru_method import method_lru from blender_maxwell.utils.lru_method import method_lru
from sympy.sets.setexpr import SetExpr
from .. import logger from .. import logger
from .math_type import MathType as MT # noqa: N817 from .math_type import MathType as MT # noqa: N817

View File

@ -170,6 +170,7 @@ ignore = [
"F722", # jaxtyping uses type annotations that ruff sees as "syntax error" "F722", # jaxtyping uses type annotations that ruff sees as "syntax error"
"N806", # Sometimes we like using types w/uppercase in functions, sue me "N806", # Sometimes we like using types w/uppercase in functions, sue me
"RUF001", # We use a lot of unicode, yes, on purpose! "RUF001", # We use a lot of unicode, yes, on purpose!
#"RUF012", # ruff misunderstands which ClassVars are actually mutable.
# Line Length - Controversy Incoming # Line Length - Controversy Incoming
## Hot Take: Let the Formatter Worry about Line Length ## Hot Take: Let the Formatter Worry about Line Length