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

📄 remotemonitorview.cpp

📁 电缆故障监控系统
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// remotemonitorView.cpp : implementation of the CRemotemonitorView class
//

#include "stdafx.h"
#include "remotemonitor.h"
#include "MainFrm.h"
#include "comm32.h"
#include "remotemonitorDoc.h"
#include "remotemonitorView.h"
#include "MMSYSTEM.H"
#include "define.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

COMMINFO Comminfo;
COMMINFO* pCommInfo;
extern int nPort,nBaudrate;
extern unsigned char  InDataBuf[];		// 串口缓冲区
extern int InDataLen;			        // 串口缓冲区中实际数据长度
extern  bool bPoll;			            // TRUE: 定时中断或串口中断正使用DataBuf和nDataBuf.

extern CString strCurrentUser;
extern CString strDutyTime;

/////////////////////////////////////////////////////////////////////////////
// CRemotemonitorView
int   m_nScale=100;
extern BOOL bRight[];	// 操作权限
IMPLEMENT_DYNCREATE(CRemotemonitorView, CScrollView)

BEGIN_MESSAGE_MAP(CRemotemonitorView, CScrollView)
	//{{AFX_MSG_MAP(CRemotemonitorView)
	ON_COMMAND(ID_ZOOMIN, OnZoomin)
	ON_COMMAND(ID_ZOOMOUT, OnZoomout)
	ON_COMMAND(ID_PAN, OnPan)
	ON_UPDATE_COMMAND_UI(ID_ZOOMIN, OnUpdateZoomin)
	ON_UPDATE_COMMAND_UI(ID_ZOOMOUT, OnUpdateZoomout)
	ON_UPDATE_COMMAND_UI(ID_PAN, OnUpdatePan)
	ON_COMMAND(ID_ARROW, OnArrow)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_COMMAND(ID_MAPCHANGE, OnMapchange)
	ON_COMMAND(ID_DRAWLINE, OnDrawline)
	ON_COMMAND(ID_DRAWCIRCLE, OnDrawcircle)
	ON_UPDATE_COMMAND_UI(ID_DRAWLINE, OnUpdateDrawline)
	ON_UPDATE_COMMAND_UI(ID_DRAWCIRCLE, OnUpdateDrawcircle)
	ON_COMMAND(ID_SELECT, OnSelect)
	ON_UPDATE_COMMAND_UI(ID_SELECT, OnUpdateSelect)
	ON_COMMAND(ID_DELETE, OnDelete)
	ON_UPDATE_COMMAND_UI(ID_DELETE, OnUpdateDelete)
	ON_WM_TIMER()
	ON_COMMAND(ID_SENDAA, OnSendaa)
	ON_COMMAND(ID_SENDAB, OnSendab)
	ON_COMMAND(ID_SENDCA, OnSendca)
	ON_COMMAND(ID_SENDCC, OnSendcc)
	ON_COMMAND(ID_SENDCD, OnSendcd)
	ON_COMMAND(ID_SENDDA, OnSendda)
	ON_COMMAND(ID_DELETELISTITEM, OnDeletelistitem)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_DESTROY()
	ON_COMMAND(ID_CLEARALARM, OnClearalarm)
	ON_COMMAND(ID_DUTYRECORD, OnDutyrecord)
	ON_COMMAND(ID_JIAOBAN, OnJiaoban)
	ON_COMMAND(ID_FENJICABLESET, OnFenjicableset)
	ON_COMMAND(ID_USERSET, OnUserset)
	ON_COMMAND(ID_VIEWDUTYRECORD, OnViewdutyrecord)
	ON_COMMAND(ID_VIEWFENJICABLEINFO, OnViewfenjicableinfo)
	ON_COMMAND(ID_VIEWCABLEALARMINFO, OnViewcablealarminfo)
	ON_UPDATE_COMMAND_UI(ID_USERSET, OnUpdateUserset)
	ON_UPDATE_COMMAND_UI(ID_FENJICABLESET, OnUpdateFenjicableset)
	ON_COMMAND(ID_SENDDC, OnSenddc)
	ON_COMMAND(ID_SENDCB, OnSendcb)
	ON_COMMAND(ID_SETCENTERTEL, OnSetcentertel)
	ON_UPDATE_COMMAND_UI(ID_CLEARALARM, OnUpdateClearalarm)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRemotemonitorView construction/destruction

