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

📄 set_dialog.cpp

📁 一个基于QT的电网监控程序
💻 CPP
字号:
/****************************************************************************** Form implementation generated from reading ui file 'set_dialog.ui'**** Created: Fri Dec 22 19:29:55 2006**      by:  The User Interface Compiler (uic)**** WARNING! All changes made in this file will be lost!****************************************************************************/#include "set_dialog.h"#include <qbuttongroup.h>#include <qpushbutton.h>#include <qradiobutton.h>#include <qlayout.h>#include <qvariant.h>#include <qtooltip.h>#include <qwhatsthis.h>#include <qframe.h>#include <math.h>#include <string.h>#include <sys/ioctl.h>#include <sys/time.h>#include <unistd.h>#include <fcntl.h>#include <stdlib.h>#include <stdio.h>/*  *  Constructs a MyDialog which is a child of 'parent', with the  *  name 'name' and widget flags set to 'f'  * *  The dialog will by default be modeless, unless you set 'modal' to *  TRUE to construct a modal dialog. */MyDialog::MyDialog( QWidget* parent,  const char* name, bool modal, WFlags fl )    : QDialog( parent, name, modal, fl ){	factor_stat=NONE;	dialog_stat=STOP;	dialog_fd=0;	    	if ( !name )		setName( "MyDialog" );    	resize( 640, 480 );     	setMinimumSize( QSize( 640, 480 ) );    	setMaximumSize( QSize( 640, 480 ) );    	QFont f( font() );    	f.setFamily( "adobe-courier" );    	f.setPointSize( 16 );    	setFont( f );     	setCaption( tr( "Setting" ) );    	setSizeGripEnabled( TRUE );    	PushButton2 = new QPushButton( this, "PushButton2" );    	PushButton2->setGeometry( QRect( 230, 420, 185, 40 ) );     	PushButton2->setText( tr( "Save" ) );    	PushButton1 = new QPushButton( this, "PushButton1" );    	PushButton1->setGeometry( QRect( 25, 420, 185, 40 ) );     	PushButton1->setText( tr( "Apply" ) );    	PushButton3 = new QPushButton( this, "PushButton3" );    	PushButton3->setGeometry( QRect( 435, 420, 185, 40 ) );     	PushButton3->setText( tr( "Cancel" ) );	    	ButtonGroup1 = new QButtonGroup( this, "ButtonGroup1" );    	ButtonGroup1->setGeometry( QRect( 15, 15, 180, 396 ) );     	ButtonGroup1->setTitle( tr( "Factor Setting" ) );    	RadioButton6 = new QRadioButton( ButtonGroup1, "RadioButton6" );    	RadioButton6->setGeometry( QRect( 30, 335, 110, 25 ) );     	RadioButton6->setText( tr( "PhaseC_V" ) );    	RadioButton5 = new QRadioButton( ButtonGroup1, "RadioButton5" );    	RadioButton5->setGeometry( QRect( 30, 275, 110, 25 ) );     	RadioButton5->setText( tr( "PhaseC_A" ) );    	RadioButton4 = new QRadioButton( ButtonGroup1, "RadioButton4" );    	RadioButton4->setGeometry( QRect( 30, 215, 110, 25 ) );     	RadioButton4->setText( tr( "PhaseB_V" ) );    	RadioButton3 = new QRadioButton( ButtonGroup1, "RadioButton3" );    	RadioButton3->setGeometry( QRect( 30, 155, 110, 25 ) );     	RadioButton3->setText( tr( "PhaseB_A" ) );    	RadioButton2 = new QRadioButton( ButtonGroup1, "RadioButton2" );    	RadioButton2->setGeometry( QRect( 30, 95, 110, 25 ) );     	RadioButton2->setText( tr( "PhaseA_V" ) );    	RadioButton1 = new QRadioButton( ButtonGroup1, "RadioButton1" );    	RadioButton1->setGeometry( QRect( 30, 35, 110, 25 ) );     	RadioButton1->setText( tr( "PhaseA_A" ) );        	ButtonGroup1->insert(RadioButton1);    	ButtonGroup1->insert(RadioButton2);    	ButtonGroup1->insert(RadioButton3);    	ButtonGroup1->insert(RadioButton4);    	ButtonGroup1->insert(RadioButton5);    	ButtonGroup1->insert(RadioButton6);        	PhaseA_A_Factor=new Factor(this,"factor1");    	PhaseA_A_Factor->setFrameShape( QFrame::NoFrame );	PhaseA_A_Factor->setGeometry( QRect( 201, 15, 425, 300 ) );	PhaseA_A_Factor->SetTitle("PhaseA Current Factor");	PhaseA_A_Factor->hide();	PhaseA_V_Factor=new Factor(this,"factor2");    	PhaseA_V_Factor->setFrameShape( QFrame::NoFrame );	PhaseA_V_Factor->setGeometry( QRect( 201, 15, 425, 300 ) );	PhaseA_V_Factor->SetTitle("PhaseA Voltage Factor");		PhaseA_V_Factor->hide();	    	PhaseB_A_Factor=new Factor(this,"factor3");    	PhaseB_A_Factor->setFrameShape( QFrame::NoFrame );	PhaseB_A_Factor->setGeometry( QRect( 201, 15, 425, 300 ) );	PhaseB_A_Factor->SetTitle("PhaseB Current Factor");		PhaseB_A_Factor->hide();	PhaseB_V_Factor=new Factor(this,"factor4");    	PhaseB_V_Factor->setFrameShape( QFrame::NoFrame );	PhaseB_V_Factor->setGeometry( QRect( 201, 15, 425, 300 ) );	PhaseB_V_Factor->SetTitle("PhaseB Voltage Factor");		PhaseB_V_Factor->hide();		    	PhaseC_A_Factor=new Factor(this,"factor5");    	PhaseC_A_Factor->setFrameShape( QFrame::NoFrame );	PhaseC_A_Factor->setGeometry( QRect( 201, 15, 425, 300 ) );	PhaseC_A_Factor->SetTitle("PhaseC Current Factor");		PhaseC_A_Factor->hide();	PhaseC_V_Factor=new Factor(this,"factor6");    	PhaseC_V_Factor->setFrameShape( QFrame::NoFrame );	PhaseC_V_Factor->setGeometry( QRect( 201, 15, 425, 300 ) );	PhaseC_V_Factor->SetTitle("PhaseC Voltage Factor");		PhaseC_V_Factor->hide();		dialog_timer = new QTimer(this);		//新建系统定时器    // signals and slots connections    	connect( PushButton3, SIGNAL( clicked() ), this, SLOT( close() ) );    	connect( PushButton1, SIGNAL( clicked() ), this, SLOT( accept() ) );    	connect( ButtonGroup1, SIGNAL( clicked(int) ), this, SLOT( radiobutton(int) ) );	connect( dialog_timer, SIGNAL(timeout()), this,SLOT(dialog_flush()) );		dialog_timer->stop();}/*   *  Destroys the object and frees any allocated resources */MyDialog::~MyDialog(){    // no need to delete child widgets, Qt does it all for us}void MyDialog::radiobutton(int){	dialog_timer->stop();	dialog_stat=STOP;		switch(factor_stat){		case NONE:		 	break;		case PHASE_A_A:			PhaseA_A_Factor->hide();			break;		case PHASE_A_V:			PhaseA_V_Factor->hide();			break;		case PHASE_B_A:			PhaseB_A_Factor->hide();			break;		case PHASE_B_V:			PhaseB_V_Factor->hide();			break;		case PHASE_C_A:			PhaseC_A_Factor->hide();			break;		case PHASE_C_V:			PhaseC_V_Factor->hide();			break;		default:			break;	}	if(RadioButton1->isChecked()){	 qDebug("RadioButton1 is checked");	 factor_stat=PHASE_A_A;	 ioctl(dialog_fd,0,0);		//set sample channel Ia	 ioctl(dialog_fd,1,1);		//set singnal sample model	 PhaseA_A_Factor->show();	}else if(RadioButton2->isChecked()){	 qDebug("RadioButton2 is checked");	 ioctl(dialog_fd,1,0);		//set sample channel Ua	 ioctl(dialog_fd,1,1);		//set singnal sample model	 	 factor_stat=PHASE_A_V;	 PhaseA_V_Factor->show();	}else if(RadioButton3->isChecked()){	 qDebug("RadioButton3 is checked");	 factor_stat=PHASE_B_A;	 ioctl(dialog_fd,2,0);		//set sample channel Ib	 ioctl(dialog_fd,1,1);		//set singnal sample model	 	 PhaseB_A_Factor->show();	}else if(RadioButton4->isChecked()){	 qDebug("RadioButton4 is checked");	 factor_stat=PHASE_B_V;	 ioctl(dialog_fd,3,0);		//set sample channel Ub	 ioctl(dialog_fd,1,1);		//set singnal sample model		 PhaseB_V_Factor->show();	}else if(RadioButton5->isChecked()){	 qDebug("RadioButton5 is checked");	 factor_stat=PHASE_C_A;	 ioctl(dialog_fd,4,0);		//set sample channel Ic	 ioctl(dialog_fd,1,1);		//set singnal sample model		 PhaseC_A_Factor->show();	}else if(RadioButton6->isChecked()){	 qDebug("RadioButton6 is checked");	 factor_stat=PHASE_C_V;	 ioctl(dialog_fd,5,0);		//set sample channel Uc	 ioctl(dialog_fd,1,1);		//set singnal sample model	 PhaseC_V_Factor->show();	}	dialog_timer->start(1000);	dialog_stat=START;}/*设置对话框刷新*/void MyDialog::dialog_flush(){	int i;	double factor,tmp;	struct timeval time_start_tmp,time_stop_tmp;	//	qDebug("dialog timer");	if(dialog_stat==STOP || factor_stat==NONE)	 return;#if 0		for(i=0;i<64;i++){    	 conf[i]=Sample(i);   	}#endif	switch(factor_stat){		case NONE:			break;		case PHASE_A_A:			ioctl(dialog_fd,0,0);		//set sample channel Ia	 		ioctl(dialog_fd,1,1);		//set singnal sample model			break;		case PHASE_A_V:	 		ioctl(dialog_fd,1,0);		//set sample channel Ua	 		ioctl(dialog_fd,1,1);		//set singnal sample model						break;		case PHASE_B_A:	 		ioctl(dialog_fd,2,0);		//set sample channel Ib	 		ioctl(dialog_fd,1,1);		//set singnal sample model					break;		case PHASE_B_V:	 		ioctl(dialog_fd,3,0);		//set sample channel Ub	 		ioctl(dialog_fd,1,1);		//set singnal sample model					break;		case PHASE_C_A:			ioctl(dialog_fd,4,0);		//set sample channel Ic	 		ioctl(dialog_fd,1,1);		//set singnal sample model					break;		case PHASE_C_V:			ioctl(dialog_fd,5,0);		//set sample channel Uc	 		ioctl(dialog_fd,1,1);		//set singnal sample model			break;		default:			break;		}		gettimeofday(&time_start_tmp,(struct timezone *)0);	while(1){	 if(read(dialog_fd,AD_tmp,130)==130){	  break;	 }else{	  gettimeofday(&time_stop_tmp,(struct timezone *)0);	  tmp=time_stop_tmp.tv_usec-time_start_tmp.tv_usec;	  if(tmp>=100000){					//exit if time out	  qWarning("Warning Sample timeout");	  goto exit;	  }	 }	}	//	conf=&AD_tmp[1];	for(i=1;i<65;i++){	 switch(factor_stat){	 	case PHASE_A_A:			conf[i-1]=(double)(AD_tmp[i]-1935/*直流分量*/);			break;		case PHASE_A_V:			conf[i-1]=(double)(AD_tmp[i]-1942/*直流分量*/);			break;	 	case PHASE_B_A:			conf[i-1]=(double)(AD_tmp[i]-1910/*直流分量*/);			break;		case PHASE_B_V:			conf[i-1]=(double)(AD_tmp[i]-1911/*直流分量*/);			break;	 	case PHASE_C_A:			conf[i-1]=(double)(AD_tmp[i]-1931/*直流分量*/);			break;		case PHASE_C_V:			conf[i-1]=(double)(AD_tmp[i]-1932/*直流分量*/);			break;		default:			break;	 }	}  	FFT(conf,64,ArrayFFT,64);		//FFT conversion		tmp=(ArrayFFT[1].R)*(ArrayFFT[1].R)+(ArrayFFT[1].I)*(ArrayFFT[1].I);   	tmp=sqrt(tmp);		switch(factor_stat){		case NONE:		 	break;		case PHASE_A_A:			i=PhaseA_A_Factor->GetCurrentValue();			factor=(double)0.0000001*i;			tmp*=factor;			PhaseA_A_Factor->setLcdNumber1(tmp);			break;		case PHASE_A_V:			i=PhaseA_V_Factor->GetCurrentValue();			factor=(double)0.00001*i;			tmp*=factor;			PhaseA_V_Factor->setLcdNumber1(tmp);			break;		case PHASE_B_A:			i=PhaseB_A_Factor->GetCurrentValue();			factor=(double)0.0000001*i;			tmp*=factor;			PhaseB_A_Factor->setLcdNumber1(tmp);			break;		case PHASE_B_V:			i=PhaseB_V_Factor->GetCurrentValue();			factor=(double)0.00001*i;			tmp*=factor;			PhaseB_V_Factor->setLcdNumber1(tmp);			break;		case PHASE_C_A:			i=PhaseC_A_Factor->GetCurrentValue();			factor=(double)0.0000001*i;			tmp*=factor;			PhaseC_A_Factor->setLcdNumber1(tmp);			break;		case PHASE_C_V:			i=PhaseC_V_Factor->GetCurrentValue();			factor=(double)0.00001*i;			tmp*=factor;			PhaseC_V_Factor->setLcdNumber1(tmp);			break;		default:			break;	}	qDebug("tmp=%.4f",tmp);	exit:	return;}void MyDialog::start_timer(){	if(dialog_stat==START){	 dialog_timer->start(1000);	}}void MyDialog::stop_timer(){	if(dialog_stat==START){	 dialog_timer->stop();	}}void MyDialog::set_factors(int old_PhaseA_A,int old_PhaseA_V, \			int old_PhaseB_A,int old_PhaseB_V, \			int old_PhaseC_A,int old_PhaseC_V ){	PhaseA_A_Factor->SetCurrentValue(old_PhaseA_A);	PhaseA_V_Factor->SetCurrentValue(old_PhaseA_V);	PhaseB_A_Factor->SetCurrentValue(old_PhaseB_A);	PhaseB_V_Factor->SetCurrentValue(old_PhaseB_V);	PhaseC_A_Factor->SetCurrentValue(old_PhaseC_A);	PhaseC_V_Factor->SetCurrentValue(old_PhaseC_V);}void MyDialog::get_factors(int* new_PhaseA_A,int* new_PhaseA_V, \			int* new_PhaseB_A,int* new_PhaseB_V, \			int* new_PhaseC_A,int* new_PhaseC_V){	*new_PhaseA_A=PhaseA_A_Factor->GetCurrentValue();	*new_PhaseA_V=PhaseA_V_Factor->GetCurrentValue();	*new_PhaseB_A=PhaseB_A_Factor->GetCurrentValue();	*new_PhaseB_V=PhaseB_V_Factor->GetCurrentValue();	*new_PhaseC_A=PhaseC_A_Factor->GetCurrentValue();	*new_PhaseC_V=PhaseC_V_Factor->GetCurrentValue();}Real MyDialog::Sample(int i){	Real tmp;		tmp=34.987+380*sin(i*COF1)+sin(3*i*COF1)+sin(5*i*COF1)+sin(11*i*COF1)+50.542*sin(31*i*COF1);   	return tmp;}void MyDialog::set_dialog_fd(int fd){	dialog_fd=fd;}

⌨️ 快捷键说明

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