// CaliPages.h : CaliPages DLL 的主头文件
//
#pragma once


#include <sst\ucut.h>
#include <sst\realview.h>
#include <ocv\RobotSpaceMapE1.h>

#include "..\pilelibs\includes\robbase\Camera.h"
#include "..\pilelibs\includes\robbase\Motion.h"
#include "..\pilelibs\includes\robbase\Robot.h"

#ifdef __ENABLE_TABX__
   #include "..\pilelibs\includes\robbase\WorkDesk.h"
   #include "..\pilelibs\includes\robbase\RobMot.h"
   #include "..\pilelibs\includes\robbase\MotOpts.h"
#endif


#define BPG_LANG_CHINESE    0
#define BPG_LANG_ENGLISH    1





//@1相机ID
#define CPS_CAM_MOBILE     0
#define CPS_CAM_LEFT       1
#define CPS_CAM_RIGHT      2
#define CPS_CAM_MOBILE_D   3  //副主轴相机
#define CPS_CAM_LEFT_D     4  //副左托盘相机
#define CPS_CAM_RIGHT_D    5  //副右托盘相机


//相机旋转
#define BPG_ROT90_NONE      0
#define BPG_ROT90_LEFT      1 
#define BPG_ROT90_RIGHT     2 

//
#define BPG_FLIP_NONE      (RV_DIR_UNK)
#define BPG_FLIP_HORI      (RV_DIR_HORI)
#define BPG_FLIP_VERT      (RV_DIR_VERT)
#define BPG_FLIP_BOTH      (RV_DIR_BOTH)




//////////////////////////BEGIN OF CALIBRATION ///////////////////////////
//C相机标定id和主工作台（默认）
#define CT_GLOBAL_LEFT    1        //全局相机1
#define CT_GLOBAL_RIGHT   (1<<1)   //全局相机2
#define CT_MOBILE_LEFT    (1<<2)   //主轴相机(随轴移动)
#define CT_MOBILE_RIGHT   (1<<3)   //主轴相机(随轴移动)

//副工作台（前后工作台的背面）
#define CT_GLOBAL_LEFT_D    (1 << 4)        //副工作台全局相机1
#define CT_GLOBAL_RIGHT_D   (1 << 5)   //副工作台全局相机2
#define CT_MOBILE_LEFT_D    (1 << 6)   //副工作台主轴相机(随轴移动)
#define CT_MOBILE_RIGHT_D   (1 << 7)   //副工作台主轴相机(随轴移动)

//编辑位置flag
#define CT_RIGHT_TRAY       (0xf)
#define CT_BACK_TABLE       (0xf << 4)   //副工作台总


//刷新视场： 校准类型id， 视场, 用户数据
//id 为相机标定 如 CT_GLOBAL_LEFT
typedef void (WINAPI *CT_REFRESH_SIGHT_FUNC)(int, CRealView*, void*);

//保存结果：校准类型id，校准类（CRobotSpaceMapE1），是否为读取, 校准ID(返回), 时间戳，校准位置(如果为写，由用户输入), 用户数据
// id 为相机标定 如 CT_GLOBAL_LEFT
typedef BOOL (WINAPI *CT_SERIALIZE_RESULTS_FUNC)(int, CRobotSpaceMapE1*, BOOL bReadIn, UINT*, time_t*, RvPoint_f64*, void*);

 
//运动模块运动状态发生改变
typedef void (WINAPI *BP_MOTION_CHANGED_FUNC)(HWND hWnd/*CWnd* pWnd*/, CMotion* pMotion, BOOL bMoving, void* pUserData);


typedef struct __ct_params{
	int   id; 
	BOOL  bImageFromSight;   //从视场获取图像
	BOOL  bHideAuxCamViewer; //不使用辅助相机视图
	BOOL  bFixedCameraPos;   //固定的相机工作位置，if true, ignore caliPosZ
	int   rotateType    ;     //被校准相机旋转类型: 不转, 左转90度,右转90度

	BOOL  bEnableRasterPos ;    //使用光栅尺坐标位置
	int   stillTime ;           //等待运动轴完全静止时间

	WORD    axisX, axisY, axisZ; //创建标定页面中使用
	double  caliPosX;  //校准位置x,y
	double  caliPosY; 
	double  caliPosZ; // z轴位置

	BOOL     bFixedAuxCam;    //校准全局相机时用,辅助相机是否固定
	CCamera* pAuxCam;        //主轴相机，校准全局相机时用
	double   auxCamPosZ;     //辅助相机轴工作位,全局相机标定时使用

    CT_REFRESH_SIGHT_FUNC fnRefreshSight; 
	void* pRefreshSightUserData; 
	CT_SERIALIZE_RESULTS_FUNC fnSerializeResults; 
	void* pSerializeResultsUserData; 
	
}CT_PARAMS, CT_MCAM_PAIRS, CT_GCAM_PARAMS, CT_EXTRA;
 

