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

📄 ddlayerfiles.cpp

📁 这是一个在vxWorks操作系统下的原创电子地图代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		board.Width = tempFileDataD[1];
		#ifdef emap_Ddl_Debug
				printf("Board.Width: %f\n",tempFileDataD[1]);
				#endif
		if(vxemap.board.Width == 0)
			vxemap.board.Width = tempFileDataD[1];
		fread(&tempFileDataD[1], 8, 1, fp[i]);
		board.Height = tempFileDataD[1];
		#ifdef emap_Ddl_Debug
				printf("Board.Height: %f\n",tempFileDataD[1]);
				#endif
		if(vxemap.board.Height == 0)
			vxemap.board.Height = tempFileDataD[1];
		fseek(fp[i], 100, 0);			/*定位到100个字节,开始读文件的记录部分*/

		if(shapeType == 1)
		{
			/*/pp1=pp2=(struct Points *)malloc(LENPOINTS);
				//pPoint = NULL;*/
				pp1 =(struct Points *)malloc(LENPOINTS);/*create mapRecord->points link list , but only one node */
				if(pp1 == NULL)
				{
					#ifdef emap_Ddl_Debug
					printf("NO MEMORY MALLOC pp1\n!");
					#endif
					return(ERROR);
				}
				recordNum = DDL_getLongtoFile(fp[i], TRUE);		/*read record header*//*record numbers*/
				#ifdef emap_Ddl_Debug
					printf("recordnum: %d\n",recordNum);
					#endif
				contentLength = DDL_getLongtoFile(fp[i], TRUE);				/*content length*/
				#ifdef emap_Ddl_Debug
					printf("contentLength: %d\n",contentLength);
					#endif	
				fread(&tempFileDataL[1], 4, 1, fp[i]);
				shapeType = tempFileDataL[1];					/*shape type*/
				fread(&tempFileDataD[1], 8, 1, fp[i]);			/*coordinate of the first point  ,读第一个记录的第一个点*/
				pp1->x = tempFileDataD[1];
				rt = fread(&tempFileDataD[1], 8, 1, fp[i]);
				/*#ifdef emap_Ddl_Debug
				printf("rt: %d\n",rt);
				#endif*/
				pp1->y = tempFileDataD[1];
				#ifdef emap_Ddl_Debug
				printf("x coordinate: %f, y coordinate: %f\n",pp1->x, pp1->y);
				#endif
				pLabel[i]->point = pp1;				/*把第一个记录插入链表*/
				/*pp2 = pp1;
				pp2->NextPoint = NULL;*/
				pLabel[i] = pLabel[i]->NextLabel;
				while(!feof(fp[i]))					/*继续读取剩下的记录数据*/
				{
					/*/pp1 = (struct Points *)malloc(LENPOINTS);*/
				
					recordNum = DDL_getLongtoFile(fp[i], TRUE);				/*read record header*/
					#ifdef emap_Ddl_Debug
					printf("recordnum: %d\n",recordNum);
					#endif
					contentLength = DDL_getLongtoFile(fp[i], TRUE);
					#ifdef emap_Ddl_Debug
					printf("contentLength: %d\n",contentLength);
					#endif
					rt = fread(&tempFileDataL[1], 4, 1, fp[i]);
					/*#ifdef emap_Ddl_Debug
					printf("rt: %d\n",rt);
					#endif*/
					if(rt)
					{
						pp1 =(struct Points *)malloc(LENPOINTS);
						if(pp1 == NULL)
						{
						#ifdef emap_Ddl_Debug
						printf("NO MEMORY MALLOC pp1\n!");
						#endif
						return(ERROR);
						}
					}
					else {
						#ifdef emap_Ddl_Debug
						printf("end record\n!");
						#endif	
						break;
						}
					shapeType = tempFileDataL[1];
					rt = fread(&tempFileDataD[1], 8, 1, fp[i]);
					#ifdef emap_Ddl_Debug
					printf("rt: %d\n",rt);
					#endif
					pp1->x = tempFileDataD[1];
					rt = fread(&tempFileDataD[1], 8, 1, fp[i]);
					#ifdef emap_Ddl_Debug
					printf("rt: %d\n",rt);
					#endif
					pp1->y = tempFileDataD[1];
					#ifdef emap_Ddl_Debug
					printf("x coordinate: %f, y coordinate: %f\n",pp1->x, pp1->y);
					#endif
					pLabel[i]->point = pp1;
					pLabel[i] = pLabel[i]->NextLabel;
					if(pLabel[i] == NULL)
					{
						#ifdef emap_Ddl_Debug
						printf("end mapLabel[%d] before malloc\n!", i);
						#endif
						break;
					}
				}
		}
		free(tmppath[i]);
		fclose(fp[i]);
		#ifdef emap_Ddl_Debug
		printf("read piontfile %d ok\n",i);
		#endif
	}
	#ifdef emap_Ddl_Debug
		printf("read all piontfile ok\n"); 
	#endif
	return(OK);
}

