179 lines
5.9 KiB
Python
179 lines
5.9 KiB
Python
|
#!/usr/bin/env python3
|
|||
|
# -*- coding: utf-8 -*-
|
|||
|
"""
|
|||
|
SUWood - 智能家具设计插件
|
|||
|
Blender插件版本
|
|||
|
"""
|
|||
|
|
|||
|
from typing import Dict, Any, Optional
|
|||
|
import logging
|
|||
|
|
|||
|
bl_info = {
|
|||
|
"name": "SUWood - 智能家具设计",
|
|||
|
"author": "SUWood Team",
|
|||
|
"version": (1, 0, 0),
|
|||
|
"blender": (3, 0, 0),
|
|||
|
"location": "View3D > Sidebar > SUWood",
|
|||
|
"description": "智能家具设计工具集,支持柜体创建、分割、轮廓等功能",
|
|||
|
"warning": "",
|
|||
|
"doc_url": "",
|
|||
|
"category": "3D View",
|
|||
|
}
|
|||
|
|
|||
|
# 配置日志
|
|||
|
logging.basicConfig(level=logging.INFO)
|
|||
|
logger = logging.getLogger(__name__)
|
|||
|
|
|||
|
# 尝试导入Blender模块
|
|||
|
try:
|
|||
|
import bpy
|
|||
|
BLENDER_AVAILABLE = True
|
|||
|
except ImportError:
|
|||
|
BLENDER_AVAILABLE = False
|
|||
|
print("⚠️ Blender模块不可用,运行在存根模式")
|
|||
|
|
|||
|
# 导入SUWood模块
|
|||
|
SUWOOD_AVAILABLE = False
|
|||
|
try:
|
|||
|
# 尝试相对导入
|
|||
|
try:
|
|||
|
from . import suw_core
|
|||
|
from . import suw_menu
|
|||
|
from . import suw_observer
|
|||
|
from . import suw_client
|
|||
|
from . import suw_constants
|
|||
|
from . import suw_load
|
|||
|
from . import suw_unit_point_tool
|
|||
|
from . import suw_unit_face_tool
|
|||
|
from . import suw_unit_cont_tool
|
|||
|
from . import suw_zone_div1_tool
|
|||
|
from . import suw_auto_client
|
|||
|
SUWOOD_AVAILABLE = True
|
|||
|
logger.info("✅ SUWood模块导入成功 (相对导入)")
|
|||
|
except ImportError:
|
|||
|
# 尝试绝对导入
|
|||
|
import suw_core
|
|||
|
import suw_menu
|
|||
|
import suw_observer
|
|||
|
import suw_client
|
|||
|
import suw_constants
|
|||
|
import suw_load
|
|||
|
import suw_unit_point_tool
|
|||
|
import suw_unit_face_tool
|
|||
|
import suw_unit_cont_tool
|
|||
|
import suw_zone_div1_tool
|
|||
|
import suw_auto_client
|
|||
|
SUWOOD_AVAILABLE = True
|
|||
|
logger.info("✅ SUWood模块导入成功 (绝对导入)")
|
|||
|
|
|||
|
except ImportError as e:
|
|||
|
SUWOOD_AVAILABLE = False
|
|||
|
logger.error(f"❌ SUWood模块导入失败: {e}")
|
|||
|
print(f"⚠️ SUWood模块导入失败: {e}")
|
|||
|
|
|||
|
# 创建存根模块以避免错误
|
|||
|
class StubModule:
|
|||
|
def __init__(self, name):
|
|||
|
self.__name__ = name
|
|||
|
|
|||
|
def __getattr__(self, name):
|
|||
|
return lambda *args, **kwargs: None
|
|||
|
|
|||
|
# 创建存根模块
|
|||
|
suw_core = StubModule('suw_core')
|
|||
|
suw_menu = StubModule('suw_menu')
|
|||
|
suw_observer = StubModule('suw_observer')
|
|||
|
suw_client = StubModule('suw_client')
|
|||
|
suw_constants = StubModule('suw_constants')
|
|||
|
suw_load = StubModule('suw_load')
|
|||
|
suw_unit_point_tool = StubModule('suw_unit_point_tool')
|
|||
|
suw_unit_face_tool = StubModule('suw_unit_face_tool')
|
|||
|
suw_unit_cont_tool = StubModule('suw_unit_cont_tool')
|
|||
|
suw_zone_div1_tool = StubModule('suw_zone_div1_tool')
|
|||
|
suw_auto_client = StubModule('suw_auto_client')
|
|||
|
|
|||
|
# 插件注册函数
|
|||
|
|
|||
|
|
|||
|
def register():
|
|||
|
"""注册SUWood插件"""
|
|||
|
try:
|
|||
|
if not BLENDER_AVAILABLE:
|
|||
|
logger.error("❌ Blender环境不可用,无法注册插件")
|
|||
|
return
|
|||
|
|
|||
|
if not SUWOOD_AVAILABLE:
|
|||
|
logger.error("❌ SUWood模块不可用,无法注册插件")
|
|||
|
return
|
|||
|
|
|||
|
# 注册区域分割工具
|
|||
|
if hasattr(suw_zone_div1_tool, 'register_zone_divide_operators'):
|
|||
|
suw_zone_div1_tool.register_zone_divide_operators()
|
|||
|
|
|||
|
# 初始化SUWood系统 (包含菜单系统注册)
|
|||
|
if hasattr(suw_menu, 'SUWMenu') and hasattr(suw_menu.SUWMenu, 'initialize'):
|
|||
|
suw_menu.SUWMenu.initialize()
|
|||
|
|
|||
|
# 注册SUW自动客户端
|
|||
|
if hasattr(suw_auto_client, 'register_suw_auto_client'):
|
|||
|
if suw_auto_client.register_suw_auto_client():
|
|||
|
logger.info("✅ SUW自动客户端注册成功")
|
|||
|
# 启动SUW客户端定时器
|
|||
|
if hasattr(suw_auto_client, 'start_suw_client_timer'):
|
|||
|
suw_auto_client.start_suw_client_timer()
|
|||
|
else:
|
|||
|
logger.warning("⚠️ SUW自动客户端注册失败,但插件仍可正常使用")
|
|||
|
|
|||
|
logger.info("✅ SUWood插件注册成功")
|
|||
|
print("🎉 SUWood插件已成功安装!")
|
|||
|
print("📋 功能包括:")
|
|||
|
print(" • 点击创体工具")
|
|||
|
print(" • 选面创体工具")
|
|||
|
print(" • 删除柜体功能")
|
|||
|
print(" • 六面切割工具")
|
|||
|
print(" • 轮廓创建工具")
|
|||
|
print(" • 智能选择管理")
|
|||
|
print(" • 实时状态显示")
|
|||
|
print(" • SUW自动客户端 (自动接收和发送SUW命令)")
|
|||
|
|
|||
|
except Exception as e:
|
|||
|
logger.error(f"❌ SUWood插件注册失败: {e}")
|
|||
|
print(f"❌ 插件注册失败: {e}")
|
|||
|
|
|||
|
# 插件注销函数
|
|||
|
|
|||
|
|
|||
|
def unregister():
|
|||
|
"""注销SUWood插件"""
|
|||
|
try:
|
|||
|
if not BLENDER_AVAILABLE:
|
|||
|
return
|
|||
|
|
|||
|
# 清理SUWood系统
|
|||
|
if SUWOOD_AVAILABLE:
|
|||
|
# 注销SUW自动客户端
|
|||
|
if hasattr(suw_auto_client, 'unregister_suw_auto_client'):
|
|||
|
suw_auto_client.unregister_suw_auto_client()
|
|||
|
# 停止SUW客户端定时器
|
|||
|
if hasattr(suw_auto_client, 'stop_suw_client_timer'):
|
|||
|
suw_auto_client.stop_suw_client_timer()
|
|||
|
|
|||
|
if hasattr(suw_menu, 'SUWMenu') and hasattr(suw_menu.SUWMenu, 'cleanup'):
|
|||
|
suw_menu.SUWMenu.cleanup()
|
|||
|
|
|||
|
# 注销区域分割工具
|
|||
|
if hasattr(suw_zone_div1_tool, 'unregister_zone_divide_operators'):
|
|||
|
suw_zone_div1_tool.unregister_zone_divide_operators()
|
|||
|
|
|||
|
logger.info("✅ SUWood插件注销成功")
|
|||
|
print("🧹 SUWood插件已卸载")
|
|||
|
|
|||
|
except Exception as e:
|
|||
|
logger.error(f"❌ SUWood插件注销失败: {e}")
|
|||
|
print(f"❌ 插件注销失败: {e}")
|
|||
|
|
|||
|
|
|||
|
# 自动注册(如果直接运行此文件)
|
|||
|
if __name__ == "__main__":
|
|||
|
register()
|