typedef struct __ct2_params{
	int   id; 
	BOOL  bHideAuxCamViewer; //不使用辅助相机视图，局部和全局相机都有效
	BOOL  bFixedCameraPos;   //固定的相机工作位置，if true, ignore caliPosZ
	int   rotateType    ;     //被校准相机旋转类型: 不转, 左转90度,右转90度
	WORD     axisX, axisY, axisZ;          //创建标定页面中使用
	double  caliPosX, caliPosY, caliPosZ; // z轴位置

	//辅助相机,全局相机标定时使用	
	BOOL     bFixedAuxCam;
	CCamera* pAuxCam;           //主轴相机，校准全局相机时用
    WORD     axisAux;           //辅助轴
	double   auxCamPos;         //辅助相机轴工作位,全局相机标定时使用
	 
	CT_SERIALIZE_RESULTS_FUNC fnSerializeResults; 
	void* pSerializeResultsUserData; 
	 
}CT2_PARAMS;


typedef struct __aw2c_params{ 
	BOOL    bShowAuxCamera;
	BOOL    bFixedCameraPos;   //固定的相机工作位置，if true, ignore caliPosZ
	WORD    axisX, axisY, axisZ;          //创建标定页面中使用
	double  caliPosX, caliPosY, caliPosZ; // z轴位置

	//自动标定
	double   sightWidth, sightHeight; //视场大小，单位: mm
	int      sampleCount;             //采用数量
	
	//是否转置x或y方向
	BOOL     bReverseDirX, bReverseDirY;
	int      stillTime ;// 拍照前等待时间

	//CT_SERIALIZE_RESULTS_FUNC fnSerializeResults; 
	//void* pSerializeResultsUserData; 

}AW2C_PARAMS;


//typedef struct __ct3_params{
//	int   id; 
//	BOOL  bHideAuxCamViewer; //不使用辅助相机视图，局部和全局相机都有效
//	BOOL  bFixedCameraPos;   //固定的相机工作位置，if true, ignore caliPosZ
//	int   rotateType    ;     //被校准相机旋转类型: 不转, 左转90度,右转90度
//	int     axisX, axisY, axisZ;          //创建标定页面中使用
//	double  caliPosX, caliPosY, caliPosZ; // z轴位置
//
//	//辅助相机,全局相机标定时使用
//	BOOL     bFixedAuxCam;    //校准全局相机时用,辅助相机是否固定
//	CCamera* pAuxCam;        //主轴相机，校准全局相机时用
//    int      axisAux;        //辅助轴
//	double   auxCamPos;      //辅助相机轴工作位,全局相机标定时使用
//  
//}CT3_PARAMS;


typedef struct __bpg_fov_info_
{
	BOOL   bValid;
	double scaleX, scaleY;
	double width, height;
}BPG_FOV_INFO;
// 
 

////////////////////////////END OF CALIBRATION/////////////////////////////


//////////BEGIN OF TOOL DIST CALI////////////////////////////////////

//主工作台 ID, USER DATA
typedef void (WINAPI *CLD_MOVE_CAMERA_FUNC)(int  , void*);

//主工作台 ID,   启动(TRUE)或停止(FALSE), USER DATA
typedef void (WINAPI *CLD_START_TOOL_FUNC)(int  , BOOL,  void*);

//主工作台 ID, USER DATA
typedef void (WINAPI *CLD_SHOW_CAMERA_WND_FUNC)(int  , void*);

typedef struct __cld_params{
	 BOOL   bEnableMoveCam;    //支持移动相机到拍照位置
	 BOOL   bEnableStartTool;  //启动工具:锣刀或打开胶水等
	 BOOL   bShowCamera;       //支持主轴相机监视窗口
	 WORD   axisX, axisY, axisZ;
	 int    startToolBit;
	 double cameraPosZ;   //相机拍照位置
	 //double toolPosZ;     //
 }CLD_PARAMS;
 
 
extern "C"  void PASCAL EXPORT  bpgSetLanguage(int lang);
extern "C"  int  PASCAL EXPORT  bpgGetLanguage();

//场景ID
extern "C"  int   PASCAL EXPORT  bpgGetHomeSceneId();
extern "C"  int   PASCAL EXPORT  bpgGetMoveSceneId();
//extern "C"  void  PASCAL EXPORT  bpgSetHomeSceneId(int scene);
//extern "C"  void  PASCAL EXPORT  bpgSetMoveSceneId(int scene);



