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

📄 disphistory.c

📁 采用MINIGUI开发的一套GUI界面
💻 C
📖 第 1 页 / 共 3 页
字号:
		if(last_t>=lasttime)
			{   //(first_t>=firsttime)(last_t>=lasttime)
			//查询的数据后一部分在本索引段内
			data_length=3*((lasttime-first_t)/interval);  //数据长度
			fseek(fd,data_firstaddr,SEEK_SET); 	
			fread(buf2+length,1,data_length,fd);  //data_length最大640个点*30个数据
			length=length+data_length;
//			 printf("flag 1index=%d\n",index);
			validindex++;
		  channel_hist[id].record[validindex-1].first=first_t;
			channel_hist[id].record[validindex-1].last=lasttime;
			channel_hist[id].record[validindex-1].interval=interval;
			channel_hist[id].record[validindex-1].number=data_length/3;
			 index=totalindex+1;//跳出FOR 循环
			}
	 	else  
			{//(first_t>=firsttime)(last_t<lasttime)
			//查询的数据包含了本索引段内所有数据
			data_length=3*number;
			fseek(fd,data_firstaddr,SEEK_SET); 	
			fread(buf2+length,1,data_length,fd); 
			length=length+data_length;	//保存BUF2的下一个数据位置
 			printf("flag 2...\n");
 			 	validindex++;
		  	channel_hist[id].record[validindex-1].first=first_t;
			channel_hist[id].record[validindex-1].last=last_t;
			channel_hist[id].record[validindex-1].interval=interval;
			channel_hist[id].record[validindex-1].number=data_length/3;
			}

		}
		else//(first_t<firsttime)
		{
		if(last_t>=lasttime)
			{//(last_t<lasttime)(last_t>=lasttime)
			//查询的数据全部在本索引段内
			data_length=3*((lasttime-firsttime)/interval);  //数据长度
			data_firstaddr=data_firstaddr+3*((firsttime-first_t)/interval);
			fseek(fd,data_firstaddr,SEEK_SET); 	
			fread(buf2+length,1,data_length,fd);  //data_length最大640个点*30个数据
			if(data_length<0)data_length=0;
			length=length+data_length;
		
//			 printf("flag 3 validindex=%d\n",validindex);
			 	validindex++;
		  channel_hist[id].record[validindex-1].first=firsttime;
			channel_hist[id].record[validindex-1].last=lasttime;
			channel_hist[id].record[validindex-1].interval=interval;
			channel_hist[id].record[validindex-1].number=data_length/3;
			 index=totalindex+1;//跳出FOR 循环
			}
		else   
			{
			if(last_t>=firsttime)
				{//(first_t<=firsttime)(last_t>=firsttime)
			//查询的数据前一部分在本索引段内
			data_length=3*((last_t-firsttime)/interval);
			data_firstaddr=data_firstaddr+3*((firsttime-first_t)/interval);
			fseek(fd,data_firstaddr,SEEK_SET); 	
			fread(buf2+length,1,data_length,fd); 
			length=length+data_length;	//保存BUF2的下一个数据位置
//			printf("data_length=%d flag 4...\n",data_length);
			
			 	validindex++;
		  channel_hist[id].record[validindex-1].first=firsttime;
			channel_hist[id].record[validindex-1].last=last_t;
			channel_hist[id].record[validindex-1].interval=interval;
			channel_hist[id].record[validindex-1].number=data_length/3;
			}
			else  //已经超过要求查询的数据范围
				{

				printf("r.");//(first_t<=firsttime)(last_t<firsttime)
			
				}
			}

		}

		}
	
	}
channel_hist[id].index_num=validindex;
channel_hist[id].number=length/3;//保存本通道有效点个数
bzero(channel_hist[id].point,sizeof(channel_hist[id].point));
 for(i=0;i<length/3;i++)
 	{
 	memcpy(data.byte,(buf2+i*3),3);
 	data.byte[2]=0;
 	channel_hist[id].point[i]=data.ipv;
	 }
}
//数据处理

bzero(point,sizeof(point));
return 0;
}
//根据时间得到秒数
char *SecondsToTime(long seconds)
{
time_t t;
long lasttime;
  struct     tm   *time ; 
  char *strtime;
  strtime=(char*)malloc(20*sizeof(char));
  t=(time_t)seconds;
   t=1169861118;
   time=gmtime(&t);
strtime=ctime(&t);
    printf("\n hour= %d ",time->tm_year+1900);
 printf("mon= %d ",time->tm_mon+1);
  printf("day= %d ",time->tm_mday);
   printf("hour= %d ",time->tm_hour);
     printf("day= %d\n",time->tm_min);
	  
//printf(" strtime= %s",strtime);
return strtime;
}
long GetSeconds(HWND hDlg)
{
	struct timeval tv;
	struct timezone tz;
		int seco,min,hour,mday,mon,year;
		int p[6];// 控件值 返回值,1表示成功,0表示失败
    		time_t   t;   
              struct     tm   nowtime ; 
		//nowtime = localtime(&t);	  
     		seco=0;
	 	min=GetDlgItemInt(hDlg,HIST_MINU,		&p[1],0);
	 	hour=GetDlgItemInt(hDlg,HIST_HOUR,	&p[2],0);
	 	mday=GetDlgItemInt(hDlg,HIST_DATE,	&p[3],0);
	 	mon=GetDlgItemInt(hDlg,HIST_MONT,	&p[4],0);
	 	year=GetDlgItemInt(hDlg,HIST_YEAR,	&p[5],0);
             printf("xierongjian= y=%d month=%d day=%d Hour=%d  minute=%d  secon=%d \n", year,mon,mday,hour,min,seco) ;   		
	    	nowtime.tm_sec=seco;/*   Seconds.[0-60]   (1   leap   second)*/                             
             nowtime.tm_min=min;/*   Minutes.[0-59]   */                                       
              nowtime.tm_hour=hour;/*   Hours. [0-23]   */   
              nowtime.tm_mday=mday;/*   Day.[1-31]   */   
              nowtime.tm_mon=mon-1;/*   Month. [0-11]   */   
              nowtime.tm_year=year-1900   ;/*   Year+   1900.*/   
              nowtime.tm_isdst=-1   ;// -1:不关心   1:夏令时间  ,不夏令时候0
             t=mktime(&nowtime);
   return (long)t;



}
//根据鼠标位置显示历史数据点的时间值
void ShowTimeInfo(HWND hDlg,int x,int y)
{
int seconds;

//根据X获得时间秒数
if(x<80)x=80;
seconds=(x-80)*(end_sec-start_sec)/560+start_sec;

 
  // InvalidateRect(hDlg,&rectinfo,FALSE);

}

/*
得到历史曲线高度



*/

int GetHistoryCurveHeight(int id)
{
 //调整纵向坐标用
int high=0;
int low=0;
int height=0;
short ipv=0;
int total_num;
int value;
int j;
 total_num=channel_hist[id].number;
		//将channel_hist[1].point变成POINT
 high=channel_conf[id].h_limit;
 low=channel_conf[id].l_limit;
 high=400;
 low=0;

 for(j=0;j<total_num;j++)
 	{
 ipv=channel_hist[id].point[j];

if(ipv>=high) value=TOP2;      //40
else if(ipv<=low) value=HEIGHT-TOP2-TOP-BOTTOM2;  //360
else value=40+(((high-ipv)*(320))/(high-low));
 
 point[j]=value;	
  	}

return 1;
}
//得到点的X坐标
/*
入口:
interval:点之间的时间间隔
ZOOM:显示放大倍数
time:基准时间点
seco:要显示的时间点秒数
time_x:基准时间点的X坐标
返回:要显示的时间点X坐标

*/
static int GetDotX(long seco,int zoom,long time,int time_x)
{
int dot;
int t;
int total;
total=time_x;
if(seco>time)seco=time;
t=(int)(time-seco);

dot=total-zoom*t;
if(dot<0)dot=0;

return dot;
}
//根据现在的点的象素位置得到点之间的距离
int GetDistance(BOOL forward)
{
int id;
	int start; 
	int end;
	int interval;  
	int sec_num;	
	int k,i,j;
	int left;//数据点的象素位置
int distance;
int temp;
int guage_x;
guage_x=channel_hist[1].guage_x;
interval=2;

distance=histzoom*interval ;

temp=1;

if(forward)   
	{
	guage_x=guage_x+distance;
	if(guage_x>560)guage_x=histzoom;
	hist_dot_seco=hist_dot_seco+interval;
	printf("hist_dot_seco= %d \n",hist_dot_seco);
	}
else
	{

	guage_x=guage_x-distance;
   	if(guage_x<histzoom)guage_x=560;
	hist_dot_seco=hist_dot_seco-interval;
//	printf("hist_dot_seco= %d \n",hist_dot_seco);	
	}
	

id=1;

 sprintf(channel_hist[1].data,"%d",0);  
   for(k=0;k<channel_hist[1].index_num;k++)
		    {
		 start=channel_hist[id].record[k].first;
		 end  =channel_hist[id].record[k].last;
		 sec_num=channel_hist[id].record[k].number;
		 interval=channel_hist[id].record[k].interval;
		 //判断索引段时间是否有在显示区时间
/*
printf("index= %d \n",k+1);
printf("start= %d   ",start);
printf("end= %d \n",end);
printf("s_sec= %d   ",start_sec);
printf("e_sec= %d  ",end_sec);
printf("guage_x= %d \n\n",guage_x);
*/
		 if((end<=end_sec)&&(end>=start_sec))
		 	{
	
			for(j=temp;j<temp+sec_num;j++)
				{
			left=GetDotX((start+(j-1)*interval),  histzoom, end_sec, 560);


			if(abs(guage_x-left)<histzoom*interval)
				{
				 guage_x=left;
				distance=histzoom*interval;	
				//得到这一点的值
				//if(left==guage_x)printf("m =%d\n",point[j]);  
			 	
				
	
				 sprintf(channel_hist[1].data,"%d",channel_hist[1].point[j-1]);  
				 j=temp+sec_num+1;
				  }
			
			 }
		  }
		temp=sec_num+1;
   	}

channel_hist[1].guage_x=guage_x;
return distance;
}

void DrawHistCurve(HDC hmemDC,int first ,int n,int x,int y,int w,int h)
{
#define INTERVAL_MAX 2;   	
int id;
	 long start;//bengin time per index
	long  end;//end time per index
	int temp;   //used when reading index data 
	int distance;//点之间的象素距离
	int interval;
	int total_num;   //区域内有效的实时点的个数
	int sec_num;	
	int k,i,j;
	char str[10];
	int left;
	int zoom;
	int dot_x;
	zoom=histzoom;
	id =1;
   //将start_sec->end_sec的时间分摊到W区域
   	start_sec=end_sec-w/histzoom;//根据放大倍数定显示区包含的时间
		      SetPenColor(hmemDC, PIXEL_lightwhite);//PIXEL_lightwhite
		      SetTextColor(hmemDC,PIXEL_lightwhite);	
	// for(id=first;id<first+n;id++){	
		 total_num=channel_hist[1].number;
		 GetHistoryCurveHeight(1);
		 temp=1;
		    for(k=0;k<channel_hist[1].index_num;k++)
		    {
		 start=channel_hist[id].record[k].first;
		 end  =channel_hist[id].record[k].last;
		 sec_num=channel_hist[id].record[k].number;
		 interval=channel_hist[id].record[k].interval;
		 //画出每个索引段
		 //起始位置
		 //判断索引段时间是否有在显示区时间
		 if((end<end_sec)&&(end_sec>start))
		 	{
		 	printf(" draw: temp=%d histzoom=%d,end_sec=%d\n",temp,histzoom,end_sec );
			printf(" start=%d\n" ,start);
			for(j=temp;j<temp+sec_num-1;j++){
				 if((end-(sec_num+1-j)*interval)>=start_sec)
				 	{
				//	 printf("start_sec=%d sec=%d\n ", start_sec, (end-(sec_num-j+1)*interval));
				dot_x=GetDotX(end-(sec_num+1-j)*interval,  histzoom, end_sec, 560);
				printf(" %d" ,dot_x);	
				  MoveTo(hmemDC, dot_x, point[j-1]);	//
			        LineTo(hmemDC,dot_x+zoom*interval, point[j] );
				 	}
				}  
			printf(" \n" );
			
		 	}
		 temp=sec_num+1;
		}
}
/*绘制历史曲线背景
 x:绘图区x坐标
y:绘图区y坐标
w:
h:

zoom:放大倍数
 */
  