CRemotemonitorView::CRemotemonitorView()
{
	// TODO: add construction code here
	m_strMapPathName="";
    m_hMemoryDC=NULL;
    m_hBitmap=NULL;
    m_hOldBitmap=NULL;
	m_bMouseDown=FALSE;
    m_pPenProperties=NULL;
    m_nCurTool=ID_ARROW;
	m_usrCurrentObject = NULL;
	m_nCurrentPenColor = RGB(255,0,0);
    m_nCurrentPenWidth =1;
	m_nCurrentFillColor= RGB(255,255,0);
	m_nTextColor=RGB(0,0,255);

    m_uRevTimer=0;
	m_uSendTimer=0;
	m_uFlashTimer=0;
    m_uProbeTimer=0;
	m_uDisplayTimer=0;
	m_uReSendTimer=0;
	m_bAlarm=false;
    m_nCounter=0;
    m_bBusy=FALSE;
	m_nLinkState=IDLE;
    m_bHasAck=FALSE;
	CreateCommInfo(&Comminfo,nPort,/*nBaudrate*/9600);
	OpenConnection(&Comminfo,(LPTHREAD_START_ROUTINE)CommWatchProc);


}
void CRemotemonitorView::ChangePenColor(COLORREF nColor)
{
	m_nCurrentPenColor = nColor;
	if(m_usrCurrentObject && m_usrCurrentObject->m_bSelected)
	{//更新当前选择图元的显示
		m_usrCurrentObject->SetPenColor(m_nCurrentPenColor);
		// 设置脏标记
	    CRemotemonitorDoc* pDoc = GetDocument();
		pDoc->SetModifiedFlag(TRUE);
		Invalidate();
	}
}

void CRemotemonitorView::ChangeFillColor(COLORREF nColor)
{
	m_nCurrentFillColor = nColor;
	if(m_usrCurrentObject && m_usrCurrentObject->m_bSelected)
	{//更新当前选择图元的显示
		m_usrCurrentObject->SetFillColor(m_nCurrentFillColor);
	    CRemotemonitorDoc* pDoc = GetDocument();
		pDoc->SetModifiedFlag(TRUE);
		Invalidate();
	}
}
void CRemotemonitorView::ChangeTextColor(COLORREF nColor)
{
	m_nTextColor = nColor;
	if(m_usrCurrentObject && m_usrCurrentObject->m_bSelected)
	{//更新当前选择图元的显示
		m_usrCurrentObject->SetTextColor(m_nTextColor);
	    CRemotemonitorDoc* pDoc = GetDocument();
		pDoc->SetModifiedFlag(TRUE);

		Invalidate();
	}
}

void CRemotemonitorView::ChangePenWidth(int nWidth)
{
	m_nCurrentPenWidth = nWidth;
	if(m_usrCurrentObject && m_usrCurrentObject->m_bSelected)
	{//更新当前选择图元的显示
		m_usrCurrentObject->SetPenWidth(m_nCurrentPenWidth);
	    CRemotemonitorDoc* pDoc = GetDocument();
		pDoc->SetModifiedFlag(TRUE);

		Invalidate();
	}
}

CRemotemonitorView::~CRemotemonitorView()
{
	CloseConnection(&Comminfo); // 关闭通信口1
	DestroyCommInfo(&Comminfo); // 删除通信控制块

	if(m_hOldBitmap)
		SelectObject(m_hMemoryDC,m_hOldBitmap);
	if(m_hBitmap)
		DeleteObject(m_hBitmap);
	if(m_hMemoryDC)
		DeleteDC(m_hMemoryDC);

	if(m_cabletable.IsOpen())
        m_cabletable.Close();
	if(m_fenjitable.IsOpen())
        m_fenjitable.Close();
	if(m_cablealarmtable.IsOpen())
        m_cablealarmtable.Close();

}

BOOL CRemotemonitorView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CRemotemonitorView drawing