//运动控制窗口
//相关参数文件: platform.ini
#ifdef __ENABLE_TABX__
    extern "C" CWnd* PASCAL EXPORT bpgCreateMoverWnd(/*CWnd* pParent,*/  CUtString strTitle, CRobMot* pRotMot, CWorkDesk* pWorkDesk, CUtString strOptionFile , HWND hNotifyWnd);
    extern "C" void PASCAL EXPORT  bpgDestroyMoverWnd(CWnd* &pMoverWin);
    extern "C" void PASCAL EXPORT  bpgSetMoverInMaintainMode(CWnd* pMoverWin, BOOL flag);
    extern "C" BOOL PASCAL EXPORT  bpgIsMoverInMaintainMode(CWnd* pMoverWin);

   extern "C"  void PASCAL EXPORT  bpgLockMoverUI(CWnd* pMoverWin, BOOL flag);
 
   //显示运动窗口
   extern "C" INT_PTR PASCAL EXPORT bpgShowMoverWnd(CUtString strTitle,   CRobMot* pRotMot, CWorkDesk* pWorkDesk, CUtString strOptionFile , HWND hNotifyWnd);

#endif

//显示相机实时监视窗口
//相机在打开状态,子窗口
extern "C" CWnd* PASCAL EXPORT   bpgCreateLiveCameraWnd(CWnd* pParent, CUtString strTitle, CUtString strName, UINT id,  CCamera* pCamera);
extern "C" const TCHAR*  PASCAL EXPORT bpgGetLiveCameraWndName(CWnd* pLiveCameraWin);
extern "C" UINT  PASCAL EXPORT         bpgGetLiveCameraWndId(CWnd* pLiveCameraWin);
extern "C" CCamera*  PASCAL EXPORT     bpgGetLiveCameraWndDevice(CWnd* pLiveCameraWin);
extern "C" void PASCAL EXPORT  bpgReleaseLiveCameraView(CWnd*  pLiveCameraWin);
extern "C" void PASCAL EXPORT  bpgDestroyLiveCameraWnd(CWnd* &pLiveCameraWin);

//弹出窗口的实时相机窗口
extern "C" CWnd* PASCAL EXPORT bpgCreateLiveCameraWndE2(CWnd* pParent, CCamera* pCamera);
extern "C" void PASCAL EXPORT  bpgReleaseLiveCameraViewE2(CWnd*  pLiveCameraWin);
extern "C" void PASCAL EXPORT  bpgDestroyLiveCameraWndE2(CWnd* &pLiveCameraWin);


//输入输出配置窗口
//bpgShowInputOutputWnd , bpgShowSpecialIoWnd配置文件字段名称
//从1开始计数
//platform.ini, motion.ini
#ifdef __ENABLE_TABX__

extern "C" INT_PTR PASCAL EXPORT bpgShowInputOutputWnd(CUtString strTitle,  CRobMot* pRotMot, CUtString strParamFile);
extern "C" INT_PTR PASCAL EXPORT bpgShowSpecialIoWnd(CUtString strTitle,  CRobMot* pRotMot,  CUtString strParamFile);

//参数文件: platform.ini 
//从1开始计数
//if bSpecific =TRUE: show 专用轴io
extern "C" CWnd* PASCAL EXPORT bpgCreateInputOutputWnd(CWnd* pParent, BOOL bSpecific,  /*CUtString strTitle,*/  CRobMot* pRotMot, CUtString strParamFile);
 

//错误码为运动卡错误码,刷新输出输出状态
extern "C" BOOL PASCAL EXPORT  bpgRefreshInputOutputWnd(BOOL bSpecific, CWnd*  pInputOutputWnd, int* pErrCode);

//重新定义输出输出口，还没有实现
extern "C" void PASCAL EXPORT  bpgRedefineInputOutputWnd(BOOL bSpecific, CWnd*  pInputOutputWnd, CUtString strParamFile);

extern "C" void PASCAL EXPORT  bpgDestroyInputOutputWnd(BOOL bSpecific, CWnd* &pInputOutputWnd);
#endif

typedef struct __gmw_params_
{
	WORD    axisX, axisY, axisZ, axisR;
	BOOL   bReverseX, bReverseY, bReverseZ, bReverseR;
	BOOL   bChildWin;
	void*                  pUserData;
	BP_MOTION_CHANGED_FUNC pMotionChangedFunc;
}GMW_PARAMS;
extern "C" CWnd* PASCAL EXPORT bpgCreateGenericMoverWnd(CWnd* pParent,  CRobot* pRobot, GMW_PARAMS* pParams );
extern "C" void PASCAL EXPORT  bpgDestroyGenericMoverWnd(CWnd* &pMoverWin);

typedef struct __gmw_g3_params_
{
	WORD    axisX, axisY, axisZ ; 
	BOOL   bChildWin;
	void*  pUserData;
	BP_MOTION_CHANGED_FUNC pMotionChangedFunc;
}GMW_G3_PARAMS;
extern "C" CWnd* PASCAL EXPORT bpgCreateGate3MoverWnd(CWnd* pParent,  CRobot* pRobot, GMW_G3_PARAMS* pParams );
extern "C" void  PASCAL EXPORT bpgDestroyGate3MoverWnd(CWnd* &pMoverWin);

