diff options
Diffstat (limited to 'uv_magic_uv/legacy/op/align_uv_cursor.py')
-rw-r--r-- | uv_magic_uv/legacy/op/align_uv_cursor.py | 126 |
1 files changed, 11 insertions, 115 deletions
diff --git a/uv_magic_uv/legacy/op/align_uv_cursor.py b/uv_magic_uv/legacy/op/align_uv_cursor.py index ec3e7036..6a08de0b 100644 --- a/uv_magic_uv/legacy/op/align_uv_cursor.py +++ b/uv_magic_uv/legacy/op/align_uv_cursor.py @@ -26,41 +26,22 @@ __date__ = "17 Nov 2018" import bpy from mathutils import Vector from bpy.props import EnumProperty, BoolProperty, FloatVectorProperty -import bmesh from ... import common from ...utils.bl_class_registry import BlClassRegistry from ...utils.property_class_registry import PropertyClassRegistry - - -__all__ = [ - 'Properties', - 'MUV_OT_AlignUVCursor', -] - - -def is_valid_context(context): - # 'IMAGE_EDITOR' and 'VIEW_3D' space is allowed to execute. - # If 'View_3D' space is not allowed, you can't find option in Tool-Shelf - # after the execution - for space in context.area.spaces: - if (space.type == 'IMAGE_EDITOR') or (space.type == 'VIEW_3D'): - break - else: - return False - - return True +from ...impl import align_uv_cursor_impl as impl @PropertyClassRegistry(legacy=True) -class Properties: +class _Properties: idname = "align_uv_cursor" @classmethod def init_props(cls, scene): def auvc_get_cursor_loc(self): - area, _, space = common.get_space('IMAGE_EDITOR', 'WINDOW', - 'IMAGE_EDITOR') + area, _, space = common.get_space_legacy('IMAGE_EDITOR', 'WINDOW', + 'IMAGE_EDITOR') bd_size = common.get_uvimg_editor_board_size(area) loc = space.cursor_location if bd_size[0] < 0.000001: @@ -76,8 +57,8 @@ class Properties: def auvc_set_cursor_loc(self, value): self['muv_align_uv_cursor_cursor_loc'] = value - area, _, space = common.get_space('IMAGE_EDITOR', 'WINDOW', - 'IMAGE_EDITOR') + area, _, space = common.get_space_legacy('IMAGE_EDITOR', 'WINDOW', + 'IMAGE_EDITOR') bd_size = common.get_uvimg_editor_board_size(area) cx = bd_size[0] * value[0] cy = bd_size[1] * value[1] @@ -161,97 +142,12 @@ class MUV_OT_AlignUVCursor(bpy.types.Operator): default='TEXTURE' ) + def __init__(self): + self.__impl = impl.AlignUVCursorLegacyImpl() + @classmethod def poll(cls, context): - # we can not get area/space/region from console - if common.is_console_mode(): - return True - return is_valid_context(context) + return impl.AlignUVCursorLegacyImpl.poll(context) def execute(self, context): - area, _, space = common.get_space('IMAGE_EDITOR', 'WINDOW', - 'IMAGE_EDITOR') - bd_size = common.get_uvimg_editor_board_size(area) - - if self.base == 'UV': - obj = context.active_object - bm = bmesh.from_edit_mesh(obj.data) - if not bm.loops.layers.uv: - return None - uv_layer = bm.loops.layers.uv.verify() - - max_ = Vector((-10000000.0, -10000000.0)) - min_ = Vector((10000000.0, 10000000.0)) - for f in bm.faces: - if not f.select: - continue - for l in f.loops: - uv = l[uv_layer].uv - max_.x = max(max_.x, uv.x) - max_.y = max(max_.y, uv.y) - min_.x = min(min_.x, uv.x) - min_.y = min(min_.y, uv.y) - center = Vector(((max_.x + min_.x) / 2.0, (max_.y + min_.y) / 2.0)) - - elif self.base == 'UV_SEL': - obj = context.active_object - bm = bmesh.from_edit_mesh(obj.data) - if not bm.loops.layers.uv: - return None - uv_layer = bm.loops.layers.uv.verify() - - max_ = Vector((-10000000.0, -10000000.0)) - min_ = Vector((10000000.0, 10000000.0)) - for f in bm.faces: - if not f.select: - continue - for l in f.loops: - if not l[uv_layer].select: - continue - uv = l[uv_layer].uv - max_.x = max(max_.x, uv.x) - max_.y = max(max_.y, uv.y) - min_.x = min(min_.x, uv.x) - min_.y = min(min_.y, uv.y) - center = Vector(((max_.x + min_.x) / 2.0, (max_.y + min_.y) / 2.0)) - - elif self.base == 'TEXTURE': - min_ = Vector((0.0, 0.0)) - max_ = Vector((1.0, 1.0)) - center = Vector((0.5, 0.5)) - else: - self.report({'ERROR'}, "Unknown Operation") - - if self.position == 'CENTER': - cx = center.x * bd_size[0] - cy = center.y * bd_size[1] - elif self.position == 'LEFT_TOP': - cx = min_.x * bd_size[0] - cy = max_.y * bd_size[1] - elif self.position == 'LEFT_MIDDLE': - cx = min_.x * bd_size[0] - cy = center.y * bd_size[1] - elif self.position == 'LEFT_BOTTOM': - cx = min_.x * bd_size[0] - cy = min_.y * bd_size[1] - elif self.position == 'MIDDLE_TOP': - cx = center.x * bd_size[0] - cy = max_.y * bd_size[1] - elif self.position == 'MIDDLE_BOTTOM': - cx = center.x * bd_size[0] - cy = min_.y * bd_size[1] - elif self.position == 'RIGHT_TOP': - cx = max_.x * bd_size[0] - cy = max_.y * bd_size[1] - elif self.position == 'RIGHT_MIDDLE': - cx = max_.x * bd_size[0] - cy = center.y * bd_size[1] - elif self.position == 'RIGHT_BOTTOM': - cx = max_.x * bd_size[0] - cy = min_.y * bd_size[1] - else: - self.report({'ERROR'}, "Unknown Operation") - - space.cursor_location = Vector((cx, cy)) - - return {'FINISHED'} + return self.__impl.execute(self, context) |