void CRemotemonitorView::OnDraw(CDC* pDC)
{
	CRemotemonitorDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
    //画位图
	if(m_hMemoryDC!=NULL)
	{

     //   BitBlt(pDC->m_hDC,0,0,m_bmInfo.bmWidth,m_bmInfo.bmHeight,m_hMemoryDC,0,0,SRCCOPY);
		::SetStretchBltMode(pDC->m_hDC,COLORONCOLOR);
        ::StretchBlt(pDC->m_hDC,0,0,(int)(m_bmInfo.bmWidth*((float)m_nScale/100.0)),(int)(m_bmInfo.bmHeight*((float)m_nScale/100.0)),m_hMemoryDC,0,0,m_bmInfo.bmWidth,m_bmInfo.bmHeight,SRCCOPY);
	}
	//以下重绘标绘图形
	if(pDoc->m_aObjects.GetSize()>0)
	{
	     pDoc->DrawObjects(pDC);
	}

}

void CRemotemonitorView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	if(m_hMemoryDC==NULL)
	{
	    sizeTotal.cx=sizeTotal.cy = 100;
	    SetScrollSizes(MM_TEXT, sizeTotal);
	}
	else
	{
	    sizeTotal.cx=(long)(m_bmInfo.bmWidth*((float)m_nScale/100.0));
		sizeTotal.cy =(long)( m_bmInfo.bmHeight*((float)m_nScale/100.0));
	}
	SetScrollSizes(MM_TEXT, sizeTotal);
    m_usrCurrentObject=NULL;
	// TODO: calculate the total size of this view

//	CloseConnection(&Comminfo); // 关闭通信口1
//	DestroyCommInfo(&Comminfo); // 删除通信控制块