extern "C" INT_PTR PASCAL EXPORT bpgShowGate3MoverWnd(CRobot* pRobot, WORD axisX, WORD axisY, WORD axisZ);

//sceneId大于零有效
//extern "C" INT_PTR PASCAL EXPORT bpgShowGate3MoverWndE1(CRobot* pRobot, WORD axisX, WORD axisY, WORD axisZ );

//extern "C" INT_PTR PASCAL EXPORT bpgShowGate3MoverWndE2(CRobot* pRobot, WORD axisX, WORD axisY, WORD axisZ );




//单轴移动窗口，支持任意多轴 
typedef struct __smw_params_
{
	 CWnd* pParent;
	 WORD*  pAxisArray;
	 int   axisCount;
	 BOOL  bChildWin ;
	 void*                  pUserData;
	 BP_MOTION_CHANGED_FUNC pMotionChangedFunc;
}SMW_PARAMS;
extern "C" CWnd* PASCAL EXPORT bpgCreateSingleMoverWnd(CWnd* pParent,  CRobot* pRobot, WORD* pAxisArray, int axisCount, BOOL bChildWin  );

//有回调函数
extern "C" CWnd* PASCAL EXPORT bpgCreateSingleMoverWndE1( CRobot* pRobot, SMW_PARAMS* pParams );
extern "C" void PASCAL EXPORT  bpgDestroySingleMoverWnd(CWnd* &pMoverWin);

extern "C" INT_PTR PASCAL EXPORT bpgShowSingleMoverWnd(CRobot* pRobot, WORD* pAxisArray, int axisCount);





//bpgShowSingleMoverWndE1: 速度场景array
#define MAX_DESC_LEN   63
typedef struct __smw_params_e1_
{ 
	WORD   axis;
	TCHAR desc[MAX_DESC_LEN +1];
	//int   jogId;  //scene id      
	//int   homeId; //scene id       
	//int   editId; //scene id	 
	BOOL  checkRange;
	double lower;
	double upper;
}SMW_PARAMS_E1;
extern "C" INT_PTR PASCAL EXPORT bpgShowSingleMoverWndE1(CRobot* pRobot, SMW_PARAMS_E1* pParmsArray, int axisCount );



//相机配置窗口
//相机在打开状态
//camClsId : CPS_CAM_LEFT
//参数文件: data.ini
//extern "C" INT_PTR PASCAL EXPORT bpgShowCameraParamWnd(CUtString strTitle, CCamera* pCamera, int camClsId,  int rotateType,   CUtString strParamFile  );

//外部程序自己保存成像参数
//Modal方式显示，
//直接返回DoModal值
//extern "C" INT_PTR PASCAL EXPORT bpgShowCameraParamWndE1(CUtString strTitle, CCamera* pCamera,   int rotateType );

#define  SCPW_EXPOSURE    1
#define  SCPW_GAIN        (1<<1)
#define  SCPW_FLIP        (1<<2)
#define  SCPW_BALANCE     (1<<3)
#define  SCPW_BRIGHT      (1<<4)   //黑白
#define  SCPW_CONTRAST    (1<<4)   //彩色
#define  SCPW_DEFAULT     (SCPW_EXPOSURE | SCPW_GAIN | SCPW_FLIP | SCPW_BALANCE)

typedef struct __scpw_params_
{
	 int     filter;
	 int     rotateType;    //BPG_ROT90_NONE
	 int     flipType;
	 RvRange exposure;      //如果lower, upper都等于0表示使用原相机参数范围
	 RvRange gain;          //如果lower, upper都等于0表示使用原相机参数范围
	 RvRange contrast;   //彩色相机, //如果lower, upper都等于0表示使用原相机参数范围
	 RvRange bright;     //灰度相机,//如果lower, upper都等于0表示使用原相机参数范围
}SCPW_PARAMS;
extern "C" INT_PTR PASCAL EXPORT bpgShowCameraParamWndE2(CUtString strTitle, CCamera* pCamera,   SCPW_PARAMS& params  );


//相机编辑位置窗口
//传入的相机在打开状态
#ifdef __ENABLE_TABX__
extern "C" INT_PTR PASCAL EXPORT bpgShowCameraEditPosWnd(int camClsId, int posFlags, CUtString strTitle, CCamera* pCamera,  CRobMot* pRotMot, CWorkDesk* pWorkDesk, CUtString strCamParamFile, CUtString strCamEditposFile);
#endif

extern "C" INT_PTR PASCAL EXPORT bpgShowAboutWnd(CUtString  strLicencePath, CUtString  strCameraModal );
extern "C" CWnd* PASCAL EXPORT   bpgCreateLicenceWnd(CWnd* pParent, CUtString  strLicencePath, CUtString strFrontFile, CUtString strActivateFile, CUtString  strCameraModal );
extern "C" void  PASCAL EXPORT   bpgDestroyLicenceWnd(CWnd* &pLicenceWnd );

 
typedef struct __slm_params{
	WORD          axisX, axisY, axisZ;
	double       shotPos;              //相机拍摄位置,对应Z轴
	RvPoint_f64  mark1pos;
	RvPoint_f64  mark2pos;
	CCaliber*    pLocater1;
	CCaliber*    pLocater2;
	BOOL         disableMark1;
	BOOL         disableMark2;
}SLM_PARAMS;
	
