#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ZEISSLevel.py
@Description：
@Author：XSH
@Time：2025/11/7 15:25
@Department：研发部
@Copyright：©2025 乐辰生物
"""
# MTBAxisUnit: str = 'µm'
MTBAxisUnit : str = 'nm'
MTBUnit     : str = '%'
MTBSpeedUnit: str = 'µm/s'
MTBLightUnit: str = 'Volt'
import clr
import sys
from System import Enum
class MTBCalibrationModes(int):
    NotCalibrated     =  0
    OnLowerLimit      =  1
    OnUpperLimit      =  2
    OnCurrentPosition =  4
    OnFullRange       =  8
    @classmethod
    def all(cls) -> list[int]:
        return [
            cls.NotCalibrated     ,
            cls.OnLowerLimit      ,
            cls.OnUpperLimit      ,
            cls.OnCurrentPosition ,
            cls.OnFullRange       ,
        ]






    @classmethod
    def items(cls) -> dict:
        return {
            cls.NotCalibrated     : 'NotCalibrated'    ,
            cls.OnLowerLimit      : 'OnLowerLimit'     ,
            cls.OnUpperLimit      : 'OnUpperLimit'     ,
            cls.OnCurrentPosition : 'OnCurrentPosition',
            cls.OnFullRange       : 'OnFullRange'      ,
        }

    @classmethod
    def toObject(cls, value: int):
        try:
            from ZEISS import MTB
            cs_enum_type = MTB.Api.MTBCalibrationModes
            cs_member_name: str = cls.items().get(value)
            if isinstance(cs_member_name, str):
                if hasattr(cs_enum_type, cs_member_name):
                    return getattr(cs_enum_type, cs_member_name)
                else:
                    # 若名称不匹配，尝试通过数值匹配
                    cs_member = Enum.ToObject(cs_enum_type, py_enum_member.value)
                    return cs_member

        except Exception as e:
            return None

class MTBCmdSetModes(int):
    Default                            =  0
    Synchronous                        =  1
    Relative                           =  2
    UnidirectionalBacklash             =  4
    BidirectionalBacklashSmart         =  8
    BidirectionalBacklash              =  16
    Smooth                             =  32
    VariableProfile                    =  64
    Fast                               =  128

    @classmethod
    def all(cls) -> list:
        return [
            cls.Default                    ,
            cls.Synchronous                ,
            cls.Relative                   ,
            cls.UnidirectionalBacklash     ,
            cls.BidirectionalBacklashSmart ,
            cls.BidirectionalBacklash      ,
            cls.Smooth                     ,
            cls.VariableProfile            ,
            cls.Fast                       ,
        ]
    @classmethod
    def items(cls) -> dict:
        return {
            cls.Default                    : 'Default'                     ,
            cls.Synchronous                : 'Synchronous'                 ,
            cls.Relative                   : 'Relative'                    ,
            cls.UnidirectionalBacklash     : 'UnidirectionalBacklash'      ,
            cls.BidirectionalBacklashSmart : 'BidirectionalBacklashSmart'  ,
            cls.BidirectionalBacklash      : 'BidirectionalBacklash'       ,
            cls.Smooth                     : 'Smooth'                      ,
            cls.VariableProfile            : 'VariableProfile'             ,
            cls.Fast                       : 'Fast'                        ,
        }

    @classmethod
    def toObject(cls, value: int):
        try:
            from ZEISS import MTB
            cs_enum_type = MTB.Api.MTBCmdSetModes
            cs_member_name: str = cls.items().get(value)
            if isinstance(cs_member_name, str):
                if hasattr(cs_enum_type, cs_member_name):
                    return getattr(cs_enum_type, cs_member_name)
                else:
                    # 若名称不匹配，尝试通过数值匹配
                    cs_member = Enum.ToObject(cs_enum_type, py_enum_member.value)
                    return cs_member

        except Exception as e:
            return None

class MTBLevel(int):
    MTBCondenserProperties          = 0                             # 聚光镜属性管理接口
    MTBEyePiece                     = 1                             # 目镜相关接口
    MTBFocus                        = 2                             # 对焦控制接口
    MTBMicroscopeManager            = 3                             # 显微镜系统管理核心类
    MTBObject                       = 4                             # 基础对象类
    MTBObjectiveChanger             = 5                             # 物镜转换器接口
    MTBRLTLSwitch                   = 6                             # 反射 / 透射光路切换接口
    MTBTLFieldStop                  = 7                             # 透射光视场光阑接口
    MTBTLFilterChanger1             = 8                             # 透射光滤轮 1 接口
    MTBTLFilterChanger2             = 9                             # 透射光滤轮 2 接口
    MTBTLHalogenLamp                = 10                            # 透射光卤素灯控制接口，专门用于控制透射光路的卤素灯，支持开关灯、调节亮度（0-100%）、查询灯泡寿命状态，是透射光卤素光源的核心控制模块
    MTBTLVirtualFilterChanger       = 11                            # 透射光虚拟滤轮接口，用于软件层面模拟滤轮切换（如通过算法补偿替代物理滤镜），或与实际滤轮联动实现复合光效调节，提升光路控制的灵活性












    @classmethod
    def all(cls) -> list[int]:
        return [
            cls.MTBCondenserProperties   ,
            cls.MTBEyePiece              ,
            cls.MTBFocus                 ,
            cls.MTBMicroscopeManager     ,
            cls.MTBObject                ,
            cls.MTBObjectiveChanger      ,
            cls.MTBRLTLSwitch            ,
            cls.MTBTLFieldStop           ,
            cls.MTBTLFilterChanger1      ,
            cls.MTBTLFilterChanger2      ,
            cls.MTBTLHalogenLamp         ,
            cls.MTBTLVirtualFilterChanger,
        ]













    @classmethod
    def items(cls) -> dict[int, str]:
        return {
            cls.MTBCondenserProperties   : 'MTBCondenserProperties'     ,
            cls.MTBEyePiece              : 'MTBEyePiece'                ,
            cls.MTBFocus                 : 'MTBFocus'                   ,
            cls.MTBMicroscopeManager     : 'MTBMicroscopeManager'       ,
            cls.MTBObject                : 'MTBObject'                  ,
            cls.MTBObjectiveChanger      : 'MTBObjectiveChanger'        ,
            cls.MTBRLTLSwitch            : 'MTBRLTLSwitch'              ,
            cls.MTBTLFieldStop           : 'MTBTLFieldStop'             ,
            cls.MTBTLFilterChanger1      : 'MTBTLFilterChanger1'        ,
            cls.MTBTLFilterChanger2      : 'MTBTLFilterChanger2'        ,
            cls.MTBTLHalogenLamp         : 'MTBTLHalogenLamp'           ,
            cls.MTBTLVirtualFilterChanger: 'MTBTLVirtualFilterChanger'  ,
        }

    @classmethod
    def handles(cls) -> dict[str, int]:
        return {
            'MTBCondenserProperties'    : cls.MTBCondenserProperties    ,
            'MTBEyePiece'               : cls.MTBEyePiece               ,
            'MTBFocus'                  : cls.MTBFocus                  ,
            'MTBMicroscopeManager'      : cls.MTBMicroscopeManager      ,
            'MTBObject'                 : cls.MTBObject                 ,
            'MTBObjectiveChanger'       : cls.MTBObjectiveChanger       ,
            'MTBRLTLSwitch'             : cls.MTBRLTLSwitch             ,
            'MTBTLFieldStop'            : cls.MTBTLFieldStop            ,
            'MTBTLFilterChanger1'       : cls.MTBTLFilterChanger1       ,
            'MTBTLFilterChanger2'       : cls.MTBTLFilterChanger2       ,
            'MTBTLHalogenLamp'          : cls.MTBTLHalogenLamp          ,
            'MTBTLVirtualFilterChanger' : cls.MTBTLVirtualFilterChanger ,
        }
    @classmethod
    def toStrID(cls, level: int) -> str:
        return cls.items().get(level, None)

    @classmethod
    def toIntID(cls, level: str) -> int:
        return cls.handles().get(level, None)


