⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ddlayerfiles.cpp

📁 这是一个在vxWorks操作系统下的原创电子地图代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:

/* 04-10-28,added some modifies, chinese notes of code*/
/*#include "mapDataStruct.h"*/
#include "math.h"


#include "taskLib.h"
#include "ioLib.h"
#include "iosLib.h"
#include "vxWorks.h"
#include"stdio.h"
#include <ugl/ugl.h>
#include "string.h"
#include <zinc/zaf.hpp>
#include <zinc/z_dsp.hpp>
//#include "ftugldrawText.h"

extern  "C"{
#undef emap_Ddl_Debug
#undef emap_Mdl_Debug
#undef emap_Msl_Debug

/*每一层地图的数据格式定义*/

typedef struct MapBoard						/*某层的地图边界*/
{
	double Top, Left , Width, Height;		/*经纬度*/
}tMapBoard;
typedef struct Points
{
	double x, y, z;
	struct Points *NextPoint;
}tPoints;

/*线段和多边形结构定义,对于线段和多边形以索引点的颜色为准,对于环形图形,环内部
以对应索引点为准*/

typedef struct Parts/*索引*/
{
	UINT32 PartsIdx;
	UINT32 Color;
	struct Parts *NextParts;
}tParts;

typedef struct MapRecord
{
	UINT32 NumParts;/*索引点数量*/
     struct Parts *firstParts;/*索引点*/
     UINT32 NumPoints;/*图形顶点数量*/
     struct Points *firstPoints;/*图形顶点*/
	struct MapRecord *NextRecord;/*下一个元素*/
}tMapRecord;

typedef struct MapLayer/*图层*/
{
	struct MapBoard Board;
	UINT32 ShapeType;  /*0 no map, 1  point, 3  ployline , 5  ploygon */
	UINT32 SurfaceType; /* unused*/
	BOOL IsDisplay;		/*displaying or not */
	UINT32 NumRecord;/*图层中的元素个数*/
	struct MapRecord *firstRecord;/*图层中的第一个元素*/
}tMapLayer;

/*文本信息格式定义*/
typedef struct Label
{
	int length;
	struct Points *point;
	char name[36];/*信息内容*/
	struct Label * NextLabel;
}tLabel;

typedef struct LabelLayer
{
	UINT32 LabelNum;
	BOOL IsDisplay;
	UINT32 Color;
	struct Label *firstLabel;
	struct LabelLayer *NextLabelLayer;
}tLabelLayer;

/*global struct  for vxemap*/

typedef struct MapGlobal 
{
	double Scale;				/*当前地图的显示比例*/
	int MapTop, MapLeft;			/*当前地图显示内容的左上角坐标*/
	int MapWidth, MapHeight;				/*显示地图的宽、高*/
	struct MapBoard board;					/*显示地图的经纬范围*/
	BOOL manyou;						/*是否漫游*/
	double mzoom, mxmove, mymove;		/*mzoom 为放大系数, mxmove, mymove漫游位移*/
	UINT16 layerMapNum; 					/*电子地图的层数*/
	int currentLayer;
	struct MapLayer *firstLayer;			/*指向第一层的指针*/
	UINT16 LabelNum;					/*信息层数*/
	struct LabelLayer *firstLable;
}tMapGlobal;

typedef struct PointInt
{
	 int x;
	 int y;
}tPointInt;
/*struct MapGlobal  vxemap ;*/		/*定义地图的全局变量*/
/*struct MapLayer   *MapLayerNum[8];*/  /*定义地图总共图层*/

#define LENMAPLAYER sizeof(struct MapLayer)
#define LENPOINTS sizeof(struct Points)
#define LENPARTS sizeof(struct Parts)
#define LENLABEL sizeof(struct Label)
#define LENLABELLAYER sizeof(struct LabelLayer)
#define LENMAPRECORD sizeof(struct MapRecord)
#define LENPOINTINT sizeof(struct PointInt)

#define MAPFILENUM   7
#define MAPFILE1		"District.shp" /*"dljck.shp"*/
#define MAPFILE2		"ResidentialArea.shp" /*"dlzxx.shp"*/
#define MAPFILE3		"Vegetable.shp"/*"dlx.shp"*/
/*#define MAPFILE4		"CrossRoads.shp"*//*"dzsx.shp"*/
#define MAPFILE4		"RoadPoly2.shp" /*"jzx.shp"*/
#define MAPFILE5		"RoadPoly3.shp" /*"tdx.shp"*/
#define MAPFILE6		"ExpressWay.shp"
#define MAPFILE7		"Railway.shp"

#define MAPFILEPOINT1      	"Business.shp"
#define MAPFILEPOINT2	     "Park.shp"
#define MAPFILEPOINT3		"School.shp"

#define DBF1			"Business.dbf"
#define DBF2			"Park.dbf"
#define DBF3			"School.dbf"


 struct MapGlobal  vxemap ;		
 struct MapLayer   *MapLayerNum[7];    
 struct Label  *MapLabel[3];
 ZafIChar GBstring[100];

  long DDL_getLongtoFile(FILE * fp, BOOL isBig);
  STATUS MDL_CDrawPloy(ZafDisplay *display, int pointNum, struct PointInt * points);
  STATUS MDL_CDrawPloyline(ZafDisplay *display, int pointNum, struct PointInt *points);
  int MDL_doxcoordinate(int xy);
  int MDL_doycoordinate(int y);
  int MDL_dofxcoordinate(double xy);
  int MDL_dofycoordinate(double y);
  STATUS MSL_showMapLayer(ZafDisplay *display, int layernumber );
  void DDL_initMapGlobal();
  STATUS  DDL_readMapFiles(char *filepath);
  STATUS DDL_readLabelPoint(char *filePath);
  STATUS DDL_readDbfFile(char *filePath);
  void InitializeEmapLib(char *filePath);
  int MDL_getCurrentMapLayer();
  STATUS MDL_drawMapLayer(ZafDisplay *display, struct MapLayer * pmapl);
  STATUS MSL_draw1Round(ZafDisplay *display, int x, int y, int r);
  STATUS MSL_ShowMapText(ZafDisplay *display);
  STATUS MSL_setGcProperty(ZafDisplay *display, ZafLogicalColor fcolor, 
	ZafLogicalColor bcolor,ZafLogicalLineStyle linestyle);
  STATUS MSL_ClearScreen(ZafDisplay *display, ZafRegionStruct windRec, ZafLogicalColor forColor, ZafLogicalColor backColor);
  STATUS MSL_DrawText(UGL_ID gc, int x, int y, int textlength, UGL_WCHAR * text);
  void SetEmapView(int left, int top, int width, int height);
  void SetEmapViewRec(ZafRegionStruct windRec);


  void EmapZoomIn();
  void EmapZoomOut();
  void EmapMoveUp();
  void EmapMoveDown();
  void EmapMoveLeft();
  void EmapMoveRight();
  void SetCurrentMapLayer(int layernum);
  void InitializeEmapLib(char *filePath);
  void RedrawEmap(ZafDisplay * display, ZafRegionStruct windRec);


void DDL_initMapGlobal()
{
	vxemap.layerMapNum = 7; vxemap.manyou = TRUE; 
	vxemap.MapHeight = 480; vxemap.MapWidth = 640;
	vxemap.MapLeft = 0; vxemap.MapTop = 0;
	vxemap.board.Left = 0; vxemap.board.Top = 0;
	vxemap.board.Width = 0; vxemap.board.Height = 0;
	vxemap.mxmove = -50; vxemap.mymove = -100;
	vxemap.mzoom = 1.2;  vxemap.Scale = 0; 
	vxemap.firstLable = 0; vxemap.LabelNum = 3;
	vxemap.currentLayer = 7;
}
/*销毁地图纪录*/
/*destroy points list*/
STATUS DDL_destroyPoints(struct Points * pPoints)
{
	struct Points *p, *p1;

	p = pPoints;
	if(p == NULL)
		return(0);
	do{
		p1 = p;
		p = p->NextPoint;
		free(p1);
	}while(p != NULL);

	return(1);
}

/*整数坐标链表*/
#if 0
STATUS DDL_destroyPointsInt(struct PointInt* pPoints)
{
	struct PointInt *p, p1;
	
	p = pPoints;
	if(p == NULL)
		return(0);
	do{
		p1 = p;
		p = p->NextPoint;
		free(p1);
	}while(p != NULL);

	return(1);
}
#endif
/*destroy parts list*/
STATUS DDL_destroyParts(struct Parts *pParts)
{
	struct Parts *p, *p1;
	
	p = pParts;
	if(p == NULL)
		return(0);
	do{
		p1 = p;
		p = p->NextParts;
		free(p1);
	}while(p != NULL);

	return(1);
}

/*destroy map record list*/
STATUS DDL_destroyRecord(struct MapRecord *pRecord)
{
	struct MapRecord *p, *p1;
	
	p = pRecord;
	if(p == NULL)
		return(0);
	DDL_destroyParts(pRecord->firstParts);
	DDL_destroyPoints(pRecord->firstPoints);
	do{
		p1 = p;
		p = p->NextRecord;
		free(p1);
	}while(p != NULL);

	return(1);
}

/*destroy Label/Text list*/
STATUS DDL_destroyLabel(struct Label*pLabel)
{
	struct Label *p, *p1;
	
	p = pLabel;
	if(p == NULL)
		return(0);
	do{
		p1 = p;
		p = p->NextLabel;
		free(p1);
	}while(p != NULL);

	return(1);
}

/*destroy Label/Text layer*/
STATUS DDL_destroyLabLayer(struct LabelLayer*pLabLayer)
{
	struct LabelLayer*p, *p1;
	
	p = pLabLayer;
	if(p == NULL)
		return(0);
	DDL_destroyLabel(pLabLayer->firstLabel);
	do{
		p1 = p;
		p = p->NextLabelLayer;
		free(p1);
	}while(p != NULL);

	return(1);
}
/*destroy all map Layers*/
STATUS DDL_destroyMapLayer(struct MapLayer *pMpLayer)
{
	struct MapLayer*p, *p1;
	
	p = pMpLayer;
	if(p == NULL)
		return(0);
	DDL_destroyRecord(pMpLayer->firstRecord);
	free(pMpLayer);
	
	return(1);	
}

STATUS  DDL_readMapFiles(char *filepath)/*读地图数据文件,并保存在图层MapLayerNum[6]中*/

	#ifdef emap_Ddl_Debug
	printf("read completely \n");
	#endif
}


