#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: ManipulatorContext.py
 @DateTime: 2025/4/8 20:42
 @SoftWare: PyCharm
 @Author  ：xsh
"""
import sys
from PyQt5                              import Qt
from AppInterfaces.ModelInterface       import ContextModelInterface
from AppCore.Levels                     import *
from AppUtils.utils                     import *
from AppCore.Requests                   import *


class MicroscopeContext(ContextModelInterface):
    API                 : str               # 蔡司显微镜接口文件
    MTBAPIPath          : str               # 蔡司显微镜接口文件路径
    ConfigPath          : str               # 蔡司显微镜配置文件路径
    MicroscopeType      : str               # 蔡司显微镜型号
    MicroscopeVersion   : str               # 蔡司显微镜版本
    MicroscopeID        : str               # 蔡司显微镜ID
    IsSucceed           : bool              # 蔡司显微镜是否加载成功
    __slots__ = (
        'API'               ,
        'MTBAPIPath'        ,
        'ConfigPath'        ,
        'MicroscopeType'    ,
        'MicroscopeVersion' ,
        'MicroscopeID'      ,
        'IsSucceed'         ,
    )
    __types__ = (
        str     ,
        str     ,
        str     ,
        str     ,
        str     ,
        str     ,
        bool    ,
    )

    def __init__(self, **args):
        super(MicroscopeContext, self).__init__()
        self.initialization("蔡司显微镜接口文件")
        self.initParameter(**args)

    def initParameter(self, **args):
        if not isinstance(args, dict) or len(args) <= 0:
            return
        for index, _property in enumerate(self.__slots__):
            setattr(self, _property, AppConvert.ObjectConvert(args.get(_property, getattr(self, _property, None)), self.__types__[index]))

    def initValue(self):
        super(MicroscopeContext, self).initValue()
        self.MTBAPIPath         = 'Resource/DLL/MTB/MTBApi.dll'         #
        self.ConfigPath         = 'Resource/DLL/MTB/AxioImageZ2.mtb'    #
        self.MicroscopeType     = ''                                    #
        self.MicroscopeVersion  = ''                                    #
        self.MicroscopeID       = None                                  #
        self.IsSucceed          = False                                 #
        self.API                = 'Library/ZeissMicroscopeAPI.dll'      #


    @property
    def absoluteFilePath(self) -> str:
        if not self.hasAPI:
            return AppUtils.toSourceFile('Library/ZeissMicroscopeAPI.dll')
        return AppUtils.toSourceFile(self.API)

    @property
    def Type(self) -> str:
        return '' if not self.hasMicroscopeType else self.MicroscopeType


    @property
    def StrID(self) -> str:
        return None if not self.hasMicroscopeID else self.MicroscopeID

    @property
    def Version(self) -> str:
        return '' if not self.hasMicroscopeVersion else self.MicroscopeVersion

    @property
    def isSucceed(self) -> bool:
        return False if not self.hasIsSucceed else self.IsSucceed

    @property
    def hasMTBAPIPath(self) -> bool:
        return hasattr(self, 'MTBAPIPath') and isinstance(self.MTBAPIPath, str)

    @property
    def hasConfigPath(self) -> bool:
        return hasattr(self, 'ConfigPath') and isinstance(self.ConfigPath, str)

    @property
    def hasMicroscopeType    (self) -> bool:
        return hasattr(self, 'MicroscopeType'    ) and isinstance(self.MicroscopeType   , str )

    @property
    def hasMicroscopeVersion (self) -> bool:
        return hasattr(self, 'MicroscopeVersion' ) and isinstance(self.MicroscopeVersion, str )

    @property
    def hasIsSucceed         (self) -> bool:
        return hasattr(self, 'IsSucceed'         ) and isinstance(self.IsSucceed        , bool)

    @property
    def hasMicroscopeID(self) -> bool:
        return hasattr(self, 'MicroscopeID') and isinstance(self.MicroscopeID, str)

    @property
    def hasAPI(self) -> bool:
        return hasattr(self, 'API') and isinstance(self.API, str)