STATUS DDL_readDbfFile(char *filePath)
{
	FILE *fp[vxemap.LabelNum];
	char *fpath[vxemap.LabelNum]; 
	char *fname[vxemap.LabelNum];
	char tmp[52];
	char okch[36];
	struct Label *pMLabel[vxemap.LabelNum];
	struct Label *p1, *p2;

	int i, j, cordernum = 0, chnum = 0, hznum = 2;
	
	if(filePath == NULL)
	{
		#ifdef emap_Ddl_Debug
			printf("no dbf file!\n");
		#endif
		return(ERROR);
	}

	fname[0] = DBF1; fname[1] = DBF2; fname[2] = DBF3;
	for(j = 0; j< vxemap.LabelNum; j++)
	{
		fpath[j] = (char *)malloc(sizeof(char) *50);
		if(fpath[j] == NULL)
		{
			#ifdef emap_Ddl_Debug
			printf("NO MEMOERY MALLOC!\n");
			#endif
			return(ERROR);
		}
		strcpy(fpath[j], filePath);
		strcat(fpath[j], fname[j]);

		if((fp[j] = fopen(fpath[j], "r")) == NULL)
		{
			#ifdef emap_Ddl_Debug
			printf("not open file: %s! \n", fpath[j]);
			#endif
			return(ERROR);
		}
		else
		{
			#ifdef emap_Ddl_Debug
			printf("open file: %s! ok\n", fpath[j]);
			#endif
		}
		fseek(fp[j], 66, SEEK_SET);
		if(!fread(tmp, 51, 1, fp[j]))
		{
			#ifdef emap_Ddl_Debug
			
				printf("no recorder\n");
				return(ERROR);
			#endif
		}
		else
		{
			#ifdef emap_Ddl_Debug
			printf("read next record!\n", fpath[j]);
			#endif
		}
		cordernum++;
		pMLabel[j] = NULL;
		p1 = p2 = (struct Label*)malloc(LENLABEL);
		for( i=0; i<36; i++)
		{
				if(tmp[i] == 0x20)
				{
					chnum =i;
					break;
				}
		}
		for(i = 0; i < chnum; i++)
		{
			okch[i] = tmp[i];
		}
		okch[++i] = '\0'; 
		strcpy(p1->name, okch);
		hznum = (chnum +1)/2;
		p1->length = hznum;
		pMLabel[j] = p1;
			
		while(fread(tmp, 51, 1, fp[j]))
		{
			cordernum++;
			p1 = (struct Label*)malloc(LENLABEL);
			for( i=0; i<36; i++)
			{
				if(tmp[i] == 0x20)
				{
					chnum =i;
					break;
				}
			}
			for(i = 0; i < chnum; i++)
			{
				okch[i] = tmp[i];
			}
			okch[++i] = '\0'; 
			strcpy(p1->name, okch);
			hznum = (chnum +1)/2;
			p1->length = hznum;
			p2->NextLabel = p1;
			p2 = p1;
		}
		MapLabel[j] = pMLabel[j];
		p2->NextLabel = NULL;
		p1 = p2 =NULL;
		free(fpath[j]);
		fclose(fp[j]);
	}
	#ifdef emap_Ddl_Debug 
	printf("read dbf file all, ok!\n");
	#endif
	return(OK);
}

void SetCurrentMapLayer(int layernum)
{
	vxemap.currentLayer = layernum;
}

int MDL_getCurrentMapLayer()
{
	return(vxemap.currentLayer);
}

void EmapZoomIn()
{
	if(vxemap.manyou == FALSE)
		vxemap.manyou = TRUE;
		vxemap.mzoom = vxemap.mzoom *1.2;
}

void EmapZoomOut()
{
	if(vxemap.manyou == FALSE)
		vxemap.manyou = TRUE;
		vxemap.mzoom = vxemap.mzoom *0.8;
}

void EmapMoveUp()
{
	if(vxemap.manyou == TRUE)
					{
				 		vxemap.mymove = vxemap.mymove + 10;
					}
}

void EmapMoveDown()
{
	if(vxemap.manyou == TRUE)
					{
						vxemap.mymove = vxemap.mymove - 10;
					}
}

void EmapMoveLeft()
{
	if(vxemap.manyou == TRUE)
					{
						vxemap.mxmove = vxemap.mxmove + 10;

					}
}

void EmapMoveRight()
{
	if(vxemap.manyou == TRUE)
					{
						vxemap.mxmove = vxemap.mxmove - 10;

					}
}