long	DDL_getLongtoFile(FILE * fp, BOOL isBig) /*字符大端模式转小端模式*/
{
	char 	ch[2];
	int n;
	long	getData =0;
	if(fp == NULL)
		return(0);
	for(n = 0; n< 4; n++)
	{
		fread(&ch[0], 1, 1, fp);
		if(isBig == TRUE)
			getData = getData* 256 + ch[0];
		else
			getData =long(getData + ch[0] * pow(256, n));
	}
	return(getData);
}

STATUS DDL_readLabelPoint(char *filePath)
{
	FILE *fp[vxemap.LabelNum];
	char *tmppath[vxemap.LabelNum];
	char *fname[vxemap.LabelNum];
	int i, j ,k, rt =0;
	long	tempFileDataL[2]={0, 0},fileCode, recordNum, contentLength, jilushu,
		shapeType, fileLength[7], fileVersion[7];
	double  tempFileDataD[2];
	
	struct MapBoard board;
	struct Points *pp1, *pp2;
	struct Label *headLabel, *plabel1, *plabel2;
	struct Label *pLabel[vxemap.LabelNum];

	if(filePath == NULL)
	{
		#ifdef emap_Ddl_Debug
			printf("no dbf file!\n");
		#endif
		return(ERROR);
	}
	fname[0] = MAPFILEPOINT1; fname[1] = MAPFILEPOINT2; fname[2] = MAPFILEPOINT3 ; 
	
	for(i = 0; i< vxemap.LabelNum; i++)
	{
		if(MapLabel[i] == NULL)
		{
			#ifdef emap_Ddl_Debug
			printf("no label information layer %d\n", i);
			#endif
			return(ERROR);
		}
		pLabel[i] = MapLabel[i];
		tmppath[i] = (char *)malloc(sizeof(char) *50);
		if(tmppath[i] == NULL)
		{
			#ifdef emap_Ddl_Debug
			printf("NO MEMOERY MALLOC!\n");
			#endif
			return(ERROR);
		}
		strcpy(tmppath[i], filePath);
		strcat(tmppath[i], fname[i]);

		if((fp[i] = fopen(tmppath[i], "r")) == NULL)
		{
			#ifdef emap_Ddl_Debug
			printf("NOT open file %s!\n", tmppath[i]);
			#endif
			return(ERROR);
		}
		fileCode = DDL_getLongtoFile(fp[i], TRUE);
		#ifdef emap_Ddl_Debug
				printf("fileCode: %d\n",fileCode);
				#endif
		fseek(fp[i], 24, 0);		
		fileLength[i] = DDL_getLongtoFile(fp[i], TRUE);				/*read file header*/
		#ifdef emap_Ddl_Debug
				printf("fileLength: %d\n",fileLength[i]);
				#endif
		fread(&fileVersion[i], 4, 1, fp[i]);
		#ifdef emap_Ddl_Debug
				printf("fileVersion: %d\n",fileVersion[i]);
				#endif
		/*fread(tempFileDataL[1], 4, 1, fp[i]);
		pMap->ShapeType = tempFileDataL[1];*/
		fread(&tempFileDataL[1], 4, 1, fp[i]);
		shapeType = tempFileDataL[1];
		#ifdef emap_Ddl_Debug
				printf("ShapeType: %d\n",shapeType);
				#endif
		fread(&tempFileDataD[1], 8, 1, fp[i]);
		board.Left = tempFileDataD[1];
		#ifdef emap_Ddl_Debug
				printf("Board.Left: %f\n",tempFileDataD[1]);
				#endif
		if(vxemap.board.Left == 0)					/*2005-10-10 by yb*/
			vxemap.board.Left = tempFileDataD[1];
		fread(&tempFileDataD[1], 8, 1, fp[i]);
		board.Top = tempFileDataD[1];
		#ifdef emap_Ddl_Debug
				printf("Board.Top: %f\n",tempFileDataD[1]);
				#endif
		if(vxemap.board.Top == 0)						/*2005-10-10 by yb*/
			vxemap.board.Top = tempFileDataD[1];
		fread(&tempFileDataD[1], 8, 1, fp[i]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -