Refactor and clean up codebase by removing unused functions and reorganizing imports
- Removed unused model keys and functions from properties.py. - Deleted projection.py as its functions were no longer needed. - Cleaned up model_catalog.py by removing unused model directory function. - Updated imports in various test files to reflect new module structure. - Removed deprecated test cases related to image editing tools. - Added new tests for ONNX runtime provider selection logic.
This commit is contained in:
@@ -3,7 +3,9 @@ from .cutout_tool import (
|
||||
CutoutSelectionToShape,
|
||||
SelectCutoutSelection,
|
||||
)
|
||||
from .image_edit_tool import CLASSES as IMAGE_EDIT_TOOL_CLASSES
|
||||
from .frame_tool import FrameImages
|
||||
from .mask_tool import EditImageAlpha
|
||||
from .rectify_tool import RectifyImagePerspective
|
||||
from .convert_to_plane import (
|
||||
ConvertToDepthPlane,
|
||||
ConvertToPlane,
|
||||
@@ -29,7 +31,9 @@ CLASSES = (
|
||||
SelectCutoutSelection,
|
||||
RunBackgroundRemoval,
|
||||
ClearModels,
|
||||
*IMAGE_EDIT_TOOL_CLASSES,
|
||||
FrameImages,
|
||||
EditImageAlpha,
|
||||
RectifyImagePerspective,
|
||||
RemoveImageBackground,
|
||||
UpscaleImage,
|
||||
ConvertToPlane,
|
||||
|
||||
@@ -1,209 +1,15 @@
|
||||
import sys
|
||||
|
||||
import bpy
|
||||
|
||||
from .actions import (
|
||||
PasteTargetError,
|
||||
acquire_packed_image,
|
||||
paste_image,
|
||||
paste_location,
|
||||
target_for_context,
|
||||
)
|
||||
from .clipboard import (
|
||||
ClipboardImageError,
|
||||
ClipboardImageUnavailable,
|
||||
clipboard_change_token,
|
||||
clipboard_image_supported,
|
||||
read_clipboard_image,
|
||||
from .operators import (
|
||||
CLASSES,
|
||||
PasteClipboardImage,
|
||||
TrackNativeCopy,
|
||||
register_keymaps,
|
||||
unregister_keymaps,
|
||||
)
|
||||
|
||||
|
||||
_keymap_items = []
|
||||
_native_copy_token = None
|
||||
|
||||
|
||||
class TrackNativeCopy(bpy.types.Operator):
|
||||
bl_idname = "anyimage.track_native_copy"
|
||||
bl_label = "Track Native Copy"
|
||||
bl_description = "Preserve Blender's native copy and paste priority"
|
||||
bl_options = {"INTERNAL"}
|
||||
|
||||
def execute(self, _context):
|
||||
global _native_copy_token
|
||||
|
||||
_native_copy_token = clipboard_change_token()
|
||||
return {"PASS_THROUGH"}
|
||||
|
||||
|
||||
class PasteClipboardImage(bpy.types.Operator):
|
||||
bl_idname = "anyimage.paste_clipboard_image"
|
||||
bl_label = "Paste Clipboard Image"
|
||||
bl_description = "Paste and pack the clipboard image for the current editor"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
import_as: bpy.props.EnumProperty(
|
||||
name="Import As",
|
||||
description="Choose the 3D View representation for the image",
|
||||
items=(
|
||||
(
|
||||
"PLANE",
|
||||
"Plane",
|
||||
"Create a mesh plane with an image material",
|
||||
),
|
||||
(
|
||||
"REFERENCE",
|
||||
"Reference Image",
|
||||
"Create an image Empty like dragging an image into Blender",
|
||||
),
|
||||
),
|
||||
default="REFERENCE",
|
||||
)
|
||||
shadeless: bpy.props.BoolProperty(
|
||||
name="Shadeless",
|
||||
description=(
|
||||
"Use an Emission shader so the image is unaffected by scene lighting"
|
||||
),
|
||||
default=False,
|
||||
)
|
||||
paste_target: bpy.props.StringProperty(
|
||||
options={"HIDDEN", "SKIP_SAVE"},
|
||||
)
|
||||
location: bpy.props.FloatVectorProperty(
|
||||
size=3,
|
||||
options={"HIDDEN", "SKIP_SAVE"},
|
||||
)
|
||||
location_set: bpy.props.BoolProperty(
|
||||
default=False,
|
||||
options={"HIDDEN", "SKIP_SAVE"},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
if not clipboard_image_supported():
|
||||
return False
|
||||
return target_for_context(context) is not None
|
||||
|
||||
def execute(self, context):
|
||||
return self._paste(context)
|
||||
|
||||
def invoke(self, context, event):
|
||||
self.paste_target = target_for_context(context) or ""
|
||||
location = paste_location(context, event)
|
||||
if location is not None:
|
||||
values = tuple(location)
|
||||
self.location = (*values, 0.0)[:3]
|
||||
self.location_set = True
|
||||
return self._paste(context, event)
|
||||
|
||||
def draw(self, _context):
|
||||
if self.paste_target != "PLANE":
|
||||
return
|
||||
self.layout.prop(self, "import_as")
|
||||
if self.import_as == "PLANE":
|
||||
self.layout.prop(self, "shadeless")
|
||||
|
||||
def _paste(self, context, event=None):
|
||||
if _should_defer_to_native_paste():
|
||||
return {"PASS_THROUGH"}
|
||||
|
||||
if not self.paste_target:
|
||||
self.paste_target = target_for_context(context) or ""
|
||||
|
||||
try:
|
||||
image_data, suffix = read_clipboard_image()
|
||||
except ClipboardImageUnavailable:
|
||||
return {"PASS_THROUGH"}
|
||||
except ClipboardImageError as error:
|
||||
self.report({"ERROR"}, str(error))
|
||||
return {"CANCELLED"}
|
||||
|
||||
image = None
|
||||
image_reused = False
|
||||
try:
|
||||
image, image_reused = acquire_packed_image(image_data, suffix)
|
||||
location = None
|
||||
if self.location_set:
|
||||
location = self.location
|
||||
if self.paste_target == "NODE":
|
||||
location = location[:2]
|
||||
paste_image(
|
||||
context,
|
||||
image,
|
||||
event,
|
||||
location=location,
|
||||
import_as=self.import_as,
|
||||
shadeless=self.shadeless,
|
||||
)
|
||||
except (OSError, RuntimeError, PasteTargetError) as error:
|
||||
if image is not None and not image_reused and image.users == 0:
|
||||
bpy.data.images.remove(image)
|
||||
self.report({"ERROR"}, f"Unable to paste clipboard image: {error}")
|
||||
return {"CANCELLED"}
|
||||
|
||||
self.report({"INFO"}, f"Pasted and packed {image.name}")
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
CLASSES = (TrackNativeCopy, PasteClipboardImage)
|
||||
|
||||
|
||||
def register_keymaps():
|
||||
_register_keymaps()
|
||||
|
||||
|
||||
def unregister_keymaps():
|
||||
global _native_copy_token
|
||||
_unregister_keymaps()
|
||||
_native_copy_token = None
|
||||
|
||||
|
||||
def _should_defer_to_native_paste():
|
||||
if _native_copy_token is None:
|
||||
return False
|
||||
return clipboard_change_token() == _native_copy_token
|
||||
|
||||
|
||||
def _register_keymaps():
|
||||
if not clipboard_image_supported():
|
||||
return
|
||||
|
||||
window_manager = getattr(bpy.context, "window_manager", None)
|
||||
keyconfigs = getattr(window_manager, "keyconfigs", None)
|
||||
addon_keyconfig = getattr(keyconfigs, "addon", None)
|
||||
if addon_keyconfig is None:
|
||||
return
|
||||
|
||||
keymap_definitions = (
|
||||
("3D View", "VIEW_3D"),
|
||||
("Node Editor", "NODE_EDITOR"),
|
||||
)
|
||||
for keymap_name, space_type in keymap_definitions:
|
||||
keymap = addon_keyconfig.keymaps.new(
|
||||
name=keymap_name,
|
||||
space_type=space_type,
|
||||
)
|
||||
modifiers = (
|
||||
{"oskey": True}
|
||||
if sys.platform == "darwin"
|
||||
else {"ctrl": True}
|
||||
)
|
||||
keymap_item = keymap.keymap_items.new(
|
||||
PasteClipboardImage.bl_idname,
|
||||
"V",
|
||||
"PRESS",
|
||||
**modifiers,
|
||||
)
|
||||
_keymap_items.append((keymap, keymap_item))
|
||||
copy_keymap_item = keymap.keymap_items.new(
|
||||
TrackNativeCopy.bl_idname,
|
||||
"C",
|
||||
"PRESS",
|
||||
**modifiers,
|
||||
)
|
||||
_keymap_items.append((keymap, copy_keymap_item))
|
||||
|
||||
|
||||
def _unregister_keymaps():
|
||||
for keymap, keymap_item in _keymap_items:
|
||||
keymap.keymap_items.remove(keymap_item)
|
||||
_keymap_items.clear()
|
||||
__all__ = (
|
||||
"CLASSES",
|
||||
"PasteClipboardImage",
|
||||
"TrackNativeCopy",
|
||||
"register_keymaps",
|
||||
"unregister_keymaps",
|
||||
)
|
||||
|
||||
201
src/anyimage/operators/clipboard_image/operators.py
Normal file
201
src/anyimage/operators/clipboard_image/operators.py
Normal file
@@ -0,0 +1,201 @@
|
||||
import sys
|
||||
|
||||
import bpy
|
||||
|
||||
from .actions import (
|
||||
PasteTargetError,
|
||||
acquire_packed_image,
|
||||
paste_image,
|
||||
paste_location,
|
||||
target_for_context,
|
||||
)
|
||||
from .clipboard import (
|
||||
ClipboardImageError,
|
||||
ClipboardImageUnavailable,
|
||||
clipboard_change_token,
|
||||
clipboard_image_supported,
|
||||
read_clipboard_image,
|
||||
)
|
||||
|
||||
|
||||
_keymap_items = []
|
||||
_native_copy_token = None
|
||||
|
||||
|
||||
class TrackNativeCopy(bpy.types.Operator):
|
||||
bl_idname = "anyimage.track_native_copy"
|
||||
bl_label = "Track Native Copy"
|
||||
bl_description = "Preserve Blender's native copy and paste priority"
|
||||
bl_options = {"INTERNAL"}
|
||||
|
||||
def execute(self, _context):
|
||||
global _native_copy_token
|
||||
|
||||
_native_copy_token = clipboard_change_token()
|
||||
return {"PASS_THROUGH"}
|
||||
|
||||
|
||||
class PasteClipboardImage(bpy.types.Operator):
|
||||
bl_idname = "anyimage.paste_clipboard_image"
|
||||
bl_label = "Paste Clipboard Image"
|
||||
bl_description = "Paste and pack the clipboard image for the current editor"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
import_as: bpy.props.EnumProperty(
|
||||
name="Import As",
|
||||
description="Choose the 3D View representation for the image",
|
||||
items=(
|
||||
(
|
||||
"PLANE",
|
||||
"Plane",
|
||||
"Create a mesh plane with an image material",
|
||||
),
|
||||
(
|
||||
"REFERENCE",
|
||||
"Reference Image",
|
||||
"Create an image Empty like dragging an image into Blender",
|
||||
),
|
||||
),
|
||||
default="REFERENCE",
|
||||
)
|
||||
shadeless: bpy.props.BoolProperty(
|
||||
name="Shadeless",
|
||||
description=(
|
||||
"Use an Emission shader so the image is unaffected by scene lighting"
|
||||
),
|
||||
default=False,
|
||||
)
|
||||
paste_target: bpy.props.StringProperty(
|
||||
options={"HIDDEN", "SKIP_SAVE"},
|
||||
)
|
||||
location: bpy.props.FloatVectorProperty(
|
||||
size=3,
|
||||
options={"HIDDEN", "SKIP_SAVE"},
|
||||
)
|
||||
location_set: bpy.props.BoolProperty(
|
||||
default=False,
|
||||
options={"HIDDEN", "SKIP_SAVE"},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
if not clipboard_image_supported():
|
||||
return False
|
||||
return target_for_context(context) is not None
|
||||
|
||||
def execute(self, context):
|
||||
return self._paste(context)
|
||||
|
||||
def invoke(self, context, event):
|
||||
self.paste_target = target_for_context(context) or ""
|
||||
location = paste_location(context, event)
|
||||
if location is not None:
|
||||
values = tuple(location)
|
||||
self.location = (*values, 0.0)[:3]
|
||||
self.location_set = True
|
||||
return self._paste(context, event)
|
||||
|
||||
def draw(self, _context):
|
||||
if self.paste_target != "PLANE":
|
||||
return
|
||||
self.layout.prop(self, "import_as")
|
||||
if self.import_as == "PLANE":
|
||||
self.layout.prop(self, "shadeless")
|
||||
|
||||
def _paste(self, context, event=None):
|
||||
if _should_defer_to_native_paste():
|
||||
return {"PASS_THROUGH"}
|
||||
|
||||
if not self.paste_target:
|
||||
self.paste_target = target_for_context(context) or ""
|
||||
|
||||
try:
|
||||
image_data, suffix = read_clipboard_image()
|
||||
except ClipboardImageUnavailable:
|
||||
return {"PASS_THROUGH"}
|
||||
except ClipboardImageError as error:
|
||||
self.report({"ERROR"}, str(error))
|
||||
return {"CANCELLED"}
|
||||
|
||||
image = None
|
||||
image_reused = False
|
||||
try:
|
||||
image, image_reused = acquire_packed_image(image_data, suffix)
|
||||
location = None
|
||||
if self.location_set:
|
||||
location = self.location
|
||||
if self.paste_target == "NODE":
|
||||
location = location[:2]
|
||||
paste_image(
|
||||
context,
|
||||
image,
|
||||
event,
|
||||
location=location,
|
||||
import_as=self.import_as,
|
||||
shadeless=self.shadeless,
|
||||
)
|
||||
except (OSError, RuntimeError, PasteTargetError) as error:
|
||||
if image is not None and not image_reused and image.users == 0:
|
||||
bpy.data.images.remove(image)
|
||||
self.report({"ERROR"}, f"Unable to paste clipboard image: {error}")
|
||||
return {"CANCELLED"}
|
||||
|
||||
self.report({"INFO"}, f"Pasted and packed {image.name}")
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
CLASSES = (TrackNativeCopy, PasteClipboardImage)
|
||||
|
||||
|
||||
def unregister_keymaps():
|
||||
global _native_copy_token
|
||||
for keymap, keymap_item in _keymap_items:
|
||||
keymap.keymap_items.remove(keymap_item)
|
||||
_keymap_items.clear()
|
||||
_native_copy_token = None
|
||||
|
||||
|
||||
def _should_defer_to_native_paste():
|
||||
if _native_copy_token is None:
|
||||
return False
|
||||
return clipboard_change_token() == _native_copy_token
|
||||
|
||||
|
||||
def register_keymaps():
|
||||
if not clipboard_image_supported():
|
||||
return
|
||||
|
||||
window_manager = getattr(bpy.context, "window_manager", None)
|
||||
keyconfigs = getattr(window_manager, "keyconfigs", None)
|
||||
addon_keyconfig = getattr(keyconfigs, "addon", None)
|
||||
if addon_keyconfig is None:
|
||||
return
|
||||
|
||||
keymap_definitions = (
|
||||
("3D View", "VIEW_3D"),
|
||||
("Node Editor", "NODE_EDITOR"),
|
||||
)
|
||||
for keymap_name, space_type in keymap_definitions:
|
||||
keymap = addon_keyconfig.keymaps.new(
|
||||
name=keymap_name,
|
||||
space_type=space_type,
|
||||
)
|
||||
modifiers = (
|
||||
{"oskey": True}
|
||||
if sys.platform == "darwin"
|
||||
else {"ctrl": True}
|
||||
)
|
||||
keymap_item = keymap.keymap_items.new(
|
||||
PasteClipboardImage.bl_idname,
|
||||
"V",
|
||||
"PRESS",
|
||||
**modifiers,
|
||||
)
|
||||
_keymap_items.append((keymap, keymap_item))
|
||||
copy_keymap_item = keymap.keymap_items.new(
|
||||
TrackNativeCopy.bl_idname,
|
||||
"C",
|
||||
"PRESS",
|
||||
**modifiers,
|
||||
)
|
||||
_keymap_items.append((keymap, copy_keymap_item))
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Rectangular Plane and Depth Plane conversion operators."""
|
||||
|
||||
from .conversion import (
|
||||
from .operators import (
|
||||
ConvertToDepthPlane,
|
||||
ConvertToPlane,
|
||||
GenerateDepthPlane,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from .main import CutoutSelectionToShape, CutoutTool, SelectCutoutSelection
|
||||
from .operators import CutoutSelectionToShape, CutoutTool, SelectCutoutSelection
|
||||
|
||||
__all__ = (
|
||||
"CutoutSelectionToShape",
|
||||
|
||||
@@ -874,9 +874,6 @@ def teddy_balloon_heights(
|
||||
)
|
||||
|
||||
|
||||
DEFAULT_ALGORITHM = "POISSON"
|
||||
|
||||
|
||||
def cotangent_poisson_field(
|
||||
planar_points,
|
||||
planar_faces,
|
||||
|
||||
@@ -2,7 +2,7 @@ import math
|
||||
|
||||
import bpy
|
||||
|
||||
from ...common.image import (
|
||||
from ..common.image import (
|
||||
MAX_PROJECTIVE_OUTPUT_PIXELS,
|
||||
PROJECTIVE_CHUNK_ROWS,
|
||||
create_image_edit_result,
|
||||
@@ -16,8 +16,8 @@ from ...common.image import (
|
||||
transform_homography,
|
||||
video_total_frames,
|
||||
)
|
||||
from ...preferences import configured_max_frame_resolution
|
||||
from ...common.viewport import (
|
||||
from ..preferences import configured_max_frame_resolution
|
||||
from ..common.viewport import (
|
||||
active_image_edit_source,
|
||||
active_view3d_tool_id,
|
||||
draw_dashed_line,
|
||||
@@ -28,7 +28,7 @@ from ...common.viewport import (
|
||||
rectangle_screen_path,
|
||||
report_image_edit_exception,
|
||||
)
|
||||
from ...common.selection import ImageEditWarning, clip_polygon_halfplanes
|
||||
from ..common.selection import ImageEditWarning, clip_polygon_halfplanes
|
||||
|
||||
FRAME_TOOL_ID = "anyimage.frame"
|
||||
PROJECTIVE_RELATIVE_EPSILON = 1e-12
|
||||
@@ -646,17 +646,3 @@ class FrameTool(bpy.types.WorkSpaceTool):
|
||||
bl_icon = "ops.sculpt.border_mask"
|
||||
bl_operator = FrameImages.bl_idname
|
||||
bl_keymap = image_edit_drag_keymap(FrameImages.bl_idname)
|
||||
|
||||
|
||||
class ActivateImageEditTool(bpy.types.Operator):
|
||||
bl_idname = "anyimage.activate_image_edit_tool"
|
||||
bl_label = "Image Edit"
|
||||
bl_description = "Activate Frame in the 3D Viewport"
|
||||
bl_options = {"INTERNAL"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return image_edit_poll(context)
|
||||
|
||||
def execute(self, _context):
|
||||
return bpy.ops.wm.tool_set_by_id(name=FRAME_TOOL_ID, space_type="VIEW_3D")
|
||||
@@ -1,18 +0,0 @@
|
||||
from .frame import ActivateImageEditTool, FrameImages, FrameTool
|
||||
from .mask import EditImageAlpha, MaskTool
|
||||
from .rectify import RectifyImagePerspective, RectifyTool
|
||||
|
||||
|
||||
CLASSES = (
|
||||
FrameImages,
|
||||
EditImageAlpha,
|
||||
ActivateImageEditTool,
|
||||
RectifyImagePerspective,
|
||||
)
|
||||
|
||||
__all__ = (
|
||||
"CLASSES",
|
||||
"FrameTool",
|
||||
"MaskTool",
|
||||
"RectifyTool",
|
||||
)
|
||||
@@ -1,25 +1,25 @@
|
||||
import bpy
|
||||
|
||||
from ...common.image import (
|
||||
from ..common.image import (
|
||||
create_image_edit_result,
|
||||
image_empty_bounds,
|
||||
image_rgba,
|
||||
replace_empty_image,
|
||||
require_image_empty,
|
||||
)
|
||||
from ...common.selection import (
|
||||
from ..common.selection import (
|
||||
rasterize_selection_path,
|
||||
rasterize_selection_union,
|
||||
SelectionPath,
|
||||
)
|
||||
from ...common.viewport import (
|
||||
from ..common.viewport import (
|
||||
brush_footprint_polygons,
|
||||
ImageGesture,
|
||||
image_edit_point_keymap,
|
||||
report_image_edit_exception,
|
||||
screen_path_to_image_pixels,
|
||||
)
|
||||
from ...properties import (
|
||||
from ..properties import (
|
||||
mask_gesture_property,
|
||||
mask_mode_property,
|
||||
mask_radius_property,
|
||||
@@ -3,7 +3,7 @@ import math
|
||||
|
||||
import bpy
|
||||
|
||||
from ...common.viewport import (
|
||||
from ..common.viewport import (
|
||||
active_view3d_tool_id,
|
||||
deserialize_matrix,
|
||||
draw_dashed_line,
|
||||
@@ -16,8 +16,8 @@ from ...common.viewport import (
|
||||
screen_path_to_image_pixels,
|
||||
serialize_matrix,
|
||||
)
|
||||
from ...common.selection import clip_polygon_halfplanes, trim_pixels_to_alpha
|
||||
from ...common.image import (
|
||||
from ..common.selection import clip_polygon_halfplanes, trim_pixels_to_alpha
|
||||
from ..common.image import (
|
||||
create_image_edit_result,
|
||||
image_base_name,
|
||||
image_pixels,
|
||||
Reference in New Issue
Block a user