extern "C" INT_PTR PASCAL EXPORT bpgShowLearnMarkWnd(const TCHAR* strTitle, CRobot* pRotMot, CCamera* pCamera,  SLM_PARAMS* params);

extern "C" INT_PTR PASCAL EXPORT bpgShowDefaultAd();


	
extern "C" CWnd* PASCAL EXPORT   bpgCreateCaliMobileW2cWnd(CWnd* pParent, CCamera* pCamera,   CRobot* pRobot ,   CT2_PARAMS* pExtra);
extern "C" void PASCAL EXPORT    bpgSetCaliMobileW2cWndCallback(CWnd* pCaliMobileW2cWnd, CT_SERIALIZE_RESULTS_FUNC fnSerializeResults, void* pUserData);

extern "C" void  PASCAL EXPORT   bpgDestroyCaliMobileW2cWnd(CWnd* &pCaliMobileW2cWnd );
extern "C" void PASCAL EXPORT    bpgReleaseCaliMobileW2cView(CWnd* pCaliMobileW2cWnd );

//对话框形式显示对话框
extern "C" INT_PTR  PASCAL EXPORT   bpgShowCaliMobileW2cWnd(const TCHAR*  strTitle, CCamera* pCamera,   CRobot* pRobot ,   const TCHAR*  strParamFile, CT2_PARAMS extra );
extern "C" BOOL  PASCAL EXPORT   bpgReadMobileW2cParams(const TCHAR*  strParamFile,  CRobotSpaceMapE1* pRsm, UINT* pId,  RvPoint_f64* pCaliPos );
extern "C" BOOL  PASCAL EXPORT   bpgWriteMobileW2cParams(const TCHAR*  strParamFile,  CRobotSpaceMapE1* pRsm, UINT id,  RvPoint_f64 caliPos );


extern "C" INT_PTR  PASCAL EXPORT   bpgShowAutoCaliW2cWnd(const TCHAR*  strTitle, CCamera* pCamera,   CRobot* pRobot, AW2C_PARAMS extra, CRobotSpaceMapE1* pRsm);



//相机编辑位置窗口e1,不保存
//传入的相机在打开状态
#ifdef __ENABLE_TABX__
typedef struct __scew_camera_edit_pos_{
	BOOL    bPlanarAxisOnly;                 //是否仅XY轴
	int     axisX, axisY, axisZ;             //创建标定页面中使用
	double  posX, posY, posZ;                //输入
}SCEW_PARAMS;
extern "C" INT_PTR PASCAL EXPORT bpgShowCameraEditPosWndE1( CUtString strTitle, CCamera* pCamera,  CRobMot* pRotMot, CWorkDesk* pWorkDesk, SCEW_PARAMS* pScewParams, int paramsSize);


 
//创建移动视场标定窗口
//extern "C" CWnd* PASCAL EXPORT bpgCreateCMCWnd(CWnd* pParent, CCamera* pCamera,   CRobMot* pRotMot, CWorkDesk* pWorkDesk,   CT_PARAMS* pExtra  );
//extern "C" void PASCAL EXPORT bpgReleaseCMCView(CWnd* pCalibCamWin );

//extern "C" void PASCAL EXPORT  bpgDestroyCMCWnd(CWnd* &pCalibCamWin);
#endif

//camera guide window
typedef struct __cgw_params
{
	WORD    axisX, axisY;
	BOOL   disableStepMove;  //双击移动
	BOOL   disableJogMove;    //连续移动
	double caliX, caliY;     //标定时机械位置
	CRobotSpaceMapE1* pRobotMap;
}CGW_PARAMS;

#define CTW_STEP_MOVE     (1)
#define CTW_JOG_MOVE      (1<<1)
 #define CTW_REVERSE_JOG_X      (1<<2)
 #define CTW_REVERSE_JOG_Y      (1<<3)
 #define CTW_REVERSE_STEP_X      (1<<4)
 #define CTW_REVERSE_STEP_Y      (1<<5)

//添加CNC对象
typedef void (WINAPI *CTW_ON_CNCOBJ_ADD_FUNC)(int /*type*/, RvPoint_f64* /*pCtrlPosArray*/, int /*ctrlPosCount*/, void* /*pUserData*/);
//更改CNC对象坐标
typedef void (WINAPI *CTW_ON_CNCOBJ_CHANGE_FUNC)(UINT   /*obj id*/, int /*ctrlPosIndex*/, RvPoint_f /*cameraPos*/,  RvPoint_f64 /*curMachPos*/ ,  void* /*pUserData*/);
//删除CNS对象
typedef BOOL (WINAPI *CTW_ON_CNCOBJ_DELETE_FUNC)(UINT   /*obj id*/,  void* /*pUserData*/);