void EmapMouseSpan(int dx , int dy)
{
	if(vxemap.manyou == TRUE)
		{
			vxemap.mxmove = vxemap.mxmove + dx;
			vxemap.mymove = vxemap.mymove + dy;
		}
}
STATUS	MDL_drawMapLayer(ZafDisplay *display, struct MapLayer * pmapl)	/*从图层提取数据并绘制图形*//*04-11-2 去掉一些形式参数*/
{
	int ii = 0, jj = 0, idx = 0, pdx = 0, ploygpointnum = 0, ploylinepnum = 0,
		tmpx1 = 0, tmpy1= 0, tmpx2 = 0, tmpy2 = 0;
	double fxmax, fxmin, fymax, fymin, fxwidth, fyheight;
	double okx, oky, zoom = 1, xmove = 0 , ymove = 0;
	long partIdex[50];
	struct PointInt pp[4000];
	struct MapLayer *pthis;
	struct MapRecord *headRecord, *pRecord;
	struct Parts *headPart, *pPart;
	struct Points *headPoint, *pPoint;

	pthis = pmapl; zoom = vxemap.mzoom; xmove = vxemap.mxmove; ymove = vxemap.mymove;
	if(pthis == NULL)
	{
		#ifdef emap_Mdl_Debug
			printf("this map layer is null\n!");
		#endif
		return(ERROR);
	}
	if(vxemap.manyou == FALSE)
	{xmove = 0; ymove = 0;}
	if((vxemap.board.Left == 0)&&(vxemap.board.Top == 0)
		&&(vxemap.board.Width == 0)&&(vxemap.board.Height == 0))
	{
		vxemap.board.Left = pthis->Board.Left; vxemap.board.Top = pthis->Board.Top;
		vxemap.board.Width = pthis->Board.Width; vxemap.board.Height = pthis->Board.Height;
	}
	/*提取边界点*/
	/*fxmin = pthis->Board.Left;	fxmax = pthis->Board.Width;		
	fymin = pthis->Board.Top;  fymax = pthis->Board.Height;*/	/*2005 - 10-10 by yb*/
	fxmin = vxemap.board.Left;	fxmax = vxemap.board.Width;		
	fymin = vxemap.board.Top;  fymax = vxemap.board.Height;
	/*fxwidth = pthis->Board.Width; fyheight = pthis->Board.Height;*/	/*2005 - 10-10 by yb*/
	okx = vxemap.MapWidth/ (fxmax - fxmin); oky = vxemap.MapHeight/(fymax - fymin);
	if(okx < oky)
		oky = okx;
	else  okx = oky;
	/*printf("to xianxin\n");*/
	if((pthis->IsDisplay)||(vxemap.manyou)) /*11-2 add to vxemap.manyou*/
	{
		switch(pthis->ShapeType)
		{
			case 3:			/*当图形为线型时*/
				headRecord = pthis->firstRecord;
				pRecord = headRecord;
				if(headRecord != NULL)
				do						/*图层纪录循环*/
				{
					
					headPart = pRecord->firstParts;
					pPart = headPart;
					if(pRecord->NumParts > 1)
					{
					if(headPart !=NULL)
					{
						/*partIdex = (long *)malloc(sizeof(long) * pRecord->NumParts);*/
						do
						{
							partIdex[idx] = pPart->PartsIdx;
							idx++;
							pPart = pPart ->NextParts;
						}while(pPart !=NULL);					
					}
					}
					headPoint = pRecord->firstPoints;
					pPoint = headPoint;
					if(headPoint != NULL)
					do
					{
 						if(pRecord->NumParts > 1)
 						{
						for(ii =1; ii< pRecord->NumParts ; ii++)
						{
							if(pdx == partIdex[ii])
								pPoint = pPoint->NextPoint;
						}
						}
						if(!vxemap.manyou)
						{
						tmpx1 = (int)(zoom *((pPoint->x - fxmin) * okx));	
						tmpy1 = (int)(zoom*((fymax - pPoint->y)*oky));
						/*tmpx2 = zoom *((pPoint->NextPoint->x -fxmin)*okx);
						tmpy2 = zoom *((fymax - pPoint->NextPoint->y)*oky);*/
						}
						else
						{
						tmpx1 =(int)(zoom *((pPoint->x - fxmin) * okx) + xmove);	
						tmpy1 =(int)(zoom*((fymax - pPoint->y)*oky) + ymove);
						/*tmpx2 = zoom *((pPoint->NextPoint->x -fxmin)*okx) + xmove;
			 			tmpy2 = zoom *((fymax - pPoint->NextPoint->y)*oky) + ymove;*/
						}
						#ifdef emap_Mdl_Debug
						printf("x1: %d, y1: %d, x2: %d, y2:%d\n",tmpx1,tmpy1, tmpx2, tmpy2);
						#endif
						/*added  by yyb 04-11-3, modfied by yb 11-10*/
						
						/*if( !((tmpx1 == tmpx2) && (tmpy1 == tmpy2))){*/
							pp[jj].x = tmpx1; 
							pp[jj].y = tmpy1;
						     jj++;
						/*}*/ /*2005-10-10*/
						tmpx2 = tmpx1;
						tmpy2 = tmpy1;
							/*uglLine(gc, tmpx1, tmpy1, tmpx2, tmpy2); */		/*04-10-28 and following line*/
						/*pp[jj].x = tmpx1; pp[jj].y = tmpy1;
						ploylinepnum++;jj++;*/
						pdx ++; 
						
						/*if(pRecord->NumParts > 1)      /*04-10-29 noted by yyb
 						{
						for(ii =1; ii< pRecord->NumParts ; ii++)
						{

⌨️ 快捷键说明

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