#ifndef CPROCESS_LEVEL_EX_H
#define CPROCESS_LEVEL_EX_H
#include "cimagecontainer.h"
#include "cmprocess.h"
#include "cprecisetime.h"
#include "camatchncc_h.h"
#include "cprocess_level.h"
/*!
 * \brief The CProcess_Level external class
 * 调平操作
 */
class CProcess_Level_Ex : public CProcess_Level {
public:
    CProcess_Level_Ex(const QString& name, int32_t id);
    virtual ~CProcess_Level_Ex();


    void SetPtManual(int iSideID, int iCamID, int ptstyle, int iLineID, bool bManualSet) override;

public:
    /*!
     * \brief 计算并生成某一面的点
     *
     * \param iSideID 面ID SIDE_A SIDE_B
     * \param baseposX  X基准点
     * \param baseposY  Y基准点
     * \param dStartTopPos    开始die的X位置
     * \param dEndBottomPos   结束die的X位置
     * \return
     */
    virtual int32_t calcuPt(int32_t iSideID,
                    double baseposX, double baseposY,
                    double  dStartTopPos, double  dEndBottomPos) override;
    /*!
     * \brief 生成默认的定位点
     *
     * \param iSideID
     */
    virtual void CalcuPtByCell(int iSideID) override;
    /*!
     * \brief 生成某条线的定位点
     *
     * \param iSideID
     * \param iLineID
     */
    virtual void CalcuPtByLine(int iSideID, int iLineID) override;
    /*!
     * \brief 按基准点生成定位点
     *
     * \param iSideID
     * \param baseposX
     * \param baseposY
     * \param dStartPos
     * \param dEndPos
     */
    virtual void CalcuPtByPos(int iSideID, double baseposX, double baseposY,
                      double  dStartPos, double  dEndPos) override;

    /*!
     * \brief 更新调平点的坐标
     * 
     * \param iSideID
     * \param ptstyle \sa pt_type
     */
    virtual void adjustPt(int iSideID, int ptstyle) override;
    /*!
     * \brief 查找调平点
     * ssssss
     * \param iSideID
     * \param iCamID
     * \param ptstyle \sa pt_type
     * \return 
     */
    virtual double SearchAlignPt(int iSideID, int iCamID, int ptstyle) override;
    /*!
     * \brief 查找基准点
     * 找到后，更新基准点的坐标
     * \param iSideID
     * \param iCamID
     * \param iLineID 0时更新基准点并生成切割线 非0时调用calcuSideVector更新切割线
     */
    virtual void SearchBasePt(int iSideID, int iCamID, int iLineID) override;
    virtual void calcuSideVector(int32_t iSideID, double dOffset, int iLineID, bool manualSet = false) override;

    /*!
     * \brief X方向调整长度，
     *  
     * \param iSideID
     * \param iCamID 
     * \param bIndex true 按步长调整 false 按1/1.3视野调整
     * \return 
     */
    double get_XAdjust_step(int iSideID, int iCamID, bool bIndex);
    /*!
    * \brief Y方向调整长度，
    *
    * \param iSideID
    * \param iCamID
    * \param bIndex true 按步长调整 false 按1/1.2视野调整
    * \return
    */
    double get_YAdjust_step(int iSideID, int iCamID, bool bIndex);

    int get_XAdjust_count(int iSideID, int iCamID);
    int get_YAdjust_count(int iSideID, int iCamID);

    /*!
    * \brief 获取X方向的起点和终点
    *
    * \param iSideID
    * \param Y
    * \param XStart
    * \param XEnd
    * \return
    */
    bool getY(int iSideID, double dBaseY, double& dYStart, double& dYEnd);

    //!按圆生成所有切割道
    virtual void calcuLineCircle(int iSideID) override;
    /*!
     * \brief 生成一条切割道
     *
     * \param Bottom
     * \param dLeft
     * \param dRight
     * \param iSideID 面ID
     * \param bsub      是否是子切割道
     * \param index     线号 0开始
     * \param baseY     Y向基准线
     */
     //TODO:需要处理生成线的算法
    virtual void calculine(CMPointd Bottom, double dLeft, double dRight,
                   int iSideID, BOOL bsub, int index, double baseX) override;

    /*!
     * \brief 计算点1与点2之前的角度
     * 左点和右点
     * 根据X的位置交换左边位置为左点 右边位置为右点
     * \param Pt1
     * \param Pt2
     * \return -90~90度
     */
    virtual double calcuAngle(CMPointd Pt1, CMPointd Pt2) override;
    /**
     * 根据参考坐标，中心坐标，半径，起始坐标，结束坐标，计算正向点和负向点
     * 
     * \param dCoordValue   待计算的逻辑坐标
     * \param dCenterValue  中心点的逻辑坐标
     * \param dCenterBaseOffset 中心点偏移
     * \param dRadius       直径
     * \param dStart
     * \param dEnd
     * \param [out] dPositive
     * \param [out] dNegative
     */
    void calcCoordValue(double dCoordValue, double dCenterValue,double dCenterBaseOffset, double dRadius,
                         double dStart, double dEnd, double& dPositive, double& dNegative);

    double calcWorktableOffset(double dCoordValue, double dRefValue);
};

#endif // CPROCESS_LEVEL_EX_H
