#include "stdafx.h"
//#include "ExportQBGISCtrlClass.h"
#include "GISDlg.h"
#include "Resource.h"
//#include "FlyLineDataStruct.h"
CGISDlg g_mapShowDlg;  
bool g_bCreateMap=false;

//显示GIS对话框
extern "C" BOOL WINAPI ShowGISDlg(const CRect rc, CWnd* pParent)//rc为GIS要显示的屏幕区域范围(包括地图和工具条)
{
	
    AFX_MANAGE_STATE(AfxGetAppModuleState()); 	
	g_mapShowDlg.SetGISWindowArea(rc);
	g_mapShowDlg.Create(IDD_DIALOG1, pParent);	
	g_mapShowDlg.MoveWindow(&rc, TRUE);
	g_mapShowDlg.ShowWindow(SW_SHOW);
	
	g_bCreateMap = true;
	return g_bCreateMap;
	
}
//创建窗口
extern "C"  BOOL WINAPI CreateWnd(CWnd* hParentWnd)
{
	//zcw add code begin
	AFX_MANAGE_STATE(AfxGetAppModuleState());
	
	//g_mapShowDlg.SetGISWindowArea(rc);
	
	
	//g_mapShowDlg.MoveWindow(&rc, TRUE);
	//g_mapShowDlg.ShowWindow(SW_SHOW);
	
	g_bCreateMap = g_mapShowDlg.Create(IDD_DIALOG1,hParentWnd);
		
	return g_bCreateMap;	   
	//zcw end
	
}
	//销毁窗口
extern "C" BOOL WINAPI DeleteWnd()
{
	//zcw add code begin
	 AFX_MANAGE_STATE(AfxGetAppModuleState());
	 g_bCreateMap = false;

	//删除对话框
	 g_mapShowDlg.DestroyWindow();
	//zcw end
	 return g_bCreateMap;
}
//获得窗口指针
extern "C" CWnd* WINAPI GetWnd()
{
	//zcw add code begin
	//::FromeHandle();
	return g_mapShowDlg.FromHandle(g_mapShowDlg.GetSafeHwnd());
	//zcw end
}

//函数功能:返回窗口句柄
extern "C" HWND WINAPI GetHWnd()
{
	//zcw add code begin
	return g_mapShowDlg.GetSafeHwnd();
	//return NULL;
	//zcw end 
}

//函数功能:移动窗口
	//int x,int y,int width,int height
extern "C" void WINAPI MoveWnd(int x,int y,int width,int height)
{
	//zcw add code begin


	g_mapShowDlg.SetWindowPos(NULL,x,y,width,height,1);
	//zcw end
}

//函数功能:移动窗口
	//LPCRECT lpRect
extern "C" void WINAPI MoveWnd2(const LPCRECT lpRect)
{
	//zcw add code begin
	//g_mapShowDlg.SetWindowPos(NULL,x,y,width,height,1);
	g_mapShowDlg.MoveWindow(lpRect);
	//zcw end
	//zcw end
}

///函数功能:显示窗口
	//BOOL
extern "C" void WINAPI ShowWnd(BOOL b)
{
	//zcw add code begin
	AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		g_mapShowDlg.ShowWindow(b);
	}
	//zcw end
}

//坐标转换函数
	//double *lon, double *lat,enum_CS CS_Dest,enum_CS CS_Sour
extern "C" void WINAPI CS2CS(double *lon, double *lat,enum_CS CS_Dest,enum_CS CS_Sour)
{
	//zcw add code begin


	//zcw end 
}
	
//航线读取函数
	//int iLine ,PTLIST *pList
extern "C" BOOL WINAPI ReadLine(int iLine ,PTLIST *pList)
{
	//zcw add code begin
	AFX_MANAGE_STATE(AfxGetAppModuleState());
	g_mapShowDlg.ReadLine(iLine, pList);
	//g_mapShowDlg.SetRouteLine(iLine, pList);
	return true;
	//zcw end
}

//添加航迹点函数
	//lon:经度,°为单位
	//lat:维度,°为单位
	//head:航向°为单位
    //double *pIFOVExtent:视场范围,8个元素的数字指针
extern "C" void WINAPI AddAirPt(int uavid,double lon,double lat,double alt,double head,double *pIFOVExtent,bool control)
{
	//zcw add code begin
	AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		g_mapShowDlg.AddFlyPoint(uavid,lon, lat, head,control);
	}
	//zcw end
}

extern "C" void WINAPI AddAirPt_ADS(const int uavNum, const int uavid, const double lon, const double lat, const double yaw, const bool control, const CString strPlaneName)
{
	AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		g_mapShowDlg.AddFlyPoint_ADS(uavNum, uavid, lon, lat, yaw, control, strPlaneName);
	}
}

//地图控件向内接口函数
	//struMapIn mapIn
extern "C" BOOL WINAPI SetMap(struMapIn mapIn)
{
	//zcw add code begin

	return true;
	//zcw end
}

//设置地图模块显示模式,用于飞控和载荷软件,
	//b:TRUE:飞控模式,FALSE:载荷模式
extern "C" BOOL WINAPI SetMode(BOOL b)
{
	//zcw add code begin

	return true;
	//zcw end
}

////用于显示航点号,航线号,侧偏距等信息
extern "C" BOOL WINAPI DRAW_FK( tagDRAWZK DrawZk)
{
	//2015.11.19
	AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_mapShowDlg && g_mapShowDlg.GetSafeHwnd())
	{
		g_mapShowDlg.m_DRAWZK = DrawZk;
		::PostMessage(g_mapShowDlg.GetSafeHwnd(),MESSAGE_DRAWZK, 0, 0);
	}
	return false;

}