//CNC位置增加时回调
typedef void (WINAPI *CTW_ON_MACH_POS_PICKUP_FUNC)  (int   /*edit mode*/, int /*index*/,   RvPoint_f64 /*machpos*/, void* /*pUserData*/);
//CNC位置撤销时回调
typedef void (WINAPI *CTW_ON_MACH_POS_ROLLBACK_FUNC)(int   /*edit mode*/, int /*index*/,   RvPoint_f64  /*prevPos*/, void* /*pUserData*/);


extern "C" CWnd* PASCAL EXPORT bpgCreateTeachWnd(CWnd* hParent,  CCamera* pCamera, CRobot* pRobot, CGW_PARAMS* pParams );
extern "C" CWnd* PASCAL EXPORT bpgCreateTeachWndE1(CWnd* hParent,  CCamera* pCamera, CRobot* pRobot, WORD  axisX, WORD axisY, int flags = CTW_STEP_MOVE |  CTW_JOG_MOVE );
 
extern "C" void PASCAL EXPORT  bpgSetRobotMapToTeachWnd (CWnd* hTeachWnd, CRobotSpaceMapE1* pRobotMap, double caliX, double caliY);

extern "C" void PASCAL EXPORT  bpgSetCncobjEditionCallbackToTeachWnd (CWnd* hTeachWnd, CTW_ON_CNCOBJ_ADD_FUNC fnAddFunc, CTW_ON_CNCOBJ_CHANGE_FUNC fnChangeFunc, CTW_ON_CNCOBJ_DELETE_FUNC fnDelete, void* pUserData);


extern "C" BOOL PASCAL EXPORT  bpgIsTeachPageStarted (CWnd* hTeachWnd );  //obsolete

extern "C" void PASCAL EXPORT  bpgInvertDirectionOfTeachWnd (CWnd* hTeachWnd, BOOL bAxisY, BOOL  bReverse);

extern "C" void PASCAL EXPORT  bpgSetTeachWndAxes(CWnd * hTeachWnd, WORD axisX, WORD axisY );

extern "C" void PASCAL EXPORT  bpgSetTeachWndExtendOptions(CWnd * hTeachWnd, int flags);
extern "C" int PASCAL EXPORT   bpgGetTeachWndExtendOptions(CWnd * hTeachWnd);

extern "C" void PASCAL EXPORT   bpgSetRobotToTeachPage(CWnd * hTeachWnd, HANDLE hRobot);
extern "C" void PASCAL EXPORT   bpgSetCameraToTeachPage(CWnd * hTeachWnd, HANDLE hCamera);
extern "C" void PASCAL EXPORT   bpgSetAxisToTeachPage(CWnd * hTeachWnd, WORD axisX, WORD axisY);

extern "C" void PASCAL EXPORT   bpgSetViewModeToTeachPage(CWnd * hTeachWnd, int mode, BOOL bRefresh);
extern "C" void PASCAL EXPORT   bpgSetAddinTypeToTeachPage(CWnd * hTeachWnd, int type, BOOL bRefresh);
extern "C" int PASCAL EXPORT    bpgGetViewModeToTeachPage(CWnd * hTeachWnd );
extern "C" int PASCAL EXPORT    bpgGetAddinTypeToTeachPage(CWnd * hTeachWnd );

 extern "C" void PASCAL EXPORT  bpgSetSubmodeOfTeachPage(CWnd * hTeachWnd, int  mode, BOOL bRefresh );
 extern "C" int PASCAL EXPORT   bpgGetSubmodeOfTeachPage(CWnd * hTeachWnd );
  

 //添加新的机械位置,编辑模式下使用
 extern "C" int PASCAL EXPORT  bpgAddNewMachPosInTeachPage(CWnd * hTeachWnd,  BOOL bPolylineFinish, BOOL bRefresh );
 //修改机械位置，修改模式下使用
 extern "C" void PASCAL EXPORT  bpgChangeMachPosInTeachPage(CWnd * hTeachWnd,  /*int index, double x, double y,*/ BOOL bRefresh ); 
 //修改或添加模式下使用
 extern "C" void PASCAL EXPORT  bpgUpdateCameraPosInTeachPage(CWnd * hTeachWnd , double x, double y, BOOL bRefresh ); 

 extern "C" void PASCAL EXPORT bpgDeleteCncobjInTeachPage(HANDLE hTeachWnd,   BOOL bRefresh );

 //撤销当前点
 extern "C" int PASCAL EXPORT  bpgRevokeMachPosInTeachPage(CWnd * hTeachWnd , BOOL bRefresh ); 

 extern "C" void PASCAL EXPORT  bpgSetCncobjToModifyInTeachPage(CWnd * hTeachWnd , DWORD id, int cpointIndex,BOOL bRefresh ); 
  


