Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

151 lines
3.7 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: GraphWnd.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of GraphWnd.cpp
//----------------------------------------------------------------------------
// GraphWnd.cpp : implementation file
//
#include "stdafx.h"
#include "Calibration.h"
#include "GraphWnd.h"
#include ".\graphwnd.h"
IMPLEMENT_DYNAMIC(CGraphWnd, CWnd)
CGraphWnd::CGraphWnd()
{
m_Min.x = m_Min.y = 0.0;
m_Max.x = m_Max.y = 1.0;
m_Axis.x = 0;
m_Axis.y = 0;
m_Step.cx = m_Step.cy = 0.1;
CGraphData GraphData;
GraphData.bVisible = TRUE;
GraphData.rgbColor = RGB(0xFF,0xFF,0xFF);
/*
GraphData.Add( CLgDPoint(0.0,0.0) );
GraphData.Add( CLgDPoint(0.2,0.1) );
GraphData.Add( CLgDPoint(0.3,0.4) );
GraphData.Add( CLgDPoint(0.6,0.5) );
GraphData.Add( CLgDPoint(0.7,0.8) );
GraphData.Add( CLgDPoint(1.0,0.9) );
*/
m_GraphDataArray.Add( GraphData );
// GraphData.RemoveAll();
GraphData.bVisible = TRUE;
GraphData.rgbColor = RGB(0xFF,0xFF,0);
/*
GraphData.Add( CLgDPoint(0.0,0.0) );
GraphData.Add( CLgDPoint(0.1,0.2) );
GraphData.Add( CLgDPoint(0.4,0.3) );
GraphData.Add( CLgDPoint(0.5,0.6) );
GraphData.Add( CLgDPoint(0.8,0.7) );
GraphData.Add( CLgDPoint(0.9,1.0) );
*/
m_GraphDataArray.Add( GraphData );
}
CGraphWnd::~CGraphWnd()
{
}
BEGIN_MESSAGE_MAP(CGraphWnd, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
void CGraphWnd::SetField( CLgDPoint min, CLgDPoint max, CLgDPoint axis, CLgDSize step )
{
// store parameters
m_Min = min;
m_Max = max;
m_Axis = axis;
m_Step = step;
// draw
CClientDC dc( this );
OnDraw( &dc );
}
void CGraphWnd::OnPaint()
{
CPaintDC dc(this);
OnDraw( &dc );
}
void CGraphWnd::OnDraw( CDC *pDC )
{
CRect rect;
GetClientRect( &rect );
#define OFFSET 5
double dX = m_Max.x - m_Min.x;
double dY = m_Max.y - m_Min.y;
double x2d = ( rect.Width() - ( OFFSET * 2 ) ) / dX;
double y2d = ( rect.Height() - ( OFFSET * 2 ) ) / dY;
#define X2D(x) ((INT)( x*x2d+OFFSET ))
#define Y2D(y) ((INT)( rect.Height()-OFFSET-y*y2d ))
// draw background
pDC->FillRect( &rect, &CBrush( RGB(0,0x7F,0) ) );
// draw axises
pDC->MoveTo( X2D(m_Axis.x), Y2D(m_Min.y) );
pDC->LineTo( X2D(m_Axis.x), Y2D(m_Max.y) );
pDC->MoveTo( X2D(m_Min.x), Y2D(m_Axis.y) );
pDC->LineTo( X2D(m_Max.x), Y2D(m_Axis.y) );
// draw steps
int sX = dX / m_Step.cx;
for( INT i = 0; i < sX; i++ )
{
pDC->MoveTo( X2D(dX * i / sX), Y2D(m_Axis.y) - 2 );
pDC->LineTo( X2D(dX * i / sX), Y2D(m_Axis.y) + 2 );
}
int sY = dY / m_Step.cy;
for( i = 0; i < sY; i++ )
{
pDC->MoveTo( X2D(m_Axis.x) - 2, Y2D(dY * i / sY) );
pDC->LineTo( X2D(m_Axis.x) + 2, Y2D(dY * i / sY) );
}
// draw data
for( i = 0; i < m_GraphDataArray.GetCount(); i++ )
{
if( !m_GraphDataArray[i].bVisible )
continue;
CPen pen( PS_SOLID, 1, m_GraphDataArray[i].rgbColor );
CPen *pPen = pDC->SelectObject( &pen );
for( INT j = 0; j < m_GraphDataArray[i].GetCount(); j++ )
{
if( j == 0 ) pDC->MoveTo( X2D(m_GraphDataArray[i][j].x), Y2D(m_GraphDataArray[i][j].y) );
else pDC->LineTo( X2D(m_GraphDataArray[i][j].x), Y2D(m_GraphDataArray[i][j].y) );
}
pDC->SelectObject( pPen );
}
}
BOOL CGraphWnd::Create( CWnd *pParentWnd, LPRECT pRect )
{
CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, NULL, NULL, NULL );
if( !CWnd::Create( strClassName, NULL, WS_CHILD | WS_VISIBLE, *pRect, pParentWnd, 0 ) )
return FALSE;
return FALSE;
}