//1:航线1  2:航线2 3:航线3  4:航线4 5:航线5
	//-1:操作失败;0:显示航线;1:隐藏航线
extern "C" int WINAPI ShowLine(int iLine)
{

	AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		g_mapShowDlg.SetFlyLineShowStatus(iLine);
		//return 1;
	}
	return g_mapShowDlg.m_pHaveDrawLineFlag[iLine-1];

}

//显示GMTI的函数体
    //char*pData:数据内存
	//int iLen:数据长度
extern "C" BOOL  WINAPI GMTI(char*pData,int iLen)
{
	//zcw add code begin
	
	return true;
	//zcw end
}
//功能:删除GIS对话框
extern "C" void WINAPI DeleteGISDlg()
{
	 AFX_MANAGE_STATE(AfxGetAppModuleState());
	g_bCreateMap = false;

	//删除对话框
	g_mapShowDlg.DestroyWindow();
}


//功能:输入无人机的经纬度,标绘航迹
//输入:经度lon(以°为单位)
//      纬度lat(以°为单位)
//      航向角yaw(以°为单位)
extern "C" void WINAPI SetUAVFlyCoordinate(int uavid,const double lon, const double lat, const double yaw,bool control)
{
 AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		//增加无人机的飞行航点
		g_mapShowDlg.AddFlyPoint(uavid,lon, lat, yaw,control);
	}
}



//功能:增加目标点,在地图显示区标绘出来
//输入:目标点号ptID,经度lon,纬度lat
extern "C" void WINAPI AddTarget(const int ptID, const double lon, const double lat)
{
	 AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		//标绘目标点
		g_mapShowDlg.AddTargetPoint(ptID, lon, lat);
	}
}



//功能:删除给定ID号的目标点
//输入:目标点号ptID
extern "C" void WINAPI DeleteTarget(const int ptID)
{
 AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		//增加给定ID号的目标点
		g_mapShowDlg.DeleteTarget(ptID);
	}
}

//功能:删除所有目标点
extern "C" void WINAPI DeleteAllTargets()
{
 AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		//增加无人机的飞行航点
		g_mapShowDlg.DeleteAllTargets();
	}
}
	


//功能:在地图显示区标绘出装订的飞行航线数据
//输入:航线数据体集合linePtArray,航线的航点个数ptNum
extern "C" void WINAPI DrawBindFlyLine(const PtStruct *linePtArray, const int ptNum)
{
 AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		//绘制装订航线
		g_mapShowDlg.DrawBindingLine(linePtArray, ptNum);
	}
}


// 显示或隐藏dlg
//输入:显示状态nCmdShow,0为隐藏;1为显示
//extern "C" void WINAPI ShowWnd(int nCmdShow)
//{
 /*AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		g_mapShowDlg.ShowWindow(nCmdShow);
	}*/
//}


//功能:设置地面站位置
//输入:经度lon,纬度lat,高度alt
extern "C" void WINAPI SetGCSPosition(const double lon, const double lat, const double alt)
{
 AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		g_mapShowDlg.SetGCSPosition(lon, lat, alt);
	}
}



//功能:标绘导引点位置
//输入:导引点类型guideMode(1为导引飞行1,2为导引飞行2),经度lon,纬度lat
extern "C" void WINAPI DrawGuidePoint(const BYTE guideMode, const double lon, const double lat)
{
 AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		//在地图显示区标绘导引点
		g_mapShowDlg.DrawGuidePoint(guideMode, lon, lat);
	}
}



//功能:显示给定名称的航线
//输入:航线文件strFlyLineName
extern "C" void WINAPI DisplayFlyLine(const CString strFlyLineName)
{
 AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		//在地图显示区标绘导引点
		g_mapShowDlg.OnShowGivenLine(strFlyLineName);
	}
}

// 功能:设置导引方式消息发送句柄及消息号
extern "C" void WINAPI SetMsgInfo(const HWND hwnd, const UINT msgID)
{
 AFX_MANAGE_STATE(AfxGetAppModuleState());
	g_mapShowDlg.SetMsgInfo(hwnd, msgID);
}


// 功能:设置装订航线消息发送句柄及消息号
extern "C" void WINAPI SetLoadLineMsgInfo(const HWND hwnd, const UINT msgID)
{
	AFX_MANAGE_STATE(AfxGetAppModuleState());
	g_mapShowDlg.SetLoadLineMsgInfo(hwnd, msgID);
}




//功能:标绘回收点位置
//输入:导引点类型callbackMode(1为回收点1;2为回收点2),经度lon,纬度lat
extern "C" void WINAPI DrawCallBackPoint(const BYTE callbackMode, const double lon, const double lat)
{
 AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		//在地图显示区标绘回收点
		g_mapShowDlg.DrawCallBackPoint(callbackMode, lon, lat);
	}
}


// #ifdef _DEBUG
// #undef THIS_FILE	
// static char THIS_FILE[]=__FILE__;
// #define new DEBUG_NEW
// #endif

extern "C" void WINAPI GetMouseWheel(short m_zDelta)
{
	AFX_MANAGE_STATE(AfxGetAppModuleState());
	if (g_bCreateMap)
	{
		g_mapShowDlg.MouseWheel(m_zDelta);
	}
}

extern "C" void WINAPI UpdateDataInfo(int index,const char* key,double value )
{
	AFX_MANAGE_STATE(AfxGetAppModuleState());
	/*if (g_bCreateMap)
	{
		g_mapShowDlg.UpdateDataInfo(index,key,value);
	}*/
}