void DrawHistoryline (HDC hmemDC,int first ,int n,int x,int y,int w,int h)//,PandectDataStruct *channel_disp)
{
       int j,i;
	int k;
	int channum;
	int rect_x,rect_y, rect_w,rect_h;
	gal_pixel colorl_text;
	int guage_x;
	int zoom;
	char str[10];
	k=1;
	zoom=histzoom;
	zoom=14;//表示有10格
	guage_x=channel_hist[1].guage_x;
	//绘制数值显示区------------------------------------
	//for(i=first;i<first+n;i++){
for(i=0;i<6;i++){		
		if(i<n/2){
				rect_w=w/(n/2);
				rect_x=rect_w*(i-first);   //一个矩形的宽度为60      
				rect_y=0; //单页上设置坐标
			}
			else				
				{
				rect_w=w/(n-n/2);
				rect_x= rect_w*(i-n/2-first);   //一个矩形的宽度为60      
				rect_y=h-BOTTOM2; //单页上设置坐标
			}
			Rectangle(hmemDC, rect_x, rect_y,rect_x+rect_w,rect_y+BOTTOM2);   	   
			SetBrushColor(hmemDC,RGB2Pixel(hmemDC,i*30,128,abs(8-i)*64)); //channel_disp[i].color
			FillBox(hmemDC, rect_x+1, rect_y+1, rect_w-1, BOTTOM2-1); 
			 SelectFont(hmemDC,lgfont_11); //设置字体
			TextOut(hmemDC,rect_x+1+rect_w/3,rect_y+BOTTOM2/3,channel_hist[i].data);
 			SelectFont(hmemDC,songgb16font); //设置字体
			TextOut(hmemDC,rect_x,rect_y,channel_hist[i].name);//channel_disp[i].tagname
 			SelectFont(hmemDC,lgfontgb12); //设置字体
       		TextOut(hmemDC,rect_x+1+rect_w-30,rect_y+BOTTOM2-20,channel_hist[i].unit);
	}

	//绘制背景------------------------------------
       SetPenColor (hmemDC,COLOR_darkgray);//COLOR_darkgray  PIXEL_lightwhite
      h=h-TOP2-BOTTOM2;
        for(k=1;k<=w/(zoom*4);k++)//列
           {   
            MoveTo(hmemDC,k*(zoom*4),TOP2);//w+(j-index)*zoom
             LineTo(hmemDC,k*(zoom*4),360);   

	      //绘制完本条竖线后绘制对应的时刻
	      sprintf(str," %02d:%02d:%02d",hour,minu,seco);
    		SelectFont(hmemDC,helfont14);
  	       SetBkMode(hmemDC,BM_TRANSPARENT);
 	        SetTextColor(hmemDC,COLOR_darkgray);
  	       TextOut(hmemDC,k*(zoom*4),340,str); 
	 

			 
        }	
        for(j=1;j<=h/(zoom*3);j++)
        {	    
        	MoveTo(hmemDC,0,TOP2+zoom*3*j);
          	LineTo(hmemDC,WIDTH-LEFT,TOP2+zoom*3*j);
        }  	 
	//时间坐标
  	//start_sec

⌨️ 快捷键说明

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