//	CreateCommInfo(&Comminfo,nPort,nBaudrate);
//	OpenConnection(&Comminfo,(LPTHREAD_START_ROUTINE)CommWatchProc);

	m_pkstart.syn=0x16;
	m_pkstart.dle=0x10;
	m_pkstart.stx=0x02;
	m_pkend.dle=0x10;
	m_pkend.etx=0x03;

	if(m_uFlashTimer)
		KillTimer(m_uFlashTimer);
	if(m_uRevTimer)
		KillTimer(m_uRevTimer);
	if(m_uSendTimer)
		KillTimer(m_uSendTimer);
    if(m_uProbeTimer)
		KillTimer(m_uProbeTimer);
    if(m_uDisplayTimer)
		KillTimer(m_uDisplayTimer);
    if(m_uReSendTimer)
		KillTimer(m_uReSendTimer);

	if(!m_cabletable.IsOpen())
        m_cabletable.Open();
	if(!m_fenjitable.IsOpen())
        m_fenjitable.Open();
	if(!m_cablealarmtable.IsOpen())
        m_cablealarmtable.Open();

	m_uFlashTimer=SetTimer(FLASHTIMER,m_FlashT,NULL);
	m_uRevTimer=SetTimer(REVTIMER,m_RevT,NULL);
	m_uSendTimer=SetTimer(SNDTIMER,m_SendT,NULL);
	m_uProbeTimer=SetTimer(PROBETIMER,m_ProbeT,NULL);
	m_uDisplayTimer=SetTimer(DISPLAYTIME,m_DisplayT,NULL);
    SendLR();
    m_bHasAck=FALSE;
}
void CRemotemonitorView::initMemoryDC()
{
   HDC hDC;
   hDC=::GetDC(*this);
   m_hMemoryDC=CreateCompatibleDC(hDC);

   m_hBitmap=(HBITMAP)LoadImage(NULL,m_strMapPathName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
 //   m_bitmap.Attach(hbitmap);
   m_hOldBitmap=(HBITMAP)SelectObject(m_hMemoryDC,m_hBitmap);
   ::ReleaseDC(*this,hDC);

//	m_pOldBitmap=m_memoryDC.SelectObject(&m_bitmap);
 //   m_bitmap.GetObject(sizeof(BITMAP),sizeof(BITMAP));

   
   ::GetObject(m_hBitmap,sizeof(BITMAP),&m_bmInfo);
	CSize sizeTotal;

	sizeTotal.cx=m_bmInfo.bmWidth;
	sizeTotal.cy = m_bmInfo.bmHeight;
	SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CRemotemonitorView printing

BOOL CRemotemonitorView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CRemotemonitorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CRemotemonitorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CRemotemonitorView diagnostics

#ifdef _DEBUG
void CRemotemonitorView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CRemotemonitorView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CRemotemonitorDoc* CRemotemonitorView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRemotemonitorDoc)));
	return (CRemotemonitorDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CRemotemonitorView message handlers

/*
void CRemotemonitorView::ReadCfgFromIni()
{
	char path_buffer[_MAX_PATH];
	char path_ini[_MAX_PATH];
	char drive[_MAX_DRIVE];
	char dir[_MAX_DIR];
	char fname[_MAX_FNAME];
	char ext[_MAX_EXT];
	CString strIniName;

	GetModuleFileName( NULL, path_buffer, _MAX_PATH );
	_splitpath( path_buffer, drive, dir, fname, ext );	
	_makepath(  path_ini, drive, dir, fname, "ini" );
    strIniName = path_ini;
	int nMapCur = GetPrivateProfileInt("MAP", "MAPCUR", 0, strIniName);
    m_nCurMap = nMapCur;
	CString strMapPathName,strEntry;
	strEntry.Format(TEXT("MAP%d"),nMapCur);
	GetPrivateProfileString("MAP", strEntry,"", strMapPathName.GetBuffer(80), 80,strIniName);

	strMapPathName.ReleaseBuffer();
	strMapPathName.TrimLeft();
	strMapPathName.TrimRight();
	m_strMapPathName = strMapPathName;
}
void CRemotemonitorView::WriteCfgToIni()
{
	char path_buffer[_MAX_PATH];
	char path_ini[_MAX_PATH];
	char drive[_MAX_DRIVE];
	char dir[_MAX_DIR];
	char fname[_MAX_FNAME];
	char ext[_MAX_EXT];
	CString strIniName;

	GetModuleFileName( NULL, path_buffer, _MAX_PATH );
	_splitpath( path_buffer, drive, dir, fname, ext );	
	_makepath(  path_ini, drive, dir, fname, "ini" );
    strIniName = path_ini;

	CString strMapCur;
    strMapCur.Format("%d",m_nCurMap);
	WritePrivateProfileString("MAP", "MAPCUR",strMapCur, strIniName); 
}

*/

void CRemotemonitorView::OnZoomin() 
{
	// TODO: Add your command handler code here
	//设置当前工具为 放大镜  地图拉近
	m_nCurTool=ID_ZOOMIN;
	HCURSOR hCursor;
    hCursor=AfxGetApp()->LoadCursor(IDC_ZOOMIN);
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)hCursor);
	int i;
    CDC* pDC = GetDC();
	OnPrepareDC(pDC);//设置DC的滚动属性,与ScollView的滚动有关
	CRemotemonitorDoc* pDoc = GetDocument();

	for(i = pDoc->m_aObjects.GetSize()-1; i >= 0; i--)
	{
		m_usrCurrentObject = pDoc->m_aObjects[i];
		m_usrCurrentObject->Selected(pDC, false);
		m_usrCurrentObject = NULL;
	}
	ReleaseDC(pDC);//释放DC资源
}
void CRemotemonitorView::OnUpdateZoomin(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_nCurTool== ID_ZOOMIN);
	
}
void CRemotemonitorView::OnZoomout() 
{
	// TODO: Add your command handler code here
	//设置当前工具为 缩小 地图拉远
	m_nCurTool=ID_ZOOMOUT;
	HCURSOR hCursor;
    hCursor=AfxGetApp()->LoadCursor(IDC_ZOOMOUT);
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)hCursor);
	int i;
    CDC* pDC = GetDC();
	OnPrepareDC(pDC);//设置DC的滚动属性,与ScollView的滚动有关
	CRemotemonitorDoc* pDoc = GetDocument();

	for(i = pDoc->m_aObjects.GetSize()-1; i >= 0; i--)
	{
		m_usrCurrentObject = pDoc->m_aObjects[i];
		m_usrCurrentObject->Selected(pDC, false);
		m_usrCurrentObject = NULL;
	}
	ReleaseDC(pDC);//释放DC资源
}
void CRemotemonitorView::OnUpdateZoomout(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_nCurTool== ID_ZOOMOUT);
}
void CRemotemonitorView::OnPan() 
{

⌨️ 快捷键说明

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