//extern "C" void PASCAL EXPORT  bpgSetTeachWndSceneId(CWnd * hTeachWnd, int sceneId);
//extern "C" int PASCAL EXPORT   bpgGetTeachWndSceneId(CWnd * hTeachWnd);

extern "C" void PASCAL EXPORT  bpgStopPlayTeachWnd (CWnd* hTeachWnd);
extern "C" BOOL PASCAL EXPORT  bpgStartPlayTeachWnd (CWnd* hTeachWnd);

extern "C" void   PASCAL EXPORT  bpgSetTeachWndFocusSize(CWnd * hTeachWnd, int sx, int cy);
extern "C" RvSize PASCAL EXPORT  bpgGetTeachWndFocusSize(CWnd * hTeachWnd );

extern "C" void  PASCAL EXPORT  bpgLockTeachWnd(CWnd* hTeachWnd, BOOL flag);
extern "C" BOOL  PASCAL EXPORT  bpgIsTeachWndLocked(CWnd* hTeachWnd);

extern "C" CRealView* PASCAL EXPORT  bpgGetViewOfTeachWnd(CWnd* hTeachWnd);
 
extern "C" void PASCAL EXPORT   bpgDestroyTeachWnd(CWnd*& hTeachWnd);

//支持backpage所有创建的cwnd
extern "C" void PASCAL EXPORT   bpgMoveWindow(CWnd* pThis, int left, int top, int width, int height);
extern "C" void PASCAL EXPORT   bpgSetWindowCaption(CWnd* pThis , const char* strCaption);

extern "C" void PASCAL EXPORT   bpgCenterWindow(CWnd* pThis, CWnd* pParent);
extern "C" void PASCAL EXPORT   bpgShowWindow(CWnd* pThis , BOOL flag);


 //序列化参数：flag 是否为读操作(TRUE)，校准类型id(可是视场的id等)， scale x, scale y, width, height, timestamp, user data
typedef BOOL (WINAPI *CF_READ_ALIBRATE_FOV_FUNC)( DWORD*,  double*, double* ,double* , double*, time_t* , void*);
typedef BOOL (WINAPI *CF_WRITE_ALIBRATE_FOV_FUNC)( DWORD,  double  , double , double , double , time_t, void*);


//创建视场比例标定窗口
//传入的相机在打开状态
typedef struct __cali_fov_e2_params_{
	DWORD   id ;                //该id 可选   
	BOOL    bShowAuxcam;        //是否支持辅助相机
	BOOL    bShowMotionPad;
	BOOL    bEditPosValid;      //校准位置是否有效
	WORD     axisX, axisY, axisZ ;  	
	double  posX, posY, posZ;      //编辑位置, posZ为保留
	CCamera* pAuxCam;
	CF_READ_ALIBRATE_FOV_FUNC   fnCaliFovRead;
	CF_WRITE_ALIBRATE_FOV_FUNC  fnCaliFovWrite; 
	void*                        pUserData;
}CF2_PARAMS;

extern "C" CWnd* PASCAL EXPORT bpgCreateCaliFovE2Wnd(CWnd* pParent, CCamera* pCamera, CRobot* pRobot, CF2_PARAMS* pParams);
extern "C" void PASCAL EXPORT bpgSetCaliFovE2WndCallback(CWnd* pCaliFovE2Win, CF_READ_ALIBRATE_FOV_FUNC fnCaliFovRead, CF_WRITE_ALIBRATE_FOV_FUNC fnCaliFovWrite,  void*  pUserData);

extern "C" void PASCAL EXPORT  bpgReleaseCaliFovE2View(CWnd* pCaliFovE2Win );
extern "C" void PASCAL EXPORT  bpgDestroyCaliFovE2Wnd(CWnd* &pCaliFovE2Win);

//对话框显示FOV标定
extern "C" INT_PTR PASCAL EXPORT bpgShowCaliFovE2Wnd(const TCHAR* strTitle,  CCamera* pCamera, CRobot* pRobot, const TCHAR*  strParamFile, CF2_PARAMS params);
extern "C" BOOL  PASCAL EXPORT   bpgReadCaliFovE2Params(const TCHAR*  strParamFile, UINT* pId,  BPG_FOV_INFO* pFovInfo);


//扫描拼图
//回调： id, total, index, RvImage, userdata
typedef void (WINAPI* SSI_SHOT_ONCE_FUNC)(DWORD , int , int , const RvImage, void*);

