#!D:/IDE/anaconda3/envs python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName：AxisSpeedModel.py\n
 @DateTime: 2025/8/13 9:50\n
 @Author  ：xsh
"""
from PyQt5 import Qt
from datetime import datetime, date
import copy
from AppCore.AppDBModels.CoreModel import (CoreModel, DBManager, dbController)
from sqlalchemy.orm import declarative_base, mapper, sessionmaker, Session
from sqlalchemy.orm import (declarative_base, Mapped, mapped_column, relationship, mapper, sessionmaker)
from sqlalchemy import Table, Engine, create_engine, Column, ForeignKey, and_, or_, insert, delete, update, select, func, ColumnElement,distinct
from sqlalchemy.types import (Text, VARCHAR, REAL, Float, Integer, String, SmallInteger, DateTime, Date, ARRAY,Boolean, JSON)
from sqlalchemy.orm.decl_api import DeclarativeBase, MetaData
from AppUtils.utils import *
from AppCore.Levels import *
class AxisVelocityModel(CoreModel):
    __tablename__ = 't_AxisVelocityModel'
    ID                  : Mapped[int                ] = mapped_column(primary_key=True                  , nullable=False)
    Level               : Mapped[int                ] = mapped_column(default=1                         , nullable=True )
    Information         : Mapped[str                ] = mapped_column(Text, default=''                  , nullable=True )
    Velocity            : Mapped[float              ] = mapped_column(default=30.00                     , nullable=True )
    Acceleration        : Mapped[float              ] = mapped_column(default=100.00                    , nullable=True )
    Deceleration        : Mapped[float              ] = mapped_column(default=100.00                    , nullable=True )

    def __init__(self, **args):
        super(AxisVelocityModel, self).__init__()
        self.initialize()
        self.initParameter(**args)

    @classmethod
    def initModels(cls):
        return [
            cls.instance(ID=1, Level=AxisLevel.AxisX      , Information='载玻台Ｘ轴移动速度', Velocity=  30.0, Acceleration=1000.0, Deceleration=1000.0),
            cls.instance(ID=2, Level=AxisLevel.AxisY      , Information='载玻台Ｙ轴移动速度', Velocity=  30.0, Acceleration=1000.0, Deceleration=1000.0),
            cls.instance(ID=3, Level=AxisLevel.AxisZ      , Information='载玻台Ｚ轴扫描速度', Velocity=  30.0, Acceleration=1000.0, Deceleration=1000.0),
            cls.instance(ID=4, Level=AxisLevel.ScanX      , Information='载玻台Ｘ轴扫描速度', Velocity= 100.0, Acceleration=2000.0, Deceleration=2000.0),
            cls.instance(ID=5, Level=AxisLevel.ScanY      , Information='载玻台Ｙ轴扫描速度', Velocity= 100.0, Acceleration=2000.0, Deceleration=2000.0),
            cls.instance(ID=6, Level=AxisLevel.SlowScanX  , Information='载玻台Ｘ轴扫描速度', Velocity=  50.0, Acceleration=2000.0, Deceleration=2000.0),
            cls.instance(ID=7, Level=AxisLevel.SlowScanY  , Information='载玻台Ｙ轴扫描速度', Velocity=  50.0, Acceleration=2000.0, Deceleration=2000.0),
            cls.instance(ID=8, Level=AxisLevel.DropOilX   , Information='载玻台Ｘ轴抹油速度', Velocity=  30.0, Acceleration=1000.0, Deceleration=1000.0),
            cls.instance(ID=9, Level=AxisLevel.DropOilY   , Information='载玻台Ｙ轴抹油速度', Velocity=  30.0, Acceleration=1000.0, Deceleration=1000.0),
        ]

    __field__ = (
        'ID'            ,
        'Level'         ,
        'Information'   ,
        'Velocity'      ,
        'Acceleration'  ,
        'Deceleration'  ,
    )
    __types__ = (
        int   ,
        int   ,
        str   ,
        float ,
        float ,
        float ,
    )

    @classmethod
    def getConfig(cls, level: int) -> (float, float, float):
        _level: int = level if level in AxisLevel.all() else AxisLevel.AxisX
        item: cls = cls.get(cls.Level == _level)
        if item is None:
            return 30.0, 100.0, 100.0
        return item.Velocity, item.Acceleration, item.Deceleration

    @classmethod
    def AxisSpeeds(cls, level: int) -> (float, float, float):
        _level: int = level if level in AxisLevel.all() else AxisLevel.AxisX
        item: cls = cls.get(cls.Level == _level)
        if item is None:
            return 30.0, 100.0, 100.0
        return item.Velocity, item.Acceleration, item.Deceleration
