# include "CMainWin.h"
# include <QDateTime>
# include "lpSysLog.h"
# include "IStation.h"
# include <QMessageBox>
# include <QCloseEvent>
# include "WfCtrl.h"
# include <QLibrary>
# include "quserinfo_global.h"
# include "Serialport_global.h"
# include <QProcess>
# include "lpSysConfig.h"
# define LEAPER_LOGO ": / leaper / Resource / app.png"
# define DELETE_POINTER(p) if (p) {delete p; p = NULL;}
# pragma execution_character_set("utf-8")
CMainWin : : CMainWin ( QWidget * parent )
: QMainWindow ( parent )
{
setWindowIcon ( QIcon ( " :/leaper/Resource/app.png " ) ) ;
onInitCoreCtrl ( ) ;
ui . setupUi ( this ) ;
lpSysLog : : instance ( ) - > Init ( ) ;
lpSysConfig : : instance ( ) - > readConfig ( ) ;
lpSysConfig : : instance ( ) - > writeConfig ( ) ;
SetLanguage ( m_strCurLanguage ) ;
SYSLOG_STATUS < < " ϵͳ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ;
{
QString strPath = QCoreApplication : : applicationDirPath ( ) ;
QString DBFilePath = strPath + " \\ DBFiles " ;
QDir dbDir ;
dbDir . mkpath ( DBFilePath ) ;
m_db = new StationDB ( DBFilePath + " \\ AntMan.db " ) ;
m_db - > InitDatabase ( ) ;
}
m_pCameraTrig = new AutoTrigger ;
connect ( m_pCameraTrig , SIGNAL ( sgTrig ( ) ) , this , SLOT ( onTrigImage ( ) ) ) ;
onInitStatus ( ) ;
connect ( m_pDesignerMgr , SIGNAL ( sgCloseWindow ( ) ) , this , SLOT ( onMainFrameClose ( ) ) ) ;
connect ( & m_testWid , SIGNAL ( sgTestMode ( int ) ) , this , SLOT ( onTestMode ( int ) ) ) ;
m_pColossus = new WfColossus ( m_pDetectorEngine ) ;
m_pWfCtrl = new CWfCtrl ( m_pCoreCtrl , m_pColossus ) ;
QStringList strList = m_pWfCtrl - > IGetStationKeys ( ) ;
foreach ( QString str , strList ) {
IStation * pS = m_pWfCtrl - > IGetStationByKey ( str ) ;
connect ( pS , SIGNAL ( sgShowModeName ( int , QString ) ) , this , SLOT ( onShowName ( int , QString ) ) ) ;
}
m_pWfCtrl - > onInit ( ) ;
m_mangeWid . onInitModelList ( m_pWfCtrl ) ;
{ //<2F> û<EFBFBD> <C3BB> <EFBFBD> <EFBFBD> <EFBFBD> ģ<EFBFBD> <C4A3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
# ifdef _DEBUG
QLibrary lib ( " QUserInfod " ) ;
# else
QLibrary lib ( " QUserInfo " ) ;
# endif
_UserCtrlCreate func = ( _UserCtrlCreate ) lib . resolve ( " UserCtrlCreate " ) ;
if ( func ) {
m_pUserCtrl = func ( ) ;
connect ( m_pUserCtrl , SIGNAL ( sgCurrentUserInfo ( QString , int , int ) ) , this , SLOT ( onLogInOut ( QString , int , int ) ) ) ;
}
}
{ //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> 豸<EFBFBD> <E8B1B8> <EFBFBD> <EFBFBD>
# ifdef _DEBUG
QLibrary lib ( " SerialPortToold " ) ; //<2F> <> <EFBFBD> ļ<EFBFBD> <C4BC> <EFBFBD>
# else
QLibrary lib ( " SerialPortTool " ) ; //<2F> <> <EFBFBD> ļ<EFBFBD> <C4BC> <EFBFBD>
# endif
_SerialPortCreate func = ( _SerialPortCreate ) lib . resolve ( " SerialPortCreate " ) ;
if ( func )
m_pSerialPort = func ( ) ;
//load seriport dll
if ( m_pSerialPort ) //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ļ<EFBFBD> <C4BC> <EFBFBD> <EFBFBD> <EFBFBD> ʹ <> <CAB9> <EFBFBD> Զ<EFBFBD> <D4B6> <EFBFBD> <EFBFBD> Ĵ<EFBFBD> <C4B4> <EFBFBD>
{
m_pSerialPort - > loadAnalysefunc ( this , & CMainWin : : onAppanalysis ) ;
//<2F> رտ<D8B1> <D5BF> ܵĴ<DCB5> <C4B4> <EFBFBD> ʹ <EFBFBD> <CAB9>
QString strDefaultPort = lpSysConfig : : instance ( ) - > m_ComName ;
int baut = lpSysConfig : : instance ( ) - > m_Baut ;
bool bOpen = m_pSerialPort - > OpenCom ( strDefaultPort , QString : : number ( baut ) ) ;
if ( bOpen = = false )
{
QMessageBox infobox ( QMessageBox : : Information , QString ( QObject : : tr ( " <EFBFBD> <EFBFBD> ʾ " ) ) , QString ( " Com %1 %2 open failed " ) . arg ( strDefaultPort ) . arg ( baut ) , QMessageBox : : Yes | QMessageBox : : No , NULL ) ;
infobox . setWindowIcon ( QIcon ( LEAPER_LOGO ) ) ;
infobox . exec ( ) ;
}
connect ( & m_HeartBit , SIGNAL ( timeout ( ) ) , this , SLOT ( onHeardBit ( ) ) ) ;
m_HeartBit . start ( 300 ) ;
}
}
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ť<EFBFBD> ¼<EFBFBD> <C2BC> <EFBFBD> <EFBFBD> <EFBFBD>
connect ( ui . actionSetting , SIGNAL ( triggered ( ) ) , this , SLOT ( onActionClicked ( ) ) ) ;
connect ( ui . actionManage , SIGNAL ( triggered ( ) ) , this , SLOT ( onActionClicked ( ) ) ) ;
connect ( ui . actionTest , SIGNAL ( triggered ( ) ) , this , SLOT ( onActionClicked ( ) ) ) ;
connect ( ui . actionHelp , SIGNAL ( triggered ( ) ) , this , SLOT ( onActionClicked ( ) ) ) ;
connect ( ui . action_Check , SIGNAL ( triggered ( ) ) , this , SLOT ( onActionClicked ( ) ) ) ;
connect ( ui . action , SIGNAL ( triggered ( ) ) , this , SLOT ( onActionClicked ( ) ) ) ;
connect ( ui . main_Login_action , SIGNAL ( triggered ( ) ) , this , SLOT ( onActionClicked ( ) ) ) ;
connect ( ui . main_action_userManager , SIGNAL ( triggered ( ) ) , this , SLOT ( onActionClicked ( ) ) ) ;
//ͼ<> <CDBC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> չʾ
connect ( this , SIGNAL ( sgShowImg ( int , QImage ) ) , this , SLOT ( onShowImage ( int , QImage ) ) ) ;
connect ( this , SIGNAL ( sgSelModel ( int , QString ) ) , this , SLOT ( onSelModel ( int , QString ) ) ) ;
connect ( this , SIGNAL ( sgShowLog ( int , QString ) ) , this , SLOT ( onShowLog ( int , QString ) ) ) ;
m_TimerID_Status = startTimer ( 1000 ) ;
ui . main_action_userManager - > setVisible ( false ) ;
//ui.action->setVisible(false);
QTextDocument * pDoc = ui . wf_text_edit_result_1 - > document ( ) ;
pDoc - > setMaximumBlockCount ( 200 ) ;
pDoc = ui . wf_text_edit_result_2 - > document ( ) ;
pDoc - > setMaximumBlockCount ( 200 ) ;
}
CMainWin : : ~ CMainWin ( )
{
DELETE_POINTER ( m_pCameraTrig ) ;
DELETE_POINTER ( m_pWfCtrl ) ;
DELETE_POINTER ( m_pColossus ) ;
if ( m_db )
{
delete m_db ;
m_db = NULL ;
}
if ( m_pUserCtrl ) {
delete m_pUserCtrl ;
m_pUserCtrl = NULL ;
}
if ( m_pSerialPort ) {
m_HeartBit . stop ( ) ;
m_pSerialPort - > CloseCom ( ) ;
delete m_pSerialPort ;
m_pSerialPort = NULL ;
}
// if (m_pDesignerMgr)
// {
// delete m_pDesignerMgr;
// m_pDesignerMgr = nullptr;
// }
if ( m_pDllDetectorEngine )
{
delete m_pDllDetectorEngine ;
m_pDllDetectorEngine = nullptr ;
}
//load coretrl
if ( m_pDllCoreCtrl )
{
delete m_pDllCoreCtrl ;
m_pDllCoreCtrl = nullptr ;
}
lpSysConfig : : uninstance ( ) ;
rmTranslator ( ) ;
lpSysLog : : uninstance ( ) ;
}
void CMainWin : : IVariantMapToUI ( emTpUiDataType dataType , const QString & camKey , const QVariantMap & vMap )
{
qDebug ( ) < < " variant 2 ui, start " ;
if ( ! m_pWfCtrl ) {
qWarning ( ) < < " VariantMapToUI, WFctrl is null " ;
return ;
}
QVariantMap mMap = vMap . value ( " algoRlt " ) . toMap ( ) ;
IStation * pStation = m_pWfCtrl - > IGetStationByKey ( camKey ) ;
if ( pStation ) {
QImage image = vMap . value ( " image " ) . value < QImage > ( ) ;
int nSize = image . height ( ) ;
if ( ! vMap . contains ( " angle " ) ) {
qWarning ( ) < < " no angle result " ;
}
QImage srcImg = vMap . value ( " originImage " ) . value < QImage > ( ) ;
double dAngle = vMap . contains ( " angle " ) ? vMap . value ( " angle " ) . toDouble ( ) : 365 ;
int errorType = vMap . contains ( " error " ) ? vMap . value ( " error " ) . toInt ( ) : 16 ;
double matchScore = vMap . value ( " score " ) . toDouble ( ) * 100 ;
QString str = vMap . value ( " resultTip " ) . toString ( ) ;
QStringList strList = str . split ( " / " ) ;
QString strRusltTip = strList . first ( ) ;
QString threshBenchMark = strList . last ( ) ;
//QString strImgPath = vMap.value("imageName").toString();
QString strResult = QTime : : currentTime ( ) . toString ( " hh:mm:ss zzz: " ) + strList . first ( ) ;
strResult + = " angle result : " + QString : : number ( dAngle , ' f ' , 3 ) ;
pStation - > setSerialPortPtr ( m_pSerialPort ) ;
if ( dAngle > = 361 )
dAngle = 361.0 ;
pStation - > sendResult ( dAngle ) ;
if ( image . isNull ( ) )
int b = 0 ;
SYSLOG_STATUS < < QString ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> λ%1<> յ<EFBFBD> <D5B5> 㷨<EFBFBD> <E3B7A8> <EFBFBD> <EFBFBD> ,<2C> <> ǰ<EFBFBD> ͺ <EFBFBD> Ϊ[%2],<2C> <> <EFBFBD> ͽǶ<CDBD> Ϊ:%3" ) . arg ( pStation - > stationId ( ) ) . arg ( pStation - > currentRunningModel ( ) ) . arg ( dAngle ) ;
emit sgShowImg ( pStation - > stationId ( ) , image ) ;
emit sgShowLog ( pStation - > stationId ( ) , strResult ) ;
pStation - > revResult ( ) ;
QString str2 = pStation - > currentRunningModel ( ) ;
int ID = pStation - > stationId ( ) ;
QString strModelName = QString ( " %1_%2 " ) . arg ( ID ) . arg ( str2 ) ;
QString strImgPath = genSavePath ( strModelName , image ) ;
if ( lpSysConfig : : instance ( ) - > m_bSaveSrcImg = = true )
genSaveSrcImgPath ( strModelName , srcImg ) ;
Struct2SaveData nStructData ;
nStructData . dAngle = dAngle ;
nStructData . errorType = errorType ;
nStructData . matchScore = matchScore ;
nStructData . threshBenchMark = threshBenchMark ;
nStructData . resultTip = strRusltTip ;
nStructData . stationName = pStation - > stationShowName ( ) ;
nStructData . value1 = strImgPath ;
nStructData . value2 = str2 ;
qWarning ( ) < < " Add Result to DB,cam= " < < camKey ;
m_db - > addData2DB ( nStructData ) ;
}
// else {
// qWarning() << "can not find station key=" << camKey;
// qWarning() << "framework, camera kyes:" << m_pCoreCtrl->ICameraKeys();
// qWarning() << "wf ctrl, camera kyes:" << m_pWfCtrl->IGetStationKeys();
// }
}
QVariant CMainWin : : IGetVariantById ( int id )
{
IStation * pStation = m_pWfCtrl - > IGetStationById ( id ) ;
if ( pStation ) {
return pStation - > getVariant ( ) ;
}
return QVariant ( ) ;
}
QString CMainWin : : genSaveSrcImgPath ( QString modelName , QImage & img )
{
QString strApp = QApplication : : applicationDirPath ( ) ;
QString targetPath = " /DBFiles/SrcImages " ;
QString strData = QDateTime : : currentDateTime ( ) . toString ( " yyyyMMdd " ) ;
QString strFileName = QDateTime : : currentDateTime ( ) . toString ( " yyyy_MM_dd_hhmmsszzz " ) + " .bmp " ;
targetPath = targetPath + " / " + strData + " / " + modelName ;
QDir dir ;
dir . mkpath ( strApp + targetPath ) ;
targetPath = targetPath + " / " + strFileName ;
if ( ! img . isNull ( ) ) {
QString strImg = strApp + targetPath ;
img . save ( strImg ) ;
}
return targetPath ;
}
QString CMainWin : : genSavePath ( QString modelName , QImage & img )
{
QString strApp = QApplication : : applicationDirPath ( ) ;
QString targetPath = " /DBFiles/Images " ;
QString strData = QDateTime : : currentDateTime ( ) . toString ( " yyyyMMdd " ) ;
QString strFileName = QDateTime : : currentDateTime ( ) . toString ( " yyyy_MM_dd_hhmmsszzz " ) + " .jpg " ;
targetPath = targetPath + " / " + strData + " / " + modelName ;
QDir dir ;
dir . mkpath ( strApp + targetPath ) ;
targetPath = targetPath + " / " + strFileName ;
if ( ! img . isNull ( ) ) {
QString strImg = strApp + targetPath ;
img . save ( strImg , " jpg " , 5 ) ;
}
return targetPath ;
}
Q_SLOT void CMainWin : : onAppanalysis ( SComFrame frame )
{
//<2F> <> <EFBFBD> ݽ<EFBFBD> <DDBD> <EFBFBD>
int nCmd = frame . cmd ;
if ( 0x43 = = nCmd )
{
onHeartComm ( frame ) ;
return ;
}
else if ( 0x50 = = nCmd ) {
int nCameraID = - 1 ;
if ( 5 = = frame . data1 ) {
nCameraID = 1 ;
}
else if ( 6 = = frame . data1 ) {
nCameraID = 2 ;
}
if ( ! m_pWfCtrl ) {
qDebug ( ) < < " CommAchieved m_pWfCtrl is null " ;
return ;
}
IStation * pStation = m_pWfCtrl - > IGetStationById ( nCameraID ) ;
if ( ! pStation ) {
return ;
}
if ( m_pWfCtrl - > IOnlineMode ( ) = = true )
{
if ( nCameraID = = 1 )
{
if ( m_StationInfo_1 . m_bRunEnable = = true )
{
pStation - > trigImage ( ) ;
}
else {
QString strMsg = QString ( " %1:<3A> <> <EFBFBD> ͺ <EFBFBD> ID:%2<> <32> ģ<EFBFBD> Ϳ <EFBFBD> <CDBF> в<EFBFBD> <D0B2> <EFBFBD> <EFBFBD> ڣ<EFBFBD> <DAA3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> գ <EFBFBD> <D5A3> <EFBFBD> <EFBFBD> <EFBFBD> " ) . arg ( QTime : : currentTime ( ) . toString ( " hh:mm:ss zzz: " ) ) . arg ( m_StationInfo_1 . m_PLCID ) ;
emit sgShowLog ( 1 , strMsg ) ;
if ( m_StationInfo_1 . m_PLCID > 0 ) {
pStation - > setSerialPortPtr ( m_pSerialPort ) ;
pStation - > sendResult ( 999 ) ;
SYSLOG_STATUS < < QString ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> λ%1:<3A> յ<EFBFBD> <D5B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ź<EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϸ<EFBFBD> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> û<EFBFBD> <C3BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 999<39> Ƕ<EFBFBD> <C7B6> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> ͺ <EFBFBD> Ϊ[%2],<2C> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> IDΪ[%3],ʱ<> <CAB1> :%4" )
. arg ( nCameraID )
. arg ( m_StationInfo_1 . strModelName . isEmpty ( ) = = true ? " <EFBFBD> <EFBFBD> " : m_StationInfo_1 . strModelName )
. arg ( m_StationInfo_1 . m_PLCID )
. arg ( QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss zzz " ) ) ;
}
else {
SYSLOG_STATUS < < QString ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> λ%1:<3A> յ<EFBFBD> <D5B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ź<EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϸ<EFBFBD> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> û<EFBFBD> <C3BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> ͺ <EFBFBD> Ϊ[%2],<2C> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> IDΪ[%3],ʱ<> <CAB1> :%4" )
. arg ( nCameraID )
. arg ( m_StationInfo_1 . strModelName . isEmpty ( ) = = true ? " <EFBFBD> <EFBFBD> " : m_StationInfo_1 . strModelName )
. arg ( m_StationInfo_1 . m_PLCID )
. arg ( QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss zzz " ) ) ;
}
}
}
else if ( nCameraID = = 2 )
{
if ( m_StationInfo_2 . m_bRunEnable = = true )
{
pStation - > trigImage ( ) ;
}
else
{
QString strMsg = QString ( " %1:<3A> <> <EFBFBD> ͺ <EFBFBD> ID:%2<> <32> ģ<EFBFBD> Ϳ <EFBFBD> <CDBF> в<EFBFBD> <D0B2> <EFBFBD> <EFBFBD> ڣ<EFBFBD> <DAA3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> գ <EFBFBD> <D5A3> <EFBFBD> <EFBFBD> <EFBFBD> " ) . arg ( QTime : : currentTime ( ) . toString ( " hh:mm:ss zzz: " ) ) . arg ( m_StationInfo_2 . m_PLCID ) ;
emit sgShowLog ( 2 , strMsg ) ;
if ( m_StationInfo_2 . m_PLCID > 0 ) {
pStation - > setSerialPortPtr ( m_pSerialPort ) ;
pStation - > sendResult ( 999 ) ;
SYSLOG_STATUS < < QString ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> λ%1:<3A> յ<EFBFBD> <D5B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ź<EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϸ<EFBFBD> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> û<EFBFBD> <C3BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 999<39> Ƕ<EFBFBD> <C7B6> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> ͺ <EFBFBD> Ϊ[%2],<2C> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> IDΪ[%3],ʱ<> <CAB1> :%4" )
. arg ( nCameraID )
. arg ( m_StationInfo_2 . strModelName . isEmpty ( ) = = true ? " <EFBFBD> <EFBFBD> " : m_StationInfo_2 . strModelName )
. arg ( m_StationInfo_2 . m_PLCID )
. arg ( QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss zzz " ) ) ;
}
else {
SYSLOG_STATUS < < QString ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> λ%1:<3A> յ<EFBFBD> <D5B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ź<EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϸ<EFBFBD> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> û<EFBFBD> <C3BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> ͺ <EFBFBD> Ϊ[%2],<2C> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> IDΪ[%3],ʱ<> <CAB1> :%4" )
. arg ( nCameraID )
. arg ( m_StationInfo_2 . strModelName . isEmpty ( ) = = true ? " <EFBFBD> <EFBFBD> " : m_StationInfo_2 . strModelName )
. arg ( m_StationInfo_2 . m_PLCID )
. arg ( QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss zzz " ) ) ;
}
}
}
}
else
pStation - > trigImage ( ) ;
}
else if ( 0xf1 = = nCmd )
{ //<2F> <> <EFBFBD> յ<EFBFBD> <D5B5> <EFBFBD> λ<EFBFBD> <CEBB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ر<EFBFBD> <D8B1> <EFBFBD> <EFBFBD> д<EFBFBD> <D0B4> <EFBFBD> <20> ػ<EFBFBD>
qApp - > closeAllWindows ( ) ;
//shutDown();
}
}
void CMainWin : : onHeartComm ( SComFrame & frame )
{
static int nS1 = - 1 ;
static int nS2 = - 1 ;
if ( m_pWfCtrl )
m_pWfCtrl - > registerConnect ( ) ;
else
return ;
if ( m_pWfCtrl - > IOnlineMode ( ) = = true )
{
int nSta1 = frame . data1 ;
int nSta2 = frame . data2 ;
if ( nS1 ! = nSta1 | | nS2 ! = nSta2 )
{
nS1 = nSta1 ;
nS2 = nSta2 ;
}
else
return ;
QStringList lstKeys = m_pWfCtrl - > IGetStationKeys ( ) ;
for each ( QString var in lstKeys )
{
IStation * pStation = m_pWfCtrl - > IGetStationByKey ( var ) ;
if ( ! pStation ) {
continue ;
}
int nId = pStation - > stationId ( ) ;
if ( nId < = 0 | | nId > 8 ) {
//error
qWarning ( ) < < " error, id is beyong " ;
continue ;
}
int mmCmd = 0 ;
if ( nId = = 1 )
mmCmd = frame . data1 ;
if ( nId = = 2 )
mmCmd = frame . data2 ;
if ( nId = = 3 )
mmCmd = frame . data3 ;
if ( nId = = 4 )
mmCmd = frame . data4 ;
if ( nId = = 5 )
mmCmd = frame . data5 ;
if ( nId = = 6 )
mmCmd = frame . data6 ;
if ( nId = = 7 )
mmCmd = frame . data7 ;
if ( nId = = 8 )
mmCmd = frame . data8 ;
QString strModel = pStation - > modelByPlcCmd ( mmCmd ) ;
if ( ! strModel . isEmpty ( ) )
{
emit ( sgSelModel ( nId , strModel ) ) ;
if ( nId = = 1 )
{
if ( m_StationInfo_1 . m_PLCID ! = mmCmd )
{
m_StationInfo_1 . m_PLCID = mmCmd ;
m_StationInfo_1 . strModelName = strModel ;
SYSLOG_STATUS < < QString ( " <EFBFBD> ﹤λ%1:<3A> л<EFBFBD> <D0BB> ͺ <EFBFBD> Ϊ[%2],<2C> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> IDΪ[%3],ʱ<> <CAB1> :%4" )
. arg ( nId )
. arg ( strModel )
. arg ( mmCmd )
. arg ( QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss zzz " ) ) ;
}
m_StationInfo_1 . m_bRunEnable = true ;
}
else if ( nId = = 2 )
{
if ( m_StationInfo_2 . m_PLCID ! = mmCmd ) {
m_StationInfo_2 . m_PLCID = mmCmd ;
m_StationInfo_2 . strModelName = strModel ;
SYSLOG_STATUS < < QString ( " <EFBFBD> ﹤λ%1:<3A> л<EFBFBD> <D0BB> ͺ <EFBFBD> Ϊ[%2],<2C> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> IDΪ[%3],ʱ<> <CAB1> :%4" )
. arg ( nId )
. arg ( strModel )
. arg ( mmCmd )
. arg ( QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss zzz " ) ) ;
}
m_StationInfo_2 . m_bRunEnable = true ;
}
}
else {
if ( nId = = 1 )
{
if ( m_StationInfo_1 . m_PLCID ! = mmCmd ) {
m_StationInfo_1 . m_PLCID = mmCmd ;
m_StationInfo_1 . strModelName = strModel ;
if ( mmCmd < = 0 )
SYSLOG_STATUS < < QString ( " <EFBFBD> ﹤λ%1:<3A> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> IDΪ[%2],ʱ<> <CAB1> :%3" )
. arg ( nId )
. arg ( mmCmd )
. arg ( QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss zzz " ) ) ;
else
SYSLOG_STATUS < < QString ( " <EFBFBD> ﹤λ%1:<3A> ͺ <EFBFBD> <CDBA> л<EFBFBD> ʧ<EFBFBD> <CAA7> ,<2C> <> Ӧ<EFBFBD> <D3A6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> IDΪ[%2],ʱ<> <CAB1> :%3" )
. arg ( nId )
. arg ( mmCmd )
. arg ( QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss zzz " ) ) ;
}
m_StationInfo_1 . m_bRunEnable = false ;
if ( mmCmd > 0 )
{
QString strMsg = QString ( " %1:<3A> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> ʧ<EFBFBD> <CAA7> ,ģ<> Ϳ <EFBFBD> <CDBF> в<EFBFBD> <D0B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> %2 " ) . arg ( QTime : : currentTime ( ) . toString ( " hh:mm:ss zzz: " ) ) . arg ( mmCmd ) ;
emit sgShowLog ( 1 , strMsg ) ;
}
}
else if ( nId = = 2 )
{
if ( m_StationInfo_2 . m_PLCID ! = mmCmd ) {
m_StationInfo_2 . m_PLCID = mmCmd ;
m_StationInfo_2 . strModelName = strModel ;
if ( mmCmd < = 0 )
SYSLOG_STATUS < < QString ( " <EFBFBD> ﹤λ%1:<3A> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> IDΪ[%2],ʱ<> <CAB1> :%3" )
. arg ( nId )
. arg ( mmCmd )
. arg ( QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss zzz " ) ) ;
else
SYSLOG_STATUS < < QString ( " <EFBFBD> ﹤λ%1:<3A> ͺ <EFBFBD> <CDBA> л<EFBFBD> ʧ<EFBFBD> <CAA7> ,<2C> <> Ӧ<EFBFBD> <D3A6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> IDΪ[%2],ʱ<> <CAB1> :%3" )
. arg ( nId )
. arg ( mmCmd )
. arg ( QDateTime : : currentDateTime ( ) . toString ( " hh:mm:ss zzz " ) ) ;
}
m_StationInfo_2 . m_bRunEnable = false ;
if ( mmCmd > 0 ) {
QString strMsg = QString ( " %1:<3A> ͺ <EFBFBD> <CDBA> <EFBFBD> <EFBFBD> <EFBFBD> ʧ<EFBFBD> ܣ<EFBFBD> ģ<EFBFBD> Ϳ <EFBFBD> <CDBF> в<EFBFBD> <D0B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> %2 " ) . arg ( QTime : : currentTime ( ) . toString ( " hh:mm:ss zzz: " ) ) . arg ( mmCmd ) ;
emit sgShowLog ( 2 , strMsg ) ;
}
}
}
}
}
}
Q_SLOT void CMainWin : : onHeardBit ( )
{
if ( m_pSerialPort ) {
SComFrame frame ;
memset ( & frame , 0 , sizeof ( SComFrame ) ) ;
frame . cmd = 0x43 ;
frame . data7 = 200 ;
frame . data8 = 0x50 ;
m_pSerialPort - > enquequeData ( frame ) ;
}
}
Q_SLOT void CMainWin : : onActionClicked ( )
{
QString strObj = sender ( ) - > objectName ( ) ;
if ( " actionSetting " = = strObj ) { //<2F> 궨
IDetectorUI * pDetectorUI = GetDesignerInterface ( ) ;
if ( pDetectorUI ) {
pDetectorUI - > ShowMainFrame ( ) ;
}
}
else if ( " actionManage " = = strObj ) { //ģ<> <C4A3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
m_mangeWid . setParent ( this ) ;
m_mangeWid . setWindowFlags ( Qt : : Dialog | Qt : : WindowCloseButtonHint ) ;
m_mangeWid . setWindowModality ( Qt : : ApplicationModal ) ;
m_mangeWid . setAttribute ( Qt : : WA_ShowModal , true ) ;
m_mangeWid . show ( ) ;
}
else if ( " actionTest " = = strObj ) { //<2F> <> <EFBFBD> <EFBFBD>
m_testWid . setParent ( this ) ;
m_testWid . setWindowFlags ( Qt : : Dialog | Qt : : WindowCloseButtonHint ) ;
m_testWid . setWindowModality ( Qt : : ApplicationModal ) ;
m_testWid . setAttribute ( Qt : : WA_ShowModal , true ) ;
m_testWid . show ( ) ;
}
else if ( " actionHelp " = = strObj ) { //<2F> <> <EFBFBD> <EFBFBD>
m_aboutWid . setParent ( this ) ;
m_aboutWid . setWindowIcon ( QIcon ( LEAPER_LOGO ) ) ;
m_aboutWid . setWindowFlags ( Qt : : Dialog | Qt : : WindowCloseButtonHint ) ;
m_aboutWid . setWindowModality ( Qt : : ApplicationModal ) ;
m_aboutWid . setAttribute ( Qt : : WA_ShowModal , true ) ;
m_aboutWid . show ( ) ;
}
else if ( " action_Check " = = strObj ) { //<2F> <> ʷ<EFBFBD> <CAB7> ¼<EFBFBD> <C2BC> ѯ
QProcess process ;
process . setWorkingDirectory ( QCoreApplication : : applicationDirPath ( ) ) ;
# ifdef _DEBUG
QString strTaskName = " Reportd.exe " ;
# else
QString strTaskName = " Report.exe " ;
# endif
process . startDetached ( strTaskName ) ;
}
else if ( " action " = = strObj ) { //ϵͳ<CFB5> <CDB3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
m_devMgrWid . setParent ( this ) ;
m_devMgrWid . setWindowIcon ( QIcon ( LEAPER_LOGO ) ) ;
m_devMgrWid . setWindowFlags ( Qt : : Dialog | Qt : : WindowCloseButtonHint ) ;
m_devMgrWid . setWindowModality ( Qt : : ApplicationModal ) ;
m_devMgrWid . setAttribute ( Qt : : WA_ShowModal , true ) ;
m_devMgrWid . show ( ) ;
}
else if ( " main_Login_action " = = strObj ) { //<2F> û<EFBFBD> <C3BB> <EFBFBD> ½
if ( m_pUserCtrl ) {
if ( m_pUserCtrl - > getLoginState ( ) = = EM_LOGIN )
{
QMessageBox infobox ( QMessageBox : : Information , QString ( QObject : : tr ( " <EFBFBD> <EFBFBD> ʾ " ) ) , QString ( QObject : : tr ( " <EFBFBD> <EFBFBD> ȷ<EFBFBD> <EFBFBD> Ҫע<EFBFBD> <EFBFBD> %1 ?" ) ) . arg ( m_pUserCtrl - > CurUser ( ) ) , QMessageBox : : Yes | QMessageBox : : No , NULL ) ;
infobox . setWindowIcon ( QIcon ( " :/image/leaper " ) ) ;
infobox . setButtonText ( QMessageBox : : Yes , QString ( " ȷ<EFBFBD> <EFBFBD> " ) ) ;
infobox . setButtonText ( QMessageBox : : No , QString ( " ȡ<EFBFBD> <EFBFBD> " ) ) ;
if ( infobox . exec ( ) = = QMessageBox : : Yes ) {
m_pUserCtrl - > LogOutUser ( ) ;
}
}
else
m_pUserCtrl - > CheckLogin ( ) ;
}
else
{
QMessageBox infobox ( QMessageBox : : Information , QString ( QObject : : tr ( " <EFBFBD> <EFBFBD> ʾ " ) ) , QString ( QObject : : tr ( " <EFBFBD> ù<EFBFBD> <EFBFBD> <EFBFBD> δ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ." ) ) , QMessageBox : : Yes , NULL ) ;
infobox . setWindowIcon ( QIcon ( " :/image/leaper " ) ) ;
infobox . setButtonText ( QMessageBox : : Yes , QString ( QObject : : tr ( " ȷ<EFBFBD> <EFBFBD> " ) ) ) ;
infobox . exec ( ) ;
}
}
else if ( " main_action_userManager " = = strObj ) { //<2F> û<EFBFBD> <C3BB> <EFBFBD> <EFBFBD> <EFBFBD>
if ( m_pUserCtrl ) {
m_pUserCtrl - > ShowUserMgrDlg ( ) ;
}
else
{
QMessageBox infobox ( QMessageBox : : Information , QString ( QObject : : tr ( " <EFBFBD> <EFBFBD> ʾ " ) ) , QString ( QObject : : tr ( " <EFBFBD> ù<EFBFBD> <EFBFBD> <EFBFBD> δ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ." ) ) , QMessageBox : : Yes , NULL ) ;
infobox . setWindowIcon ( QIcon ( " :/image/leaper " ) ) ;
infobox . setButtonText ( QMessageBox : : Yes , QString ( QObject : : tr ( " ȷ<EFBFBD> <EFBFBD> " ) ) ) ;
infobox . exec ( ) ;
}
}
}
void CMainWin : : timerEvent ( QTimerEvent * event )
{
if ( m_TimerID_Status = = event - > timerId ( ) )
{
onUpdateStatus ( ) ;
}
}
void CMainWin : : closeEvent ( QCloseEvent * event )
{
QMessageBox info ( this ) ;
info . setWindowIcon ( QIcon ( LEAPER_LOGO ) ) ;
info . setWindowTitle ( QObject : : tr ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ) ) ;
info . setText ( QObject : : tr ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ϵͳ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> У <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫ<EFBFBD> رգ <EFBFBD> " ) ) ;
info . setStandardButtons ( QMessageBox : : Ok | QMessageBox : : Cancel ) ;
info . setButtonText ( QMessageBox : : Ok , QObject : : tr ( " ȷ<EFBFBD> <EFBFBD> " ) ) ;
info . setButtonText ( QMessageBox : : Cancel , QObject : : tr ( " ȡ<EFBFBD> <EFBFBD> " ) ) ;
if ( info . exec ( ) ! = QMessageBox : : Ok )
{
event - > ignore ( ) ;
}
else
event - > accept ( ) ;
}
//<2F> <> ʼ <EFBFBD> <CABC> ״̬<D7B4> <CCAC>
void CMainWin : : onInitStatus ( )
{
const int c_nWidth = 170 ;
m_pLbCurrentTime = new QLabel ( QObject : : tr ( " ϵͳʱ<EFBFBD> <EFBFBD> " ) ) ;
m_pLbCurrentTime - > setMinimumHeight ( 40 ) ;
m_pLbCurrentTime - > setMinimumWidth ( c_nWidth ) ;
m_pLbOnLine = new class QLabel ( QObject : : tr ( " ģʽ: " ) ) ;
m_pLbOnLine - > setMinimumWidth ( c_nWidth ) ;
m_pLbUser = new class QLabel ( QObject : : tr ( " <EFBFBD> û<EFBFBD> :<3A> <> " ) ) ;
m_pLbUser - > setMinimumWidth ( c_nWidth ) ;
m_pLbConnect = new class QLabel ( QObject : : tr ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ״̬:" ) ) ;
m_pLbConnect - > setMinimumWidth ( c_nWidth ) ;
//m_pLbDiskSpace = new class QLabel(QObject::tr("Ӳ<> <D3B2> ʣ<EFBFBD> <CAA3> <EFBFBD> ռ <EFBFBD> :xxx.xG"));
//m_pLbDiskSpace->setMinimumWidth(c_nWidth);
ui . statusBar - > addWidget ( m_pLbOnLine ) ;
ui . statusBar - > addWidget ( m_pLbConnect ) ;
ui . statusBar - > addWidget ( m_pLbUser ) ;
ui . statusBar - > addWidget ( m_pLbCurrentTime ) ;
//ui.statusBar->addWidget(m_pLbDiskSpace);
}
void CMainWin : : onUpdateStatus ( )
{
if ( m_pLbCurrentTime ) {
QString m_currentTimerString = QDateTime : : currentDateTime ( ) . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
m_pLbCurrentTime - > setText ( QObject : : tr ( " ϵͳʱ<EFBFBD> <EFBFBD> : " ) + m_currentTimerString + " " ) ;
//m_pLbCurrentTime->setStyleSheet("font: 14px;");
}
if ( m_pLbOnLine & & m_pWfCtrl ) {
QString strOnlineState = QString ( QObject : : tr ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ģʽ <EFBFBD> <EFBFBD> " ) )
+ ( m_pWfCtrl - > IOnlineMode ( ) = = true ? QObject : : tr ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ģʽ " ) : QObject : : tr ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ģʽ " ) ) ;
m_pLbOnLine - > setText ( strOnlineState ) ;
// m_pLbOnLine->setStyleSheet("font: bold 14px;");
}
if ( m_pLbConnect & & m_pWfCtrl ) {
QString strOnlineState = QString ( QObject : : tr ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ״̬<EFBFBD> <EFBFBD> " ) )
+ ( m_pWfCtrl - > IConnectStatus ( ) = = true ? QObject : : tr ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ) : QObject : : tr ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 쳣" ) ) ;
m_pLbConnect - > setText ( strOnlineState ) ;
}
if ( m_pLbUser ) {
m_pLbUser - > setText ( QObject : : tr ( " <EFBFBD> û<EFBFBD> : %1" ) . arg ( m_strUserName . isEmpty ( ) = = true ? QObject : : tr ( " δ<EFBFBD> <EFBFBD> ¼ " ) : m_strUserName ) ) ;
}
// if (m_pLbDiskSpace)
// {
// QString strDiskSpace = QString(QObject::tr("Ӳ<> <D3B2> ʣ<EFBFBD> <CAA3> <EFBFBD> ռ <EFBFBD> :%1G")).arg(100 / 1024.0);
// m_pLbDiskSpace->setText(strDiskSpace);
// }
}
bool CMainWin : : onInitCoreCtrl ( )
{
//load engine
if ( NULL = = m_pDllDetectorEngine )
{
m_pDllDetectorEngine = new CDllDetectorEngine ( ) ;
if ( NULL = = m_pDllDetectorEngine )
{
return false ;
}
m_pDetectorEngine = m_pDllDetectorEngine - > m_pDE ;
}
//load coretrl
if ( NULL = = m_pDllCoreCtrl )
{
m_pDllCoreCtrl = new CDllCoreCtrl ( QStringList ( ) , this , m_pDetectorEngine ) ;
if ( NULL = = m_pDllCoreCtrl )
{
return false ;
}
m_pCoreCtrl = m_pDllCoreCtrl - > m_pCoreCtrl ;
}
m_pDllDetectorEngine - > Initialize ( m_pCoreCtrl ) ;
if ( NULL = = m_pDesignerMgr )
{
m_pDesignerMgr = new QDetectorDesignerMgr ( ) ;
if ( ! m_pDesignerMgr - > Initialize ( m_pDetectorEngine ) ) {
qWarning ( ) < < " Initialize is false " ;
}
}
return true ;
}
bool CMainWin : : onInitDevice ( )
{
QStringList strCamKeys = m_pCoreCtrl - > ICameraKeys ( ) ;
for ( int nIndex = 0 ; nIndex < strCamKeys . size ( ) ; nIndex + + )
{
QString camKey = strCamKeys . at ( nIndex ) ;
m_pCoreCtrl - > IOpenCamera ( camKey ) ;
m_pCoreCtrl - > IStartCamera ( camKey ) ;
}
return true ;
}
//======ϵͳ<CFB5> <CDB3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
void CMainWin : : SearchQmFile ( const QString & strDir )
{
QDir dir ( strDir ) ;
if ( ! dir . exists ( ) )
{
return ;
}
dir . setFilter ( QDir : : Dirs | QDir : : Files | QDir : : NoDotAndDotDot ) ;
dir . setSorting ( QDir : : DirsFirst ) ; // <20> ļ<EFBFBD> <C4BC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// ת<> <D7AA> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> List
QFileInfoList list = dir . entryInfoList ( ) ;
if ( list . size ( ) < 1 )
{
return ;
}
int i = 0 ;
do
{
QFileInfo fileInfo = list . at ( i ) ;
QString tt = fileInfo . fileName ( ) ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ļ<EFBFBD> <C4BC> <EFBFBD>
bool bisDir = fileInfo . isDir ( ) ;
if ( bisDir )
{
SearchQmFile ( fileInfo . filePath ( ) ) ;
}
else
{
bool bQm = fileInfo . fileName ( ) . endsWith ( " .qm " ) ;
SetTranslator ( fileInfo . filePath ( ) ) ;
}
i + + ;
} while ( i < list . size ( ) ) ;
}
void CMainWin : : SetTranslator ( const QString strPath )
{
if ( strPath . isEmpty ( ) )
{
return ;
}
QTranslator * pTrans = new QTranslator ;
if ( pTrans - > load ( strPath ) ) // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> سɹ<D8B3>
{
qApp - > installTranslator ( pTrans ) ;
m_VecTranPtr . append ( pTrans ) ;
}
else
{
delete pTrans ;
pTrans = NULL ;
}
}
void CMainWin : : SetLanguage ( QString strLangage )
{
QString strDirPath = QString ( QCoreApplication : : applicationDirPath ( ) + " /language/ " ) ;
QString translatorFileName = strLangage ;
if ( ! translatorFileName . isEmpty ( ) )
{
rmTranslator ( ) ;
QLocale : : setDefault ( QLocale ( translatorFileName ) ) ;
QString transDir = strDirPath + translatorFileName ;
SearchQmFile ( transDir ) ;
}
}
void CMainWin : : rmTranslator ( )
{
if ( m_VecTranPtr . size ( ) > 0 )
{
while ( m_VecTranPtr . size ( ) )
{
QTranslator * pVa = m_VecTranPtr . takeFirst ( ) ;
qApp - > removeTranslator ( pVa ) ;
delete pVa ;
pVa = NULL ;
}
}
}
void CMainWin : : writeConfig ( )
{
QSettings setting ( " language.ini " , QSettings : : IniFormat ) ;
setting . setValue ( " language " , m_strCurLanguage ) ;
}
//======<3D> <> <EFBFBD> <EFBFBD>
IDetectorUI * CMainWin : : GetDesignerInterface ( ) const
{
if ( m_pDesignerMgr )
return m_pDesignerMgr - > GetDesignerInterface ( ) ;
return nullptr ;
}
void CMainWin : : saveSolution ( )
{
qDebug ( ) < < " start save solution " ;
if ( m_pColossus & & m_pWfCtrl ) {
m_pColossus - > saveTask ( m_pWfCtrl - > IGetModelInfos ( ) ) ;
}
qDebug ( ) < < " finish save solution " ;
}
Q_SLOT void CMainWin : : onMainFrameClose ( )
{
if ( m_pWfCtrl ) {
m_pWfCtrl - > IUpdateModelInfo ( ) ;
}
}
Q_SLOT void CMainWin : : onSnapImage ( int nCamera /*= -1*/ )
{
if ( ! m_pWfCtrl )
return ;
IStation * pStation = m_pWfCtrl - > IGetStationById ( nCamera ) ;
if ( ! pStation ) {
return ;
}
else {
pStation - > trigImage ( ) ;
}
}
Q_SLOT void CMainWin : : onTrigImage ( )
{
onSnapImage ( 1 ) ;
onSnapImage ( 2 ) ;
}
Q_SLOT void CMainWin : : onSelModel ( int nId , QString strModel )
{
if ( m_pWfCtrl ) {
m_pWfCtrl - > ISelModel ( nId , strModel ) ;
}
}
Q_SLOT void CMainWin : : onChangeUI ( QString strUsr , int nLevel )
{
switch ( nLevel ) {
case 9 :
case 8 :
case 7 :
case 6 :
ui . main_action_userManager - > setVisible ( true ) ;
ui . action - > setEnabled ( true ) ;
ui . actionTest - > setEnabled ( true ) ;
break ;
case 5 :
ui . main_action_userManager - > setVisible ( true ) ;
ui . action - > setEnabled ( true ) ;
ui . actionTest - > setEnabled ( true ) ;
break ;
case 4 :
case 3 :
case 2 :
case 1 :
case 0 :
ui . main_action_userManager - > setVisible ( false ) ;
ui . action - > setEnabled ( false ) ;
ui . actionTest - > setEnabled ( false ) ;
break ;
default :
break ;
}
}
Q_SLOT void CMainWin : : onLogInOut ( QString strName , int level , int state )
{
onChangeUI ( strName , level ) ;
m_strUserName = strName ;
if ( state = = 0 ) {
ui . main_Login_action - > setText ( QObject : : tr ( " ע <20> <> " ) ) ;
}
else
{
ui . main_Login_action - > setText ( QObject : : tr ( " <EFBFBD> <EFBFBD> ¼" ) ) ;
}
}
Q_SLOT void CMainWin : : onTestMode ( int val )
{
if ( val = = 0 ) {
m_pCameraTrig - > start ( 1000 ) ;
}
else if ( val = = 1 ) {
m_pCameraTrig - > stop ( ) ;
}
else if ( val = = 2 ) {
onSnapImage ( 1 ) ;
}
else if ( val = = 3 ) {
onSnapImage ( 2 ) ;
}
}
//չʾ <D5B9> <CABE> <EFBFBD> <EFBFBD> ͼƬ
Q_SLOT void CMainWin : : onShowImage ( int ID , QImage img )
{
auto ShowImg = [ & ] ( QLabel * pLab , QImage & img ) {
if ( ! pLab ) {
qDebug ( ) < < " label image is null " ;
return ;
}
if ( img . isNull ( ) )
{
QString str = QObject : : tr ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> : ģ<> <C4A3> <EFBFBD> <EFBFBD> ͼ<EFBFBD> <CDBC> <EFBFBD> ߴ 粻ƥ<E7B2BB> 䣬<EFBFBD> <E4A3AC> <EFBFBD> <EFBFBD> <EFBFBD> ±궨ģ<EAB6A8> <C4A3> !!!" ) ;
pLab - > setText ( str ) ;
}
else
{
QRect rt = ui . wf_lb_image_show_1 - > rect ( ) ;
int h = img . height ( ) ;
int w = img . width ( ) ;
float d = w * 1.0 / h ;
if ( d > 0 )
{
int h2 = rt . width ( ) / d ;
rt . setHeight ( h2 ) ;
}
QImage imgShow = img . scaled ( QSize ( rt . size ( ) ) ) ;
pLab - > setPixmap ( QPixmap : : fromImage ( imgShow ) ) ;
}
} ;
if ( ID = = 1 )
{
ShowImg ( ui . wf_lb_image_show_1 , img ) ;
}
else if ( ID = = 2 )
{
ShowImg ( ui . wf_lb_image_show_2 , img ) ;
}
}
//չʾ <D5B9> <CABE> <EFBFBD> ڼ<EFBFBD> <DABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͺ <EFBFBD> <CDBA> <EFBFBD>
Q_SLOT void CMainWin : : onShowName ( int ID , QString strName )
{
if ( ID = = 1 ) {
ui . wf_lb_station_name_1 - > setText ( strName ) ;
}
else if ( ID = = 2 ) {
ui . wf_lb_station_name_2 - > setText ( strName ) ;
}
}
//չʾ log
Q_SLOT void CMainWin : : onShowLog ( int nID , QString strMsg )
{
if ( nID = = 1 ) {
ui . wf_text_edit_result_1 - > append ( strMsg ) ;
}
else if ( nID = = 2 ) {
ui . wf_text_edit_result_2 - > append ( strMsg ) ;
}
}