typedef struct __ssp_scan_params_ {
//	int          sceneId;                //场景ID   
	int          stillTime;         //拍照前静止状态时间
	WORD          axisX, axisY, axisZ;     //x,y轴号
	RvPoint_f64  leftTop;
	RvPoint_f64  rightBottom;
	double       shotPosZ;                //Z轴位置， <=0 的话，不移动z轴位置
	double       fovWidth;
	double       fovHeight;	
	
	 
	union{
	   SSI_SHOT_ONCE_FUNC  fnShotOnce;    //适用bpgShowScanWnd 
	   CRealView*          pRealView;    //适用bpgShowScanWndE1
	};

	union{
	    void*        pUserData;   //适用bpgShowScanWnd 
	    double       pixelsPerMm; //适用bpgShowScanWndE1
	};

	double       scaleX, scaleY;  //输出扫描后的图像算出的根据实际比例输出

}SSP_PARAMS;

extern "C" INT_PTR PASCAL EXPORT  bpgShowScanWnd(CRobot * pRobot, CCamera * pCamera, RvImage imResult, SSP_PARAMS* pParam);
extern "C" INT_PTR PASCAL EXPORT  bpgShowScanWndE1(CRobot * pRobot, CCamera * pCamera,  SSP_PARAMS* pParam);


//下面接口未实现
extern "C" CWnd* PASCAL EXPORT    bpgCreateScanWnd(CWnd* pParent, int left, int top, int width, int height);
extern "C" void PASCAL EXPORT     bpgDestroyScanWnd(CWnd* &pScanWnd );
extern "C" BOOL PASCAL EXPORT     bpgExecuteScanWnd(CWnd* pScanWnd, CRobot * pRobot, CCamera * pCamera, double pixelsPerMm, SSP_PARAMS* pParam);
extern "C" void PASCAL EXPORT     bpgSetScanWndPos(CWnd*  pScanWnd, int left, int top, int width, int height );
extern "C" CRealView* PASCAL EXPORT  bpgGetViewOfScanWnd(CWnd* hTeachWnd);


//标定移动相机
//extern "C" int PASCAL EXPORT bpgCalibrateMobileCamera( CUtString strTitle, CCamera* pCamera, CRobMot* pRotMot, CWorkDesk* pWorkDesk,  CT_PARAMS extra );

//标定全景相机
//extern "C" int PASCAL EXPORT bpgCalibrateTopCamera( CUtString strTitle, CCamera* pTopCamera, CCamera* pMobileCamera, CRobMot* pRotMot, CWorkDesk* pWorkDesk,  CT_PARAMS extra );

extern "C" INT_PTR PASCAL EXPORT bpgShowCaliCamToToolDistWnd(const TCHAR* strTitle, CRobot* pRotMot, CCamera* pCamera, CLD_PARAMS params, RvOffset_f64* pResult);
extern "C" CWnd* PASCAL EXPORT   bpgCreateCaliCamToToolDistWnd(CWnd* pParent,   CRobot* pRotMot, CCamera* pCamera, CLD_PARAMS params);
extern "C" void PASCAL EXPORT    bpgDestroyCaliCamToToolDistWnd(CWnd* &pCcttdWin);



//从1开始计数
extern "C" CWnd* PASCAL EXPORT bpgCreateInputOutputWndE1(CWnd* pParent, CMotion* pMotion, CGpio* pInputArr, int inputCount, CGpio* pOutputArr, int outputCount);
extern "C" BOOL PASCAL EXPORT  bpgRefreshInputOutputWndE1(CWnd*  pInputOutputWnd, int* pErrCode);
extern "C" void PASCAL EXPORT  bpgDestroyInputOutputWndE1(CWnd* &pInputOutputWnd);
 

// 
////自动定位编辑窗
//extern "C" int PASCAL EXPORT bpgShowAutoLocateWnd(CUtString strTitle, const RvImage image, CCaliber* pCaliber);
//
////定位器编辑器
//extern "C" int PASCAL EXPORT bpgShowLocaterEditorWnd(CUtString strTitle, const CRealView* pLinkedView, CCaliber* pCaliber);
//

//全局视场编辑窗口
//seqCncElem里面的元素由外部调用者释放
//同时，外部调用者也要释放该函数产生的新的cnc elem对象
//extern "C" int PASCAL EXPORT bpgShowTopSightEditorWnd(CUtString strTitle, const RvImage image, RvSequence seqCncElem, BOOL bJigsawWinValid);
//
//extern "C" CWnd* PASCAL EXPORT bpgCreateTopSightEditorWnd(CWnd* pParentWnd,  CUtString strTitle, const RvImage image );
//
//extern "C" void PASCAL EXPORT bpgSetCncElemToSightEditor(CWnd* pEditorWin, const RvSequence seqCncElem );
//extern "C" void PASCAL EXPORT bpgGetCncElemToSightEditor(CWnd* pEditorWin, RvSequence seqCncElem );
//extern "C" void PASCAL EXPORT bpgClearCncElemToSightEditor(CWnd* pEditorWin);
// 
//extern "C" void PASCAL EXPORT  bpgDestroyTopSightEditorWnd(CWnd* &pEditorWin);

