MFC-Simulator/TestSimulator/TestSimulatorDlg.cpp

1582 lines
47 KiB
C++
Raw Permalink Normal View History

2023-02-03 03:07:52 +01:00
// TestSimulatorDlg.cpp : <20><><EFBFBD>@<40><>
//
#include "stdafx.h"
#include "TestSimulator.h"
#include "TestSimulatorDlg.h"
#include "afxdialogex.h"
#define _USE_MATH_DEFINES
#include "math.h"
//#include <iostream>
//using namespace std;
#define WIN_WIDTH 1316 //<2F><><EFBFBD>ܲ<EFBFBD><DCB2>Ȥ<EFBFBD><C8A4>ϼe<CFBC><65>
#define WIN_HEIGHT 559 //<2F><><EFBFBD>ܲ<EFBFBD><DCB2>Ȥ<EFBFBD><C8A4>ϰ<EFBFBD><CFB0><EFBFBD>
#define GRID_R 1 //<2F><><EFBFBD>@<40><><EFBFBD>I<EFBFBD>b<EFBFBD>|<7C>j<EFBFBD>p
#define MAX_STR_LEN 100 //<2F>̤j<CCA4>r<EFBFBD><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28>Ω<EFBFBD>Ū<EFBFBD><C5AA>ini<6E><69>)
#define WHITE RGB (255, 255, 255) //<2F>u<EFBFBD>@<40>ϭI<CFAD><49><EFBFBD>w<EFBFBD>]<5D>C<EFBFBD><43>
#define GRAY RGB (240, 240, 240) //<2F><><EFBFBD>I<EFBFBD>C<EFBFBD><43>
#define LIGHT_BLUE RGB (176, 224, 230) //<2F><><EFBFBD><EFBFBD>Block<63><6B><EFBFBD><EFBFBD><EFBFBD>C<EFBFBD><43>
#define RED RGB (255, 0, 0) //<2F><><EFBFBD><EFBFBD>Block<63><6B><EFBFBD><EFBFBD><EFBFBD>C<EFBFBD><43>
#define BLACK RGB (0, 0, 0) //<2F>s<EFBFBD>u<EFBFBD>C<EFBFBD><43>
#define MARK_FONTSIZE 120 //<2F>Ҧ<EFBFBD>Mark<72>r<EFBFBD><72><EFBFBD>j<EFBFBD>p
#define MARK_WIDTH 90 //Mark<72>ϰ<EFBFBD><CFB0>e<EFBFBD><65>
#define MARK_LOCK_WIDTH 60 //Lock Mark<72>ϰ<EFBFBD><CFB0>e<EFBFBD><65>
#define MARK_HEIGHT 40 //Mark<72>ϰ찪<CFB0><ECB0AA>
#define NO_VALUE -10 //<2F><><EFBFBD>s<EFBFBD>b<EFBFBD><62><EFBFBD>J<EFBFBD>T<EFBFBD><54>
#define NO_OPER_FLAG -11 //<2F><><EFBFBD>s<EFBFBD>b<EFBFBD>B<EFBFBD>
#define NO_INPUT_FLAG -12 //<2F><><EFBFBD>s<EFBFBD>b<EFBFBD><62><EFBFBD>J<EFBFBD>i<EFBFBD><69>
#define COMPUTE_ERROR -13 //<2F><><EFBFBD><EFBFBD><EFBFBD>\<5C><><EFBFBD>B<EFBFBD><42>
#define NO_BLOCK_HEAD -14 //<2F><><EFBFBD>s<EFBFBD>b<EFBFBD>s<EFBFBD><73>Block
#define NO_SEL_NUM -15 //<2F><><EFBFBD>s<EFBFBD>b<EFBFBD><62><EFBFBD><EFBFBD>Block<63>s<EFBFBD><73>
#define NO_BLK_TYPE 0 //Block<63><6B><EFBFBD>ݩ<EFBFBD><DDA9>{<7B><>type
#define BLK_IN 1 //Block<63><6B>IN
#define BLK_OUT 2 //Block<63><6B>OUT
#define BLK_AND 3 //Block<63><6B>AND
#define BLK_OR 4 //Block<63><6B>OR
#define BLK_NOT 5 //Block<63><6B>NOT
#define BLK_FUN 6 //Block<63><6B>FUN
#define ZERO 0 //FALSE flag
#define ONE 1 //TRUE flag
#define SIN 2 //Sin flag
#define COS 3 //Cos flag
#define MSEC 0.001 //millisecond
#define MAX_DATA_NUM 512 //<2F>̤j<CCA4>x<EFBFBD>sdata<74>ƥ<EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// <20><> App About <20>ϥ<EFBFBD> CAboutDlg <20><><EFBFBD>ܤ<EFBFBD><DCA4><EFBFBD>
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// <20><><EFBFBD>ܤ<EFBFBD><DCA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV <20>
// <20>{<7B><><EFBFBD>X<EFBFBD><58><EFBFBD>@
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CTestSimulatorDlg <20><><EFBFBD>ܤ<EFBFBD><DCA4><EFBFBD>
CTestSimulatorDlg::CTestSimulatorDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CTestSimulatorDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_rcWork.SetRect (0, 0, 0, 0);
m_rcClient.SetRect(0, 0, 0, 0);
m_ptLEnd.SetPoint (0, 0);
m_pOscDlg = NULL;
m_pOldBitmap = NULL;
m_clrBg = WHITE;
m_bInitDlg = FALSE;
m_bSelectBlk = FALSE;
m_bMoveBlk = FALSE;
m_bLineMode = FALSE;
m_bConnect = FALSE;
m_bDelBlk = FALSE;
m_bSimulate = FALSE;
m_bBgPic = FALSE;
m_bGrid = FALSE;
m_bLock = FALSE;
m_iWorkLeft = 150;
m_iWorkTop = 10;
m_iWorkRight = 1150;
m_iWorkBottom = 510;
m_iBlkWidth = 100;
m_iBlkHeight = 50;
m_iGridX = (int) (m_iBlkWidth / 4.);
m_iGridY = (int) (m_iBlkHeight / 2.);
m_iContainerSize = 0;
m_iSlctBlkNum = 0;
m_iHeadBlkNum = 0;
m_iSimBlkNum = 0;
m_iOutSize = 0;
m_iStep = 0;
}
void CTestSimulatorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CTestSimulatorDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_SIZE()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDBLCLK()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_IN, &CTestSimulatorDlg::OnBnClickedButtonIn)
ON_BN_CLICKED(IDC_BUTTON_OUT, &CTestSimulatorDlg::OnBnClickedButtonOut)
ON_BN_CLICKED(IDC_BUTTON_LINE, &CTestSimulatorDlg::OnBnClickedButtonLine)
ON_BN_CLICKED(IDC_BUTTON_AND, &CTestSimulatorDlg::OnBnClickedButtonAnd)
ON_BN_CLICKED(IDC_BUTTON_OR, &CTestSimulatorDlg::OnBnClickedButtonOr)
ON_BN_CLICKED(IDC_BUTTON_NOT, &CTestSimulatorDlg::OnBnClickedButtonNot)
ON_BN_CLICKED(IDC_BUTTON_FUNCTION, &CTestSimulatorDlg::OnBnClickedButtonFunction)
ON_BN_CLICKED(IDC_BUTTON_SIMULATE, &CTestSimulatorDlg::OnBnClickedButtonSimulate)
ON_BN_CLICKED(IDC_BUTTON_BGCOLOR, &CTestSimulatorDlg::OnBnClickedButtonBgcolor)
ON_BN_CLICKED(IDC_BUTTON_BGPIC, &CTestSimulatorDlg::OnBnClickedButtonBgpic)
ON_BN_CLICKED(IDC_BUTTON_OPEN, &CTestSimulatorDlg::OnBnClickedButtonOpen)
ON_BN_CLICKED(IDC_BUTTON_SAVE, &CTestSimulatorDlg::OnBnClickedButtonSave)
ON_BN_CLICKED(IDC_BUTTON_GRID, &CTestSimulatorDlg::OnBnClickedButtonGrid)
ON_BN_CLICKED(IDC_BUTTON_LOCK, &CTestSimulatorDlg::OnBnClickedButtonLock)
END_MESSAGE_MAP()
// CTestSimulatorDlg <20>T<EFBFBD><54><EFBFBD>B<EFBFBD>z<EFBFBD>`<60><>
BOOL CTestSimulatorDlg::OnInitDialog()
{
this->SetWindowPos (NULL, 0, 0, WIN_WIDTH, WIN_HEIGHT, SWP_NOZORDER | SWP_NOMOVE); //<2F>]<5D>w<EFBFBD><77><EFBFBD>ܲ<EFBFBD><DCB2>Ȥ<EFBFBD><C8A4>ϰ<EFBFBD>
m_rcWork.SetRect (m_iWorkLeft, m_iWorkTop, m_iWorkRight, m_iWorkBottom); //<2F>]<5D>w<EFBFBD>u<EFBFBD>@<40>ϰ<EFBFBD>
this->GetClientRect (&m_rcClient); //Ū<><C5AA><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2>Ȥ<EFBFBD><C8A4>ϰ<EFBFBD>
m_dcBgPic.CreateCompatibleDC (NULL); //<2F>إ߻P<DFBB><50><EFBFBD>ܲ<EFBFBD><DCB2>ۮe<DBAE><65>dc<64>A<EFBFBD>H<EFBFBD><48><EFBFBD>J<EFBFBD>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD>
CString strIniPath (_T (".\\Initial.ini")); //.ini<6E><69><EFBFBD>|
CString strAppName (_T ("BgParameter")); //.ini<6E><69>[<5B>`<60>W]
CString strBgPicBOOL; //<2F>x<EFBFBD>s<EFBFBD>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD><CFA4><EFBFBD><EFBFBD>L<EFBFBD>Ȫ<EFBFBD><C8AA>r<EFBFBD><72>
CString strBgPicPath; //<2F>x<EFBFBD>s<EFBFBD>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD><CFA4><EFBFBD><EFBFBD>|<7C><><EFBFBD>r<EFBFBD><72>
CString strBgColor; //<2F>x<EFBFBD>s<EFBFBD>I<EFBFBD><49><EFBFBD>C<EFBFBD><43><EFBFBD>Ȫ<EFBFBD><C8AA>r<EFBFBD><72>
CString strGridBOOL; //<2F>x<EFBFBD>s<EFBFBD><73><EFBFBD>I<EFBFBD><49><EFBFBD>L<EFBFBD>Ȫ<EFBFBD><C8AA>r<EFBFBD><72>
CString strLockBOOL; //<2F>x<EFBFBD>s<EFBFBD><73><EFBFBD>w<EFBFBD><77><EFBFBD>L<EFBFBD>Ȫ<EFBFBD><C8AA>r<EFBFBD><72>
CString strKeyName (_T ("BgPicBOOL")); //.ini<6E><69><EFBFBD>ܼƦW<C6A6><57>
GetPrivateProfileString (strAppName, strKeyName, _T ("None"), strBgPicBOOL.GetBuffer (MAX_STR_LEN), MAX_STR_LEN, strIniPath);
strKeyName.Format (_T ("BgPicPath"));
GetPrivateProfileString (strAppName, strKeyName, _T ("None"), strBgPicPath.GetBuffer (MAX_STR_LEN), MAX_STR_LEN, strIniPath);
strKeyName.Format (_T ("BgColor"));
GetPrivateProfileString (strAppName, strKeyName, _T ("None"), strBgColor.GetBuffer (MAX_STR_LEN), MAX_STR_LEN, strIniPath);
strKeyName.Format (_T ("GridBOOL"));
GetPrivateProfileString (strAppName, strKeyName, _T ("None"), strGridBOOL.GetBuffer (MAX_STR_LEN), MAX_STR_LEN, strIniPath);
strKeyName.Format (_T ("LockBOOL"));
GetPrivateProfileString (strAppName, strKeyName, _T ("None"), strLockBOOL.GetBuffer (MAX_STR_LEN), MAX_STR_LEN, strIniPath);
//<2F><><EFBFBD>J<EFBFBD>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD>(or<6F>C<EFBFBD><43>)
if (strBgPicBOOL == _T ("TRUE"))
{
m_strPicPath = strBgPicPath;
//<2F><4E><C5AA><EFBFBD><EFBFBD>.bmp<6D><70><EFBFBD>w<EFBFBD><77>HBITMAP
HBITMAP hbBgPic;
//<2F>Q<EFBFBD><51>HBITMAP<41>[<5B><><EFBFBD><EFBFBD><EFBFBD>ϡALoadImage (handle, <20>Ϥ<EFBFBD><CFA4><EFBFBD><EFBFBD>|, <20><><EFBFBD>J<EFBFBD>˦<EFBFBD>, <20>ϥܼe<DCBC><65>(<28><><EFBFBD><EFBFBD>), <20>ϥܪ<CFA5><DCAA><EFBFBD>(<28><><EFBFBD><EFBFBD>), LR_LOADFROMFILE: <20>ھڸ<DABE><DAB8>|<7C><><EFBFBD>ȸ˦b<CBA6>Ϲ<EFBFBD>)
hbBgPic = (HBITMAP)::LoadImage (AfxGetInstanceHandle (), m_strPicPath, IMAGE_BITMAP, m_rcWork.Width (), m_rcWork.Height (), LR_LOADFROMFILE);
m_bitmapBgPic.Attach (hbBgPic);
m_pOldBitmap = m_dcBgPic.SelectObject (&m_bitmapBgPic);
m_bBgPic = TRUE;
}
else if (strBgPicBOOL == _T ("FALSE"))
m_clrBg = _ttoi (strBgColor);
//<2F>]<5D>w<EFBFBD><77><EFBFBD>I<EFBFBD><49><EFBFBD>l<EFBFBD><6C><EFBFBD>A
if (strGridBOOL == _T ("TRUE"))
m_bGrid = TRUE;
//<2F><><EFBFBD>J<EFBFBD><4A><EFBFBD>w<EFBFBD><77><EFBFBD>l<EFBFBD><6C><EFBFBD>A
if (strLockBOOL == _T ("TRUE"))
m_bLock = TRUE;
CDialogEx::OnInitDialog();
// <20>N [<5B><><EFBFBD><EFBFBD>...] <20>\<5C><><EFBFBD><EFBFBD><EFBFBD>[<5B>J<EFBFBD>t<EFBFBD>Υ\<5C><><EFBFBD><EFBFBD><EFBFBD>C
// IDM_ABOUTBOX <20><><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD>t<EFBFBD>ΩR<CEA9>O<EFBFBD>d<EFBFBD>򤧤<EFBFBD><F2A4A7A4>C
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// <20>]<5D>w<EFBFBD><77><EFBFBD><EFBFBD><EFBFBD>ܤ<EFBFBD><DCA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϥܡC<DCA1><43><EFBFBD><EFBFBD><EFBFBD>ε{<7B><><EFBFBD><EFBFBD><EFBFBD>D<EFBFBD><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>O<EFBFBD><4F><EFBFBD>ܤ<EFBFBD><DCA4><EFBFBD><EFBFBD>ɡA
// <20>ج[<5B>|<7C>۰ʱq<CAB1>Ʀ<EFBFBD><C6A6>@<40>~
SetIcon(m_hIcon, TRUE); // <20>]<5D>w<EFBFBD>j<EFBFBD>ϥ<EFBFBD>
SetIcon(m_hIcon, FALSE); // <20>]<5D>w<EFBFBD>p<EFBFBD>ϥ<EFBFBD>
m_bInitDlg = TRUE;
return TRUE; // <20>Ǧ^ TRUE<55>A<EFBFBD><41><EFBFBD>D<EFBFBD>z<EFBFBD><EFBFBD><EFBFBD>]<5D>w<EFBFBD>J<EFBFBD>I
}
void CTestSimulatorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// <20>p<EFBFBD>G<EFBFBD>N<EFBFBD>̤p<CCA4>ƫ<EFBFBD><C6AB>s<EFBFBD>[<5B>J<EFBFBD>z<EFBFBD><7A><EFBFBD><EFBFBD><EFBFBD>ܤ<EFBFBD><DCA4><EFBFBD><EFBFBD>A<EFBFBD>z<EFBFBD>ݭn<DDAD>U<EFBFBD>C<EFBFBD><43><EFBFBD>{<7B><><EFBFBD>X<EFBFBD>A
// <20>H<EFBFBD><4B>s<EFBFBD>ϥܡC<DCA1><43><EFBFBD><EFBFBD><EFBFBD>ϥΤ<CFA5><CEA4><EFBFBD>/<2F>˵<EFBFBD><CBB5>Ҧ<EFBFBD><D2A6><EFBFBD> MFC <20><><EFBFBD>ε{<7B><><EFBFBD>A
// <20>ج[<5B>|<7C>۰ʧ<DBB0><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>@<40>~<7E>C
void CTestSimulatorDlg::OnPaint ()
{
//<2F><><EFBFBD>w<EFBFBD>īإ<C4AB>
CPaintDC dcSim (this); //<2F>D<EFBFBD><44><EFBFBD>ܲ<EFBFBD>dc
CDC dcMem; //<2F><><EFBFBD>sdc
CBitmap bitmapMem;
CBitmap * pOldBitmap;
dcMem.CreateCompatibleDC (&dcSim); //<2F>إ߻P<DFBB>D<EFBFBD><44><EFBFBD>ܲ<EFBFBD><DCB2>ۮe<DBAE><65>dc
bitmapMem.CreateCompatibleBitmap (&dcSim, m_iWorkRight, m_iWorkBottom);
pOldBitmap = dcMem.SelectObject (&bitmapMem);
//ø<>s<EFBFBD>I<EFBFBD><49>
dcMem.SetBkMode (TRANSPARENT);
dcMem.FillSolidRect (m_rcWork, m_clrBg);
//<2F>Ҧ<EFBFBD>Mark<72><6B>rect
CPoint ptMarkTL (m_iWorkRight - MARK_WIDTH, m_iWorkTop);
CPoint ptMarkBR (m_iWorkRight, m_iWorkTop + MARK_HEIGHT);
CRect rcModeMark (ptMarkTL, ptMarkBR);
//<2F>Ҧ<EFBFBD>Mark<72>r<EFBFBD><72>
CFont fontModeMark, * pOldFont;
fontModeMark.CreatePointFont (MARK_FONTSIZE, _T ("Arial"), &dcMem);
//<2F>Ѧs<D1A6><73><EFBFBD>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD><CFA4><EFBFBD>dc<64><63><EFBFBD><EFBFBD><EFBFBD>ܤ<EFBFBD><DCA4>sdc
if (m_bBgPic)
dcMem.BitBlt (m_iWorkLeft, m_iWorkTop, m_rcWork.Width (), m_rcWork.Height (), &m_dcBgPic, 0, 0, SRCCOPY);
//ø<>s<EFBFBD><73><EFBFBD>I
if (m_bGrid)
{
CBrush brushGray (GRAY);
CBrush* pOldBrush;
pOldBrush = dcMem.SelectObject (&brushGray);
for (int i = m_iWorkLeft; i < m_iWorkRight; i += m_iGridX)
{
for (int j = m_iWorkTop; j < m_iWorkBottom; j += m_iGridY)
dcMem.Ellipse (CRect (i - GRID_R, j - GRID_R, i + GRID_R, j + GRID_R));
}
dcMem.SelectObject (pOldBrush);
}
//ø<>s<EFBFBD><73><EFBFBD>wMark
if (m_bLock)
{
CPoint ptLockMarkTL (m_iWorkLeft, m_iWorkTop);
CPoint ptLockMarkBR (m_iWorkLeft + MARK_LOCK_WIDTH, m_iWorkTop + MARK_HEIGHT);
CRect rcLockMark (ptLockMarkTL, ptLockMarkBR);
pOldFont = dcMem.SelectObject (&fontModeMark);
dcMem.DrawText (_T ("Lock"), -1, &rcLockMark, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
dcMem.SelectObject (pOldFont);
}
//ø<>sBlock<63>s<EFBFBD>u
for (int i = 0; i < m_iContainerSize; i++)
m_vcBlkContainer[i]->DrawLine (&dcMem);
//ø<>s<EFBFBD><73><EFBFBD><EFBFBD>Block<63><6B><EFBFBD><EFBFBD>
if (m_bSelectBlk)
{
if (m_iSlctBlkNum >= 0 && m_iSlctBlkNum < m_iContainerSize)
{
CPen penLightBlue (PS_SOLID, 10, LIGHT_BLUE);
CPen* pOldPen;
pOldPen = dcMem.SelectObject (&penLightBlue);
dcMem.Rectangle (m_vcBlkContainer[m_iSlctBlkNum]->GetBlkRect ());
dcMem.SelectObject (pOldPen);
}
}
//ø<>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD>Ҧ<EFBFBD>Mark<72>P<EFBFBD><50><EFBFBD><EFBFBD>Block<63><6B><EFBFBD><EFBFBD>
if (m_bSimulate)
{
//ø<>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD>Ҧ<EFBFBD>Mark
pOldFont = dcMem.SelectObject (&fontModeMark);
dcMem.DrawText (_T ("Simulation"), -1, &rcModeMark, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
dcMem.SelectObject (pOldFont);
//ø<>s<EFBFBD><73><EFBFBD><EFBFBD>Block<63><6B><EFBFBD><EFBFBD>
CPen penRed (PS_SOLID, 10, RED);
CPen* pOldPen;
pOldPen = dcMem.SelectObject (&penRed);
dcMem.Rectangle (m_vcBlkContainer[m_iSimBlkNum]->GetBlkRect ());
dcMem.SelectObject (pOldPen);
}
//ø<>sBlock
for (int i = 0; i < m_iContainerSize; i++)
m_vcBlkContainer[i]->Draw (&dcMem);
//ø<>s<EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>Mark<72>P<EFBFBD>s<EFBFBD>u<EFBFBD><75><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>u<EFBFBD>u<EFBFBD>q
if (m_bLineMode)
{
//ø<>s<EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>Mar
pOldFont = dcMem.SelectObject (&fontModeMark);
dcMem.DrawText (_T ("LineMode"), -1, &rcModeMark, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
dcMem.SelectObject (pOldFont);
//ø<>s<EFBFBD>s<EFBFBD>u<EFBFBD><75><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>u<EFBFBD>u<EFBFBD>q
if (m_bConnect)
{
CPen penBlack (PS_DASH, 1, BLACK);
CPen* pOldPen;
pOldPen = dcMem.SelectObject (&penBlack);
CPoint ptLStart = m_vcBlkContainer[m_iHeadBlkNum]->GetPinOutRect ().CenterPoint (); //<2F>u<EFBFBD>q<EFBFBD>_<EFBFBD>I<EFBFBD><49>Block<63><6B><EFBFBD>XPin<69><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>I
int iCornerGridY = (int) (((ptLStart.y + m_ptLEnd.y) / 2. - m_iWorkTop) / m_iGridY + 0.5); //<2F>s<EFBFBD>u<EFBFBD><75><EFBFBD><EFBFBD><EFBFBD>B<EFBFBD>Z<EFBFBD>u<EFBFBD>@<40>ϤW<CFA4><57><EFBFBD>X<EFBFBD>Ӯ<EFBFBD><D3AE>I
int iCornerY = iCornerGridY * m_iGridY + m_iWorkTop; //<2F>s<EFBFBD>u<EFBFBD><75><EFBFBD><EFBFBD><EFBFBD>BY<42>y<EFBFBD><79>
dcMem.MoveTo (ptLStart);
dcMem.LineTo (CPoint (ptLStart.x, iCornerY));
dcMem.MoveTo (CPoint (ptLStart.x, iCornerY));
dcMem.LineTo (CPoint (m_ptLEnd.x, iCornerY));
dcMem.MoveTo (CPoint (m_ptLEnd.x, iCornerY));
dcMem.LineTo (m_ptLEnd);
dcMem.SelectObject (pOldPen);
}
}
//<2F>Ѥ<EFBFBD><D1A4>sdc<64><63><EFBFBD><EFBFBD><EFBFBD>ܥD<DCA5><44><EFBFBD>ܲ<EFBFBD>dc
dcSim.BitBlt (m_iWorkLeft, m_iWorkTop, m_rcWork.Width (), m_rcWork.Height (), &dcMem, m_iWorkLeft, m_iWorkTop, SRCCOPY);
//<2F>M<EFBFBD>z
dcMem.SelectObject (pOldBitmap);
bitmapMem.DeleteObject ();
dcMem.DeleteDC ();
}
// <20><><EFBFBD>ϥΪ̩즲<CCA9>̤p<CCA4>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>ɡA
// <20>t<EFBFBD>ΩI<CEA9>s<EFBFBD>o<EFBFBD>ӥ\<5C><><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܡC
HCURSOR CTestSimulatorDlg::OnQueryDragIcon ()
{
return static_cast<HCURSOR>(m_hIcon);
}
//<2F><><EFBFBD>UIN<49><4E><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonIn ()
{
m_bLineMode = FALSE; //<2F><><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>
CBlockBasis* pBlk = new CBlockIn; //new<65>@<40><>CBlockIn<49><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //<2F>]<5D>wBlock In<49><6E>rect
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //<2F>]<5D>wBlock<63>s<EFBFBD><73>
m_vcBlkContainer.push_back (pBlk); //<2F>s<EFBFBD>JBlock<63><6B>vector<6F><72>
m_iContainerSize = (int) m_vcBlkContainer.size (); //<2F><><EFBFBD><EFBFBD>Block<63><6B>vector size
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//<2F><><EFBFBD>UOUT<55><54><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonOut ()
{
m_bLineMode = FALSE; //<2F><><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>
CBlockBasis* pBlk = new CBlockOut; //new<65>@<40><>CBlockOut<75><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //<2F>]<5D>wBlock Out<75><74>rect
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //<2F>]<5D>wBlock<63>s<EFBFBD><73>
m_vcBlkContainer.push_back (pBlk); //<2F>s<EFBFBD>JBlock<63><6B>vector<6F><72>
m_iContainerSize = (int) m_vcBlkContainer.size (); //<2F><><EFBFBD><EFBFBD>Block<63><6B>vector size
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//<2F><><EFBFBD>UAND<4E><44><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonAnd ()
{
m_bLineMode = FALSE; //<2F><><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>
CBlockBasis* pBlk = new CBlockAnd; //new<65>@<40><>CBlockAnd<6E><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //<2F>]<5D>wBlock And<6E><64>rect
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //<2F>]<5D>wBlock<63>s<EFBFBD><73>
m_vcBlkContainer.push_back (pBlk); //<2F>s<EFBFBD>JBlock<63><6B>vector<6F><72>
m_iContainerSize = (int) m_vcBlkContainer.size (); //<2F><><EFBFBD><EFBFBD>Block<63><6B>vector size
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//<2F><><EFBFBD>UOR<4F><52><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonOr ()
{
m_bLineMode = FALSE; //<2F><><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>
CBlockBasis* pBlk = new CBlockOr; //new<65>@<40><>CBlockOr<4F><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //<2F>]<5D>wBlock Or<4F><72>rect
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //<2F>]<5D>wBlock<63>s<EFBFBD><73>
m_vcBlkContainer.push_back (pBlk); //<2F>s<EFBFBD>JBlock<63><6B>vector<6F><72>
m_iContainerSize = (int) m_vcBlkContainer.size (); //<2F><><EFBFBD><EFBFBD>Block<63><6B>vector size
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//<2F><><EFBFBD>UNOT<4F><54><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonNot ()
{
m_bLineMode = FALSE; //<2F><><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>
CBlockBasis* pBlk = new CBlockNot; //new<65>@<40><>CBlockNot<6F><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //<2F>]<5D>wBlock Not<6F><74>rect
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //<2F>]<5D>wBlock<63>s<EFBFBD><73>
m_vcBlkContainer.push_back (pBlk); //<2F>s<EFBFBD>JBlock<63><6B>vector<6F><72>
m_iContainerSize = (int) m_vcBlkContainer.size (); //<2F><><EFBFBD><EFBFBD>Block<63><6B>vector size
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//<2F><><EFBFBD>UFunction<6F><6E><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonFunction ()
{
m_bLineMode = FALSE; //<2F><><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>
CBlockBasis* pBlk = new CBlockFun; //new<65>@<40><>CBlockFun<75><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //<2F>]<5D>wBlock Fun<75><6E>rect
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //<2F>]<5D>wBlock<63>s<EFBFBD><73>
m_vcBlkContainer.push_back (pBlk); //<2F>s<EFBFBD>JBlock<63><6B>vector<6F><72>
m_iContainerSize = (int) m_vcBlkContainer.size (); //<2F><><EFBFBD><EFBFBD>Block<63><6B>vector size
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//<2F><><EFBFBD>ULine<6E><65><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonLine ()
{
//<2F>]<5D>w<EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD><D2A6>í<EFBFBD>ø<EFBFBD>u<EFBFBD>@<40><>
if (!m_bSimulate)
{
if (m_bLineMode)
m_bLineMode = FALSE;
else
{
if (!m_vcBlkContainer.empty ())
{
m_bLineMode = TRUE;
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
}
}
}
//<2F><><EFBFBD>USimulate<74><65><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonSimulate ()
{
if (!m_bSimulate)
{
if (m_bSelectBlk && m_iSlctBlkNum >= 0 && m_iSlctBlkNum < m_iContainerSize &&
m_vcBlkContainer[m_iSlctBlkNum]->BlkTypeIs () == BLK_OUT && m_vcBlkContainer[m_iSlctBlkNum]->GetBlkHeadSize () > 0)
{
m_iSimBlkNum = m_iSlctBlkNum; //<2F>]<5D>w<EFBFBD><77><EFBFBD><EFBFBD>Block<63>s<EFBFBD><73>
m_bSimulate = TRUE; //<2F>]<5D>w<EFBFBD><77><EFBFBD><EFBFBD><EFBFBD>Ҧ<EFBFBD>
m_bLineMode = FALSE; //<2F><><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>
m_bDelBlk = FALSE; //<2F>T<EFBFBD><54><EFBFBD>R<EFBFBD><52>Block
//<2F>Y<EFBFBD>ܪi<DCAA><69><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD>Х<EFBFBD><D0A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>w<EFBFBD>O<EFBFBD><4F><EFBFBD><EFBFBD><EFBFBD>A<EFBFBD>hnew<65>@<40>ӥܪi<DCAA><69><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD>
if (m_pOscDlg == NULL)
{
m_pOscDlg = new COscDlg (this);
m_pOscDlg->Create (IDD_DIALOG_OSC, this);
m_pOscDlg->SetWindowPos (this, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
m_pOscDlg->UpdateData (FALSE);
}
else
{
m_pOscDlg->ShowWindow (SW_SHOW);
m_pOscDlg->UpdateData (FALSE);
}
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
else
MessageBox (_T ("Please select output block and check if it is connected."));
}
}
//<2F><><EFBFBD>UGrid<69><64><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonGrid ()
{
//<2F>]<5D>w<EFBFBD><77><EFBFBD>I<EFBFBD>Ҧ<EFBFBD>
if (!m_bGrid)
m_bGrid = TRUE;
else
{
m_bGrid = FALSE;
m_bLock = FALSE;
}
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//<2F><><EFBFBD>ULock<63><6B><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonLock ()
{
if (m_bGrid)
{
if (!m_bLock)
{
m_bLock = TRUE; //<2F>]<5D>w<EFBFBD><77><EFBFBD>w<EFBFBD>Ҧ<EFBFBD>
//<2F>]<5D>w<EFBFBD>{<7B><>Block<63><6B><EFBFBD>w<EFBFBD><77><EFBFBD>̬<EFBFBD><CCAC>F<EFBFBD>񪺮<EFBFBD><F1AABAAE>I<EFBFBD>W
for (int i = 0; i < m_iContainerSize; i++)
{
int GridX = (int) ((m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().x - m_iWorkLeft) / (double) m_iGridX + 0.5);
int GridY = (int) ((m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().y - m_iWorkTop) / (double) m_iGridY + 0.5);
m_vcBlkContainer[i]->SetBlkRect (CPoint (GridX * m_iGridX + m_iWorkLeft, GridY * m_iGridY + m_iWorkTop), m_iBlkWidth, m_iBlkHeight);
}
}
else
m_bLock = FALSE;
}
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//<2F><><EFBFBD>U<EFBFBD>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD><CFA4><EFBFBD><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonBgpic ()
{
//<2F>إ<EFBFBD>CFileDialog (TRUE<55>}<7D><><EFBFBD>ɮ<EFBFBD>, <20>w<EFBFBD>]<5D><><EFBFBD><EFBFBD><EFBFBD>ɦW, <20><><EFBFBD>l<EFBFBD>ɮצW, OFN_HIDEREADONLY: <20><><EFBFBD><EFBFBD>, <20>z<EFBFBD><7A>)
CFileDialog fileDlg (TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, _T (" bitmap (*.bmp)|*.bmp||"));
//<2F>YFile<6C><65><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD>U<EFBFBD>T<EFBFBD>w<EFBFBD><77>
if (fileDlg.DoModal () == IDOK)
{
m_strPicPath = fileDlg.GetPathName (); //Ū<><C5AA><EFBFBD>ɮ׸<C9AE><D7B8>|
//<2F><4E><C5AA><EFBFBD><EFBFBD>.bmp<6D><70><EFBFBD>w<EFBFBD><77>HBITMAP
HBITMAP hbBgPic;
hbBgPic = (HBITMAP)::LoadImage (AfxGetInstanceHandle (), m_strPicPath, IMAGE_BITMAP, m_rcWork.Width (), m_rcWork.Height (), LR_LOADFROMFILE);
m_bitmapBgPic.Detach ();
m_bitmapBgPic.Attach (hbBgPic);
//<2F>ȩ󭺦<C8A9><F3ADBAA6><EFBFBD><EFBFBD>J<EFBFBD>Ϥ<EFBFBD><CFA4>ɬ<EFBFBD><C9AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>lbitmap<61><70><EFBFBD><EFBFBD>
if (!m_bBgPic)
m_pOldBitmap = m_dcBgPic.SelectObject (&m_bitmapBgPic);
else
m_dcBgPic.SelectObject (&m_bitmapBgPic);
m_bBgPic = TRUE;
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
}
//<2F><><EFBFBD>U<EFBFBD>I<EFBFBD><49><EFBFBD>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonBgcolor ()
{
//<2F>إߦ<D8A5><DFA6>m<EFBFBD><6D><EFBFBD>ܲ<EFBFBD>
CColorDialog clrDlg (m_clrBg, CC_PREVENTFULLOPEN);
//<2F>Y<EFBFBD><59><EFBFBD>m<EFBFBD><6D><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD>U<EFBFBD>T<EFBFBD>w<EFBFBD><77>
if (clrDlg.DoModal () == IDOK)
{
if (m_bBgPic && m_pOldBitmap != NULL)
{
m_dcBgPic.SelectObject (m_pOldBitmap);
m_bBgPic = FALSE;
}
m_clrBg = clrDlg.GetColor (); //<2F>]<5D>w<EFBFBD>I<EFBFBD><49><EFBFBD>C<EFBFBD><43>
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
}
//<2F><><EFBFBD>UOpen<65><6E><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonOpen ()
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ҧ<EFBFBD><D2A6>U<EFBFBD><55><EFBFBD>i<EFBFBD>i<EFBFBD><69>Ū<EFBFBD><C5AA>
if (!m_bSimulate)
{
//<2F>إ<EFBFBD>CFileDialog (TRUE<55>}<7D><><EFBFBD>ɮ<EFBFBD>, <20>w<EFBFBD>]<5D><><EFBFBD><EFBFBD><EFBFBD>ɦW, <20><><EFBFBD>l<EFBFBD>ɮצW, OFN_HIDEREADONLY: <20><><EFBFBD><EFBFBD>, <20>z<EFBFBD><7A>)
CFileDialog fileDlg (TRUE, _T ("txt"), NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, _T (" txt (*.txt)|*.txt||"));
//<2F>إ<EFBFBD>CStdioFile<6C><48><C5AA><EFBFBD>ɮ׸<C9AE><D7B8><EFBFBD>
CStdioFile fileSim;
//<2F>Y<EFBFBD>ɮ׹<C9AE><D7B9>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD>U<EFBFBD>T<EFBFBD>w<EFBFBD><77>
if (fileDlg.DoModal () == IDOK)
{
//<2F>}<7D><><EFBFBD>ɮ<EFBFBD> (<28>ɮ׸<C9AE><D7B8>|, CFile::modeNoTruncate: <20><><EFBFBD>M<EFBFBD>Ť<EFBFBD><C5A4>󤺮e | CFile::modeRead: <20><>Ū)
fileSim.Open (fileDlg.GetPathName (), CFile::modeNoTruncate | CFile::modeRead);
CString strData; //<2F>x<EFBFBD>s<EFBFBD>C<EFBFBD>@<40>C<EFBFBD>r<EFBFBD><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CStringArray strArray; //<2F>x<EFBFBD>s<EFBFBD>C<EFBFBD>@Block<63>U<EFBFBD><55><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
fileSim.ReadString (strData); //Ū<><C5AA><EFBFBD>ɮ׸<C9AE><D7B8>ƶi<C6B6>r<EFBFBD><72>
if (strData == "BlockData: ") //<2F><><EFBFBD>ƶ}<7D>Y<EFBFBD><59><EFBFBD><EFBFBD>BlockDate
{
//Ū<><C5AA><EFBFBD>ɮ׮ɨ<D7AE><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Block
m_bSelectBlk = FALSE;
m_iSlctBlkNum = NO_SEL_NUM;
//<2F>M<EFBFBD><4D><EFBFBD>ܪi<DCAA><69><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD>
if (m_pOscDlg != NULL)
{
m_pOscDlg->DestroyWindow ();
delete m_pOscDlg;
m_pOscDlg = NULL;
}
//<2F>M<EFBFBD><4D><EFBFBD>s<EFBFBD><73>Block<63><6B>vector
for (int i = 0; i < m_iContainerSize; i++)
delete m_vcBlkContainer[i];
std::vector <CBlockBasis*> ().swap (m_vcBlkContainer);
//<2F>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD>ɮ<EFBFBD>Ū<EFBFBD><C5AA><EFBFBD>@<40><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while (fileSim.ReadString (strData))
{
SplitString (strData, ',', strArray); //<2F><4E><C5AA><EFBFBD><EFBFBD>r<EFBFBD><72><EFBFBD><EFBFBD><EFBFBD>j<EFBFBD><6A>Block<63>U<EFBFBD><55><EFBFBD><EFBFBD><EFBFBD>ơA<C6A1><41><EFBFBD>x<EFBFBD>s<EFBFBD>ܰ}<7D>C<EFBFBD><43>
if (strArray[0] == "IN") //Block In<49><6E><EFBFBD>Ƥ<EFBFBD><C6A4>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20>i<EFBFBD><69>flag
{
CBlockBasis* pBlk = new CBlockIn;
pBlk->SetBlkRect (CPoint (_ttoi (strArray[1]), _ttoi (strArray[2])), m_iBlkWidth, m_iBlkHeight);
pBlk->SetInputFlag (_ttoi (strArray[3]));
pBlk->SetBlkValue ();
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ());
m_vcBlkContainer.push_back (pBlk);
m_iContainerSize = (int) m_vcBlkContainer.size ();
}
else if (strArray[0] == "OUT") //Block Out<75><74><EFBFBD>Ƥ<EFBFBD><C6A4>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20><><EFBFBD>Jchannel<65>ƥ<EFBFBD>, <20><><EFBFBD>JBlock<63>s<EFBFBD><73>
{
CBlockBasis* pBlk = new CBlockOut;
pBlk->SetBlkRect (CPoint (_ttoi (strArray[1]), _ttoi (strArray[2])), m_iBlkWidth, m_iBlkHeight);
int iBlkHeadSize = _ttoi (strArray[3]);
for (int i = 0; i < iBlkHeadSize; i++)
{
pBlk->SetBlkHead1Num (_ttoi (strArray[4 + i]));
pBlk->SetBlkHeadSize (FALSE);
}
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ());
m_vcBlkContainer.push_back (pBlk);
m_iContainerSize = (int) m_vcBlkContainer.size ();
}
else if (strArray[0] == "AND") //Block And<6E><64><EFBFBD>Ƥ<EFBFBD><C6A4>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20><><EFBFBD>JBlock<63>s<EFBFBD><73>
{
CBlockBasis* pBlk = new CBlockAnd;
pBlk->SetBlkRect (CPoint (_ttoi (strArray[1]), _ttoi (strArray[2])), m_iBlkWidth, m_iBlkHeight);
pBlk->SetBlkHead1Num (_ttoi (strArray[3]));
pBlk->SetBlkHead2Num (_ttoi (strArray[4]));
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ());
m_vcBlkContainer.push_back (pBlk);
m_iContainerSize = (int) m_vcBlkContainer.size ();
}
else if (strArray[0] == "OR") //Block Or<4F><72><EFBFBD>Ƥ<EFBFBD><C6A4>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20><><EFBFBD>JBlock<63>s<EFBFBD><73>
{
CBlockBasis* pBlk = new CBlockOr;
pBlk->SetBlkRect (CPoint (_ttoi (strArray[1]), _ttoi (strArray[2])), m_iBlkWidth, m_iBlkHeight);
pBlk->SetBlkHead1Num (_ttoi (strArray[3]));
pBlk->SetBlkHead2Num (_ttoi (strArray[4]));
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ());
m_vcBlkContainer.push_back (pBlk);
m_iContainerSize = (int) m_vcBlkContainer.size ();
}
else if (strArray[0] == "NOT") //Block Not<6F><74><EFBFBD>Ƥ<EFBFBD><C6A4>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20><><EFBFBD>JBlock<63>s<EFBFBD><73>
{
CBlockBasis* pBlk = new CBlockNot;
pBlk->SetBlkRect (CPoint (_ttoi (strArray[1]), _ttoi (strArray[2])), m_iBlkWidth, m_iBlkHeight);
pBlk->SetBlkHead1Num (_ttoi (strArray[3]));
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ());
m_vcBlkContainer.push_back (pBlk);
m_iContainerSize = (int) m_vcBlkContainer.size ();
}
else if (strArray[0] == "FUN") //Block Fun<75><6E><EFBFBD>Ƥ<EFBFBD><C6A4>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20><><EFBFBD>JBlock<63>s<EFBFBD><73>, <20>B<EFBFBD>⤸flag
{
CBlockBasis* pBlk = new CBlockFun;
pBlk->SetBlkRect (CPoint (_ttoi (strArray[1]), _ttoi (strArray[2])), m_iBlkWidth, m_iBlkHeight);
pBlk->SetBlkHead1Num (_ttoi (strArray[3]));
pBlk->SetBlkHead2Num (_ttoi (strArray[4]));
pBlk->SetOperFlag (_ttoi (strArray[5]));
pBlk->SetBlkNum ((int) m_vcBlkContainer.size ());
m_vcBlkContainer.push_back (pBlk);
m_iContainerSize = (int) m_vcBlkContainer.size ();
}
}
//<2F><><EFBFBD><EFBFBD>Ū<EFBFBD><C5AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD>ɮ<EFBFBD>
fileSim.Close ();
//<2F><>Ū<EFBFBD><C5AA><EFBFBD><EFBFBD><ECAABA><EFBFBD>JBlock<63>s<EFBFBD><73><EFBFBD>A<EFBFBD><41><EFBFBD>s<EFBFBD>]<5D>w<EFBFBD>C<EFBFBD>@Block<63><6B><EFBFBD>s<EFBFBD><73>Block<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_iContainerSize = (int) m_vcBlkContainer.size ();
for (int i = 0; i < m_iContainerSize; i++)
{
if (!(m_vcBlkContainer[i]->BlkTypeIs () == BLK_OUT))
{
int iHeadBlk1Num = m_vcBlkContainer[i]->GetBlkHead1Num ();
if (iHeadBlk1Num >= 0)
m_vcBlkContainer[i]->SetBlkHead1Ptr (m_vcBlkContainer[iHeadBlk1Num]);
int iHeadBlk2Num = m_vcBlkContainer[i]->GetBlkHead2Num ();
if (iHeadBlk2Num >= 0)
m_vcBlkContainer[i]->SetBlkHead2Ptr (m_vcBlkContainer[iHeadBlk2Num]);
}
else
{
int iBlkHeadSize = m_vcBlkContainer[i]->GetBlkHeadSize ();
for (int j = 0; j < iBlkHeadSize; j++)
{
int iBlkHeadNum = m_vcBlkContainer[i]->GetBlkHead1Num (j);
m_vcBlkContainer[i]->SetBlkHead1Ptr (m_vcBlkContainer[iBlkHeadNum]);
}
}
}
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
else
fileSim.Close ();
}
}
}
//<2F><><EFBFBD>USave<76><65><EFBFBD>s
void CTestSimulatorDlg::OnBnClickedButtonSave ()
{
//<2F>إ<EFBFBD>CFileDialog (FALSE<53>x<EFBFBD>s<EFBFBD>ɮ<EFBFBD>, <20>w<EFBFBD>]<5D><><EFBFBD><EFBFBD><EFBFBD>ɦW, <20><><EFBFBD>l<EFBFBD>ɮצW, OFN_HIDEREADONLY: <20><><EFBFBD><EFBFBD>, <20>z<EFBFBD><7A>)
CFileDialog fileDlg (FALSE, _T ("txt"), _T ("Simulator"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T (" txt (*.txt)|*.txt||"));
//<2F>إ<EFBFBD>CStdioFile<6C>H<EFBFBD>x<EFBFBD>s<EFBFBD><73><EFBFBD><EFBFBD>
CStdioFile fileSim;
//<2F>Y<EFBFBD>ɮ׹<C9AE><D7B9>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD>U<EFBFBD>T<EFBFBD>w<EFBFBD><77>
if (fileDlg.DoModal () == IDOK)
{
// <20>}<7D><><EFBFBD>ɮ<EFBFBD> (<28>ɮ׸<C9AE><D7B8>|, CFile::modeCreate: <20>H<EFBFBD>s<EFBFBD>ؤ覡<D8A4><E8A6A1><EFBFBD>} | CFile::modeWrite: <20>u<EFBFBD>g)
fileSim.Open (fileDlg.GetPathName (), CFile::modeCreate | CFile::modeWrite);
CString strData; //<2F>ΥH<CEA5>g<EFBFBD>J<EFBFBD>ɮת<C9AE><D7AA>r<EFBFBD><72>
strData.Format (_T ("BlockData: \n"));
fileSim.WriteString (strData);
for (int i = 0; i < m_iContainerSize; i++)
{
int iBlkFlag = m_vcBlkContainer[i]->BlkTypeIs ();
switch (iBlkFlag)
{
case BLK_IN: //Block In<49><6E><EFBFBD>x<EFBFBD>s<EFBFBD><73><EFBFBD>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20>i<EFBFBD><69>flag
strData.Format (_T ("%3s, %3d, %3d, %2d\n"), "IN", m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().x, m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().y,
m_vcBlkContainer[i]->GetInputFlag ());
break;
case BLK_OUT: //Block Out<75><74><EFBFBD>x<EFBFBD>s<EFBFBD><73><EFBFBD>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20><><EFBFBD>Jchannel<65>ƥ<EFBFBD>, <20><><EFBFBD>JBlock<63>s<EFBFBD><73>
strData.Format (_T ("%3s, %3d, %3d, %1d"), "OUT", m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().x, m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().y,
m_vcBlkContainer[i]->GetBlkHeadSize ());
for (int j = 0; j < m_vcBlkContainer[i]->GetBlkHeadSize (); j++)
{
CString strNum;
strNum.Format (_T ("%1d"), m_vcBlkContainer[i]->GetBlkHead1Num (j));
strData.Append (_T (", "));
strData.Append (strNum);
}
strData.Append (_T ("\n"));
break;
case BLK_AND: //Block And<6E><64><EFBFBD>x<EFBFBD>s<EFBFBD><73><EFBFBD>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20><><EFBFBD>JBlock<63>s<EFBFBD><73>
strData.Format (_T ("%3s, %3d, %3d, %1d, %1d\n"), "AND", m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().x, m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().y,
m_vcBlkContainer[i]->GetBlkHead1Num (), m_vcBlkContainer[i]->GetBlkHead2Num ());
break;
case BLK_OR: //Block Or<4F><72><EFBFBD>x<EFBFBD>s<EFBFBD><73><EFBFBD>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20><><EFBFBD>JBlock<63>s<EFBFBD><73>
strData.Format (_T ("%3s, %3d, %3d, %1d, %1d\n"), "OR", m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().x, m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().y,
m_vcBlkContainer[i]->GetBlkHead1Num (), m_vcBlkContainer[i]->GetBlkHead2Num ());
break;
case BLK_NOT: //Block Not<6F><74><EFBFBD>x<EFBFBD>s<EFBFBD><73><EFBFBD>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20><><EFBFBD>JBlock<63>s<EFBFBD><73>
strData.Format (_T ("%3s, %3d, %3d, %1d\n"), "NOT", m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().x, m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().y,
m_vcBlkContainer[i]->GetBlkHead1Num ());
break;
case BLK_FUN: //Block Fun<75><6E><EFBFBD>x<EFBFBD>s<EFBFBD><73><EFBFBD>e<EFBFBD>]<5D>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>m, <20><><EFBFBD>JBlock<63>s<EFBFBD><73>, <20>B<EFBFBD>⤸flag
strData.Format (_T ("%3s, %3d, %3d, %1d, %1d, %2d\n"), "FUN", m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().x, m_vcBlkContainer[i]->GetBlkRect ().CenterPoint ().y,
m_vcBlkContainer[i]->GetBlkHead1Num (), m_vcBlkContainer[i]->GetBlkHead2Num (), m_vcBlkContainer[i]->GetOperFlag ());
break;
default:
break;
}
fileSim.WriteString (strData); //<2F>N<EFBFBD>r<EFBFBD><EFBFBD>e<EFBFBD>g<EFBFBD>J<EFBFBD>ɮ<EFBFBD>
}
fileSim.Close (); //<2F>g<EFBFBD>J<EFBFBD><4A><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD>ɮ<EFBFBD>
}
}
//<2F>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>U
void CTestSimulatorDlg::OnLButtonDown (UINT nFlags, CPoint ptCursor)
{
SetCapture ();
m_bDelBlk = FALSE; //<2F>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>U<EFBFBD>ɸT<C9B8><54><EFBFBD>R<EFBFBD><52>Block
//<2F>P<EFBFBD>_<EFBFBD><5F><EFBFBD>ЬO<D0AC>_<EFBFBD><5F><EFBFBD><EFBFBD>Block rect<63>d<EFBFBD><64>
for (int i = m_iContainerSize - 1; i >= 0; i--)
{
if (m_vcBlkContainer[i]->GetBlkRect ().PtInRect (ptCursor))
{
SetCursor (LoadCursor (NULL, IDC_SIZEALL));
m_iSlctBlkNum = i; //<2F><><EFBFBD><EFBFBD>Block<63>s<EFBFBD><73>
m_bSelectBlk = TRUE;
m_bMoveBlk = TRUE;
m_bLineMode = FALSE; //<2F><><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>
break;
}
else //<2F>I<EFBFBD><49><EFBFBD>DBlock<63><6B><EFBFBD>m<EFBFBD>ɡA<C9A1><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>аO
{
m_bSelectBlk = FALSE;
m_iSlctBlkNum = NO_SEL_NUM;
}
}
//<2F>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Block<63>A<EFBFBD>ߧY<DFA7><59>ø<EFBFBD>u<EFBFBD>@<40><>
if (m_bSelectBlk)
{
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//<2F>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD><D2A6>ɡA<C9A1>P<EFBFBD>_<EFBFBD><5F><EFBFBD>Ы<EFBFBD><D0AB>U<EFBFBD><55><EFBFBD>m<EFBFBD>O<EFBFBD>_<EFBFBD><5F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>XPin<69>}<7D>d<EFBFBD><64>
if (m_bLineMode)
{
for (int i = 0; i < m_iContainerSize; i++)
{
if (m_vcBlkContainer[i]->GetPinOutRect ().PtInRect (ptCursor))
{
m_iHeadBlkNum = i;
m_bConnect = TRUE;
break;
}
}
}
CDialogEx::OnLButtonDown (nFlags, ptCursor);
}
//<2F>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD>
void CTestSimulatorDlg::OnMouseMove (UINT nFlags, CPoint ptCursor)
{
//<2F><><EFBFBD>ʿ<EFBFBD><CABF><EFBFBD>Block
if (m_bMoveBlk)
{
//<2F><><EFBFBD>w<EFBFBD>Ҧ<EFBFBD><D2A6>U<EFBFBD>p<EFBFBD><EFBFBD>Ц<EFBFBD><D0A6>m<EFBFBD>̾F<CCBE>񤧮<EFBFBD><F1A4A7AE>I<EFBFBD>A<EFBFBD>N<EFBFBD><4E><EFBFBD>ʪ<EFBFBD>Block<63><6B><EFBFBD>߳]<5D>m<EFBFBD><6D><EFBFBD>Ӯ<EFBFBD><D3AE>I<EFBFBD><49><EFBFBD>m
if (m_bLock)
{
int iGridX = (int) ((ptCursor.x - m_iWorkLeft) / (double) m_iGridX + 0.5);
int iGridY = (int) ((ptCursor.y - m_iWorkTop) / (double) m_iGridY + 0.5);
m_vcBlkContainer[m_iSlctBlkNum]->Move (CPoint (iGridX * m_iGridX + m_iWorkLeft, iGridY * m_iGridY + m_iWorkTop));
}
else
m_vcBlkContainer[m_iSlctBlkNum]->Move (ptCursor);
}
//<2F>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD>
if (m_bLineMode)
{
for (int i = 0; i < m_iContainerSize ; i++)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>оa<D0BE><61>Block<63><6B><EFBFBD>XPin<69>}<7D>ɡA<C9A1>]<5D>w<EFBFBD><77><EFBFBD>м˦<D0BC><CBA6><EFBFBD><EFBFBD>Q<EFBFBD>r<EFBFBD>b<EFBFBD>Y
if (m_vcBlkContainer[i]->GetPinOutRect ().PtInRect (ptCursor))
SetCursor (LoadCursor (NULL, IDC_CROSS));
//<2F>s<EFBFBD>u<EFBFBD>ɡA<C9A1>]<5D>w<EFBFBD><77><EFBFBD>Ц<EFBFBD><D0A6>m<EFBFBD><6D><EFBFBD><EFBFBD><EFBFBD>u<EFBFBD>u<EFBFBD>q<EFBFBD><71><EFBFBD><EFBFBD>
if (m_bConnect)
m_ptLEnd = ptCursor;
}
}
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
CDialogEx::OnMouseMove (nFlags, ptCursor);
}
//<2F>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}
void CTestSimulatorDlg::OnLButtonUp (UINT nFlags, CPoint ptCursor)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Block<63>ɡA<C9A1>i<EFBFBD>R<EFBFBD><52><EFBFBD><EFBFBD>Block
if (m_bSelectBlk)
m_bDelBlk = TRUE;
if (m_bMoveBlk)
{
//<2F><><EFBFBD><EFBFBD>Block<63><6B><EFBFBD>A<EFBFBD>U<EFBFBD>A<EFBFBD><41><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}<7D><><EFBFBD>m<EFBFBD>W<EFBFBD>X<EFBFBD>u<EFBFBD>@<40>ϡA<CFA1>h<EFBFBD>]<5D>wBlock<63><6B><EFBFBD>^<5E>u<EFBFBD>@<40>Ϥ<EFBFBD><CFA4><EFBFBD>
if (!(m_rcWork.PtInRect (m_vcBlkContainer[m_iSlctBlkNum]->GetBlkRect ().TopLeft ()) &&
m_rcWork.PtInRect (m_vcBlkContainer[m_iSlctBlkNum]->GetBlkRect ().BottomRight ())))
m_vcBlkContainer[m_iSlctBlkNum]->Move (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y));
m_bMoveBlk = FALSE;
}
//<2F>s<EFBFBD>u<EFBFBD>Ҧ<EFBFBD><D2A6>U
if (m_bLineMode && m_bConnect)
{
//<2F>P<EFBFBD>_<EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}<7D><><EFBFBD>m<EFBFBD>O<EFBFBD>_<EFBFBD><5F><EFBFBD><EFBFBD>Block<63><6B><EFBFBD>JPin<69>}<7D>d<EFBFBD><64><EFBFBD>A<EFBFBD>Y<EFBFBD>O<EFBFBD>A<EFBFBD>h<EFBFBD>]<5D>w<EFBFBD><77>Block<63>s<EFBFBD><73><EFBFBD>_<EFBFBD>lBlock<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < m_iContainerSize; i++)
{
if (m_vcBlkContainer[i]->GetPinIn1Rect ().PtInRect (ptCursor))
{
m_vcBlkContainer[i]->SetBlkHead1Ptr (m_vcBlkContainer[m_iHeadBlkNum]);
m_vcBlkContainer[i]->SetBlkHead1Num (m_iHeadBlkNum);
m_vcBlkContainer[i]->SetBlkHeadSize (FALSE);
break;
}
if (m_vcBlkContainer[i]->GetPinIn2Rect ().PtInRect (ptCursor))
{
m_vcBlkContainer[i]->SetBlkHead2Ptr (m_vcBlkContainer[m_iHeadBlkNum]);
m_vcBlkContainer[i]->SetBlkHead2Num (m_iHeadBlkNum);
m_vcBlkContainer[i]->SetBlkHeadSize (FALSE);
break;
}
}
m_bConnect = FALSE; //<2F>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}<7D>ɡA<C9A1><41><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD>u<EFBFBD><75><EFBFBD>u<EFBFBD>q
}
ReleaseCapture ();
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
CDialogEx::OnLButtonUp(nFlags, ptCursor);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD>
void CTestSimulatorDlg::OnLButtonDblClk (UINT nFlags, CPoint ptCursor)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ҧ<EFBFBD><D2A6>U<EFBFBD><55><EFBFBD>i<EFBFBD><69><EFBFBD><EFBFBD>Block flag
if (!m_bSimulate)
{
for (int i = 0; i < m_iContainerSize; i++)
{
if (m_vcBlkContainer[i]->GetBlkRect ().PtInRect (ptCursor))
{
if (m_vcBlkContainer[i]->BlkTypeIs () == BLK_IN) //<2F><><EFBFBD><EFBFBD>Block In<49><6E><EFBFBD>J<EFBFBD>i<EFBFBD><69>flag
{
CInputDlg inputdlgSim;
inputdlgSim.SetInputFlag (m_vcBlkContainer[i]->GetInputFlag ());
if (inputdlgSim.DoModal () == IDOK)
{
m_vcBlkContainer[i]->SetInputFlag (inputdlgSim.GetInputFlag ());
m_vcBlkContainer[i]->SetBlkValue ();
}
else
MessageBox (_T ("The input has not been changed."));
}
else if (m_vcBlkContainer[i]->BlkTypeIs () == BLK_FUN) //<2F><><EFBFBD><EFBFBD>Block Fun<75>B<EFBFBD>⤸flag
{
CFunDlg fundlgSim;
fundlgSim.SetOperFlag (m_vcBlkContainer[i]->GetOperFlag ());
if (fundlgSim.DoModal () == IDOK)
m_vcBlkContainer[i]->SetOperFlag (fundlgSim.GetOperFlag ());
else
MessageBox (_T ("The operator has not been changed."));
}
break;
}
}
}
CDialogEx::OnLButtonDblClk (nFlags, ptCursor);
}
void CTestSimulatorDlg::OnTimer (UINT_PTR nIDEvent)
{
if (nIDEvent == 0)
KillTimer (0);
int iTimeInterval = m_pOscDlg->GetTimeInterval (); //<2F><><EFBFBD>o<EFBFBD>ϥΪ̳]<5D>w<EFBFBD><77><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD>j(<28><><EFBFBD><EFBFBD>ms)
double dTime = m_iStep * iTimeInterval * MSEC; //<2F><><EFBFBD><EFBFBD><EFBFBD>i<EFBFBD><69><EFBFBD>`<60>ɶ<EFBFBD>(<28><><EFBFBD><EFBFBD>s)
std::deque <double> deqRowValue; //<2F>ΥH<CEA5>x<EFBFBD>s<EFBFBD>C<EFBFBD>@<40>Ӯɶ<D3AE><C9B6>I<EFBFBD>U<EFBFBD>Uinput channel<65><6C><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>e<EFBFBD>P<EFBFBD>_input<75>O<EFBFBD>_<EFBFBD>X<EFBFBD>z(<28>ȧP<C8A7>_<EFBFBD>@<40><>)
if (m_iStep == 0)
{
m_iOutSize = m_vcBlkContainer[m_iSimBlkNum]->GetBlkHeadSize (); //Ū<><C5AA>channel<65>ƥ<EFBFBD>
for (int i = 0; i < m_iOutSize; i++)
{
int iValueFlag = m_vcBlkContainer[m_iSimBlkNum]->GetValueFlag (i);
if (iValueFlag == NO_VALUE) //<2F><><EFBFBD>s<EFBFBD>binput signal
{
MessageBox (_T ("Please check if the output block exists input signal."));
m_pOscDlg->m_bSim = FALSE;
m_pOscDlg->m_bModify = TRUE;
break;
}
else if (iValueFlag == COMPUTE_ERROR) //<2F>s<EFBFBD>b<EFBFBD><62><EFBFBD><EFBFBD><EFBFBD>\<5C><><EFBFBD>B<EFBFBD><42><EFBFBD>
{
MessageBox (_T ("Operation is not allowed."));
m_pOscDlg->m_bSim = FALSE;
m_pOscDlg->m_bModify = TRUE;
break;
}
else if (iValueFlag == NO_OPER_FLAG) //Block Fun<75><6E><EFBFBD>]<5D>w<EFBFBD>B<EFBFBD>
{
MessageBox (_T ("Please check if the operator in function block has been set up."));
m_pOscDlg->m_bSim = FALSE;
m_pOscDlg->m_bModify = TRUE;
break;
}
else
m_pOscDlg->m_bSim = TRUE;
}
}
//<2F><>input<75><74><EFBFBD>X<EFBFBD>z<EFBFBD>B<EFBFBD><42><EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD>}<7D>l
if (m_pOscDlg->m_bSim)
{
if (m_iStep == 0)
{
m_pOscDlg->SetOutputSize (m_iOutSize); //<2F>]<5D>w<EFBFBD>ܪi<DCAA><69><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD>channel<65><6C>
m_pOscDlg->InitialData (); //<2F><><EFBFBD>l<EFBFBD>ƥܪi<DCAA><69><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD>(channel<65>ƥ<EFBFBD>, <20>H<EFBFBD><48><EFBFBD>e<EFBFBD><65>)
m_deq2DOutputValue.clear (); //<2F>}<7D>l<EFBFBD><6C><EFBFBD><EFBFBD><EFBFBD>e<EFBFBD>M<EFBFBD>ŤG<C5A4><47><EFBFBD>x<EFBFBD>}
}
//<2F>]<5D>w<EFBFBD>Ӯɶ<D3AE><C9B6>U<EFBFBD>A<EFBFBD>C<EFBFBD>@<40><>Block In<49><6E><EFBFBD><EFBFBD>
for (int i = 0; i < m_iContainerSize; i++)
{
if (m_vcBlkContainer[i]->BlkTypeIs () == BLK_IN)
{
if (m_vcBlkContainer[i]->GetInputFlag () == SIN)
m_vcBlkContainer[i]->SetBlkValue (dTime);
else if (m_vcBlkContainer[i]->GetInputFlag () == COS)
m_vcBlkContainer[i]->SetBlkValue (dTime);
}
}
//<2F><><EFBFBD>o<EFBFBD><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Block Out<75><74><EFBFBD><EFBFBD>(<28><><EFBFBD>h<EFBFBD><68>channel)
for (int i = 0; i < m_iOutSize; i++)
{
double dValue = m_vcBlkContainer[m_iSimBlkNum]->GetBlkValue (i);
deqRowValue.push_back (dValue); //<2F>s<EFBFBD>J<EFBFBD>C<EFBFBD>V<EFBFBD>q(<28><><EFBFBD><EFBFBD><EFBFBD>Ӯɶ<D3AE><C9B6>I<EFBFBD>U<EFBFBD>C<EFBFBD>@<40><>input channel<65><6C><EFBFBD><EFBFBD>)
}
int iDataSize = (int) m_deq2DOutputValue.size (); //Ū<><C5AA><EFBFBD>`data<74>ƥ<EFBFBD>
//<2F>Y<EFBFBD>`data<74>ƥضW<D8B6>L<EFBFBD>w<EFBFBD>]<5D>̤jdata<74>ơA<C6A1>R<EFBFBD><52><EFBFBD>Ĥ@<40><>data<74>A<EFBFBD>åѥ<C3A5><D1A5>ݥ[<5B>J<EFBFBD>sdata
if (iDataSize < MAX_DATA_NUM)
m_deq2DOutputValue.push_back (deqRowValue);
else
{
m_deq2DOutputValue.pop_front ();
m_deq2DOutputValue.push_back (deqRowValue);
}
//FFT<46>D<EFBFBD>Y<EFBFBD><59><EFBFBD>W<EFBFBD>v
double dOutFreq = 0.;
if (iDataSize == MAX_DATA_NUM /*&& m_pOscDlg->m_bFFT*/)
{
std::deque <double> deqOutputData;
for (int i = 0; i < MAX_DATA_NUM; i++)
{
double dValue = m_deq2DOutputValue[i][m_pOscDlg->m_iSlctOutputNum];
deqOutputData.push_back (dValue);
}
dOutFreq = FFT (deqOutputData, MAX_DATA_NUM, iTimeInterval * MSEC);
}
//<2F>ǭȦܥܪi<DCAA><69><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD>(<28><><EFBFBD>e<EFBFBD>ɶ<EFBFBD>, <20><><EFBFBD><EFBFBD>output value, <20>W<EFBFBD>v)
m_pOscDlg->SetData(dTime, deqRowValue[m_pOscDlg->m_iSlctOutputNum], dOutFreq);
//m_pOscDlg->SetData (dTime, deqRowValue[m_pOscDlg->m_iSlctOutputNum]);
m_iStep++;
//<2F><><EFBFBD>s<EFBFBD>ܪi<DCAA><69><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD>
m_pOscDlg->UpdateData (FALSE);
m_pOscDlg->InvalidateRect (m_pOscDlg->m_rcWork, FALSE);
m_pOscDlg->UpdateWindow ();
}
CDialogEx::OnTimer (nIDEvent);
if (m_pOscDlg->m_bSim && nIDEvent == 0)
SetTimer (0, 10, NULL);
}
//<2F>D<EFBFBD><44><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>j<EFBFBD>p<EFBFBD><70><EFBFBD><EFBFBD>
void CTestSimulatorDlg::OnSize (UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
//<2F><><EFBFBD>ͦ<EFBFBD><CDA6>D<EFBFBD><44><EFBFBD>ܲ<EFBFBD><DCB2>ɤ<EFBFBD><C9A4>i<EFBFBD>J
if (m_bInitDlg)
{
//<2F>P<EFBFBD>_<EFBFBD>O<EFBFBD>_<EFBFBD>̤p<CCA4><70>
if (!IsIconic ())
{
//<2F><><EFBFBD>o<EFBFBD>D<EFBFBD><44><EFBFBD>ܲ<EFBFBD><DCB2>Ȥ<EFBFBD><C8A4><EFBFBD>
CRect rcCurClient;
this->GetClientRect (&rcCurClient);
//<2F>p<EFBFBD><70>x, y<><79><EFBFBD>V<EFBFBD>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double dMultipleWid = rcCurClient.Width () / (double) m_rcClient.Width ();
m_rcClient.right = rcCurClient.Width ();
double dMultipleHeight = rcCurClient.Height () / (double) m_rcClient.Height ();
m_rcClient.bottom = rcCurClient.Height ();
//<2F>]<5D>w<EFBFBD><77><EFBFBD>s<EFBFBD><73><EFBFBD>u<EFBFBD>@<40>ϰ<EFBFBD>
m_iWorkLeft = (int) (dMultipleWid * m_iWorkLeft + 0.5);
m_iWorkTop = (int) (dMultipleHeight * m_iWorkTop + 0.5);
m_iWorkRight = (int) (dMultipleWid * m_iWorkRight + 0.5);
m_iWorkBottom = (int) (dMultipleHeight * m_iWorkBottom + 0.5);
m_rcWork.SetRect (m_iWorkLeft, m_iWorkTop, m_iWorkRight, m_iWorkBottom);
//<2F>]<5D>w<EFBFBD><77><EFBFBD>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>m<EFBFBD>P<EFBFBD>j<EFBFBD>p
Resize (IDC_BUTTON_IN , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_OUT , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_AND , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_OR , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_NOT , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_FUNCTION , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_LINE , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_SIMULATE , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_GRID , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_LOCK , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_BGPIC , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_BGCOLOR , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_OPEN , dMultipleWid, dMultipleHeight);
Resize (IDC_BUTTON_SAVE , dMultipleWid, dMultipleHeight);
//<2F><><EFBFBD>s<EFBFBD><73><EFBFBD>J<EFBFBD>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD>
if (m_bBgPic)
{
HBITMAP hbBgPic;
hbBgPic = (HBITMAP)::LoadImage (AfxGetInstanceHandle (), m_strPicPath, IMAGE_BITMAP, m_rcWork.Width (), m_rcWork.Height (), LR_LOADFROMFILE);
m_bitmapBgPic.Detach ();
m_bitmapBgPic.Attach (hbBgPic);
m_dcBgPic.SelectObject (&m_bitmapBgPic);
}
//<2F>]<5D>w<EFBFBD><77><EFBFBD>s<EFBFBD><73>Block<63><6B><EFBFBD>m<EFBFBD>P<EFBFBD>j<EFBFBD>p
m_iBlkWidth = (int) (m_iBlkWidth * dMultipleWid + 0.5);
m_iBlkHeight = (int) (m_iBlkHeight * dMultipleHeight + 0.5);
m_iGridX = (int) (m_iBlkWidth / 4. + 0.5);
m_iGridY = (int) (m_iBlkHeight / 2. + 0.5);
for (int i = 0; i < m_iContainerSize; i++)
Resize (m_vcBlkContainer[i], dMultipleWid, dMultipleHeight);
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
Invalidate (TRUE);
UpdateWindow ();
//<2F>Y<EFBFBD>s<EFBFBD>b<EFBFBD>ܪi<DCAA><69><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2>A<EFBFBD>h<EFBFBD><68><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>
if (m_bSimulate && m_pOscDlg != NULL)
m_pOscDlg->ShowWindow (SW_SHOW);
}
}
}
BOOL CTestSimulatorDlg::PreTranslateMessage (MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
//<2F><><EFBFBD>U<EFBFBD>R<EFBFBD><52><EFBFBD><EFBFBD>
if (pMsg->wParam == VK_DELETE && !m_vcBlkContainer.empty () && m_bDelBlk && !m_bSimulate)
{
//<2F>P<EFBFBD>_<EFBFBD><5F><EFBFBD>LBlock<63>O<EFBFBD>_<EFBFBD><5F><EFBFBD>s<EFBFBD><73><EFBFBD>ܸӧR<D3A7><52><EFBFBD><EFBFBD>Block<63>A<EFBFBD>Y<EFBFBD><59><EFBFBD>A<EFBFBD>h<EFBFBD>M<EFBFBD><4D><EFBFBD>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < m_iContainerSize; i++)
{
if (!(m_vcBlkContainer[i]->BlkTypeIs () == BLK_OUT))
{
if (m_vcBlkContainer[i]->GetBlkHead1Ptr () == m_vcBlkContainer[m_iSlctBlkNum])
{
m_vcBlkContainer[i]->SetBlkHead1Ptr (NULL);
m_vcBlkContainer[i]->SetBlkHead1Num (NO_BLOCK_HEAD);
}
if (m_vcBlkContainer[i]->GetBlkHead2Ptr () == m_vcBlkContainer[m_iSlctBlkNum])
{
m_vcBlkContainer[i]->SetBlkHead2Ptr (NULL);
m_vcBlkContainer[i]->SetBlkHead2Num (NO_BLOCK_HEAD);
}
}
else
{
int iBlkHeadSize = m_vcBlkContainer[i]->GetBlkHeadSize ();
for (int j = 0; j < iBlkHeadSize; j++)
{
if (m_vcBlkContainer[i]->GetBlkHead1Ptr (j) == m_vcBlkContainer[m_iSlctBlkNum])
{
m_vcBlkContainer[i]->DeleteBlkHead1Ptr (j);
m_vcBlkContainer[i]->SetBlkHeadSize (TRUE);
}
}
}
}
//<2F>M<EFBFBD><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Block
delete m_vcBlkContainer[m_iSlctBlkNum];
m_vcBlkContainer.erase (m_vcBlkContainer.begin () + m_iSlctBlkNum);
m_iContainerSize = (int) m_vcBlkContainer.size ();
//<2F><><EFBFBD>s<EFBFBD>s<EFBFBD><73>
for (int i = 0; i < m_iContainerSize; i++)
m_vcBlkContainer[i]->SetBlkNum (i);
//<2F><><EFBFBD>s<EFBFBD>]<5D>w<EFBFBD>s<EFBFBD><73><EFBFBD>s<EFBFBD><73>
for (int i = 0; i < m_iContainerSize; i++)
{
if (!(m_vcBlkContainer[i]->BlkTypeIs () == BLK_OUT))
{
if (m_vcBlkContainer[i]->GetBlkHead1Ptr () != NULL)
{
int iBlkHead1Num = m_vcBlkContainer[i]->GetBlkHead1Ptr ()->GetBlkNum ();
m_vcBlkContainer[i]->SetBlkHead1Num (iBlkHead1Num);
}
if (m_vcBlkContainer[i]->GetBlkHead2Ptr () != NULL)
{
int iBlkHead2Num = m_vcBlkContainer[i]->GetBlkHead2Ptr ()->GetBlkNum ();
m_vcBlkContainer[i]->SetBlkHead2Num (iBlkHead2Num);
}
}
else
{
int iBlkHeadSize = m_vcBlkContainer[i]->GetBlkHeadSize ();
m_vcBlkContainer[i]->ClearBlkHead1Num ();
for (int j = 0; j < iBlkHeadSize; j++)
{
int iBlkHeadNum = m_vcBlkContainer[i]->GetBlkHead1Ptr (j)->GetBlkNum ();
m_vcBlkContainer[i]->SetBlkHead1Num (iBlkHeadNum);
}
}
}
//<2F>R<EFBFBD><52><EFBFBD><EFBFBD><EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_bSelectBlk = FALSE;
m_iSlctBlkNum = NO_SEL_NUM;
m_bDelBlk = FALSE;
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//<2F><><EFBFBD>UESC<53><43>
else if (pMsg->wParam == VK_ESCAPE)
{
m_bSelectBlk = FALSE;
m_iSlctBlkNum = NO_SEL_NUM;
m_bMoveBlk = FALSE;
m_bLineMode = FALSE;
m_bConnect = FALSE;
m_bDelBlk = FALSE;
//<2F><>ø<EFBFBD>u<EFBFBD>@<40><>
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
return TRUE;
}
//<2F><><EFBFBD>UENTER<45><52>
else if (pMsg->wParam == VK_RETURN)
return TRUE;
}
return CDialogEx::PreTranslateMessage(pMsg);
}
void CTestSimulatorDlg::OnDestroy ()
{
CString strIniPath (_T (".\\Initial.ini")); //.ini<6E><69><EFBFBD>|
CString strAppName (_T ("BgParameter")); //.ini<6E><69>[<5B>`<60>W]
CString strColorRef; //<2F>C<EFBFBD><43><EFBFBD>ܼ<EFBFBD>
strColorRef.Format (_T ("%u"), m_clrBg); //<2F>N<EFBFBD>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>r<EFBFBD><72>
//<2F><><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>T
CString strKeyName (_T ("BgPicBOOL")); //.ini<6E><69><EFBFBD>ܼƦW<C6A6><57>
if (m_bBgPic)
{
WritePrivateProfileString (strAppName, strKeyName, _T ("TRUE"), strIniPath); //<2F><><EFBFBD>J<EFBFBD>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD>
strKeyName.Format (_T ("BgPicPath"));
WritePrivateProfileString (strAppName, strKeyName, m_strPicPath, strIniPath); //<2F>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD><CFA4><EFBFBD><EFBFBD>|
strKeyName.Format (_T ("BgColor"));
WritePrivateProfileString (strAppName, strKeyName, _T ("None"), strIniPath); //<2F>I<EFBFBD><49><EFBFBD>C<EFBFBD>⬰None
}
else
{
WritePrivateProfileString (strAppName, strKeyName, _T ("FALSE"), strIniPath); //<2F><><EFBFBD><EFBFBD><EFBFBD>J<EFBFBD>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD>
strKeyName.Format (_T ("BgPicPath"));
WritePrivateProfileString (strAppName, strKeyName, _T ("None"), strIniPath); //<2F>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD><CFA4><EFBFBD><EFBFBD>|<7C><>None
strKeyName.Format (_T ("BgColor"));
WritePrivateProfileString (strAppName, strKeyName, strColorRef, strIniPath); //<2F><><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>C<EFBFBD><43><EFBFBD><EFBFBD>
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD>}<7D>һP<D2BB>_
strKeyName.Format (_T ("GridBOOL"));
if (m_bGrid)
WritePrivateProfileString (strAppName, strKeyName, _T ("TRUE"), strIniPath);
else
WritePrivateProfileString (strAppName, strKeyName, _T ("FALSE"), strIniPath);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>w<EFBFBD>}<7D>һP<D2BB>_
strKeyName.Format (_T ("LockBOOL"));
if (m_bLock)
WritePrivateProfileString (strAppName, strKeyName, _T ("TRUE"), strIniPath);
else
WritePrivateProfileString (strAppName, strKeyName, _T ("FALSE"), strIniPath);
//<2F>M<EFBFBD><4D><EFBFBD>s<EFBFBD><73><EFBFBD>I<EFBFBD><49><EFBFBD>Ϥ<EFBFBD><CFA4><EFBFBD>dc
m_dcBgPic.SelectObject (m_pOldBitmap);
m_dcBgPic.DeleteDC ();
//<2F>M<EFBFBD><4D><EFBFBD>ܪi<DCAA><69><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD>
if (m_pOscDlg != NULL)
{
m_pOscDlg->DestroyWindow ();
delete m_pOscDlg;
}
//<2F>M<EFBFBD><4D>Block vector
for (int i = 0; i < m_iContainerSize; i++)
delete m_vcBlkContainer[i];
CDialogEx::OnDestroy();
}
//<2F>N<EFBFBD>@<40>C<EFBFBD>r<EFBFBD><72><EFBFBD>̾ڤ<CCBE><DAA4>j<EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD><EFBFBD>ά<EFBFBD><CEAC>W<EFBFBD>ߦr<DFA6><72>
void CTestSimulatorDlg::SplitString (CString str, char cSplit, CStringArray& strarray)
{
strarray.RemoveAll ();
CString strTemp = str;
while (1)
{
int iIndex = strTemp.Find (cSplit);
if (iIndex >= 0)
{
CString strLeft = strTemp.Left (iIndex);
strLeft.Remove (' ');
strarray.Add (strLeft);
strTemp = strTemp.Right (strTemp.GetLength () - 1 - iIndex);
}
else
break;
}
strTemp.Remove (' ');
strarray.Add (strTemp);
}
//<2F><><EFBFBD>s<EFBFBD>]<5D>w<EFBFBD><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>m<EFBFBD>Τj<CEA4>p
void CTestSimulatorDlg::Resize (int nID, double dMulWid, double dMulHei)
{
CRect rcItem;
GetDlgItem (nID)->GetWindowRect (&rcItem);
ScreenToClient (&rcItem);
rcItem.TopLeft ().x = (int) (rcItem.TopLeft ().x * dMulWid + 0.5);
rcItem.TopLeft ().y = (int) (rcItem.TopLeft ().y * dMulHei + 0.5);
rcItem.BottomRight ().x = (int) (rcItem.BottomRight ().x * dMulWid + 0.5);
rcItem.BottomRight ().y = (int) (rcItem.BottomRight ().y * dMulHei + 0.5);
GetDlgItem (nID)->MoveWindow (rcItem);
}
//<2F><><EFBFBD>s<EFBFBD>]<5D>wBlock<63><6B><EFBFBD>m<EFBFBD>Τj<CEA4>p
void CTestSimulatorDlg::Resize (CBlockBasis* pBlk, double dMulWid, double dMulHei)
{
CRect rcItem = pBlk->GetBlkRect ();
rcItem.TopLeft ().x = (int) (rcItem.TopLeft ().x * dMulWid + 0.5);
rcItem.TopLeft ().y = (int) (rcItem.TopLeft ().y * dMulHei + 0.5);
rcItem.BottomRight ().x = (int) (rcItem.BottomRight ().x * dMulWid + 0.5);
rcItem.BottomRight ().y = (int) (rcItem.BottomRight ().y * dMulHei + 0.5);
pBlk->SetBlkRect (rcItem.CenterPoint (), m_iBlkWidth, m_iBlkHeight);
}
//<2F>p<EFBFBD><70>data<74>h<EFBFBD><68>(<28><><EFBFBD>Ω<EFBFBD>FFT)
int CTestSimulatorDlg::GetComputationLayers(int iDataSize)
{
int m_iLayers = 1;
if (iDataSize == 2)
return 1;
while (1)
{
iDataSize = iDataSize / 2;
m_iLayers++;
if (iDataSize == 2)
return m_iLayers;
if (iDataSize <= 1)
return -1;
}
}
//FFT<46>D<EFBFBD>Y<EFBFBD><59><EFBFBD>W<EFBFBD>v
double CTestSimulatorDlg::FFT (const std::deque <double> & deq2dData, int iSize, double dUnitTime)
{
std::deque <CComplex> deqFData;
std::deque <CComplex> deqWeights;
std::deque <CComplex> deqX;
std::deque <double> deqAmplitude;
int iDeqLen = iSize;
int iLayers = GetComputationLayers (iSize);
for (int i = 0; i < iDeqLen; i++)
deqFData.push_back (CComplex (deq2dData[i], 0));
double dFixedFactors = (-2 * M_PI) / iDeqLen;
//<2F>p<EFBFBD><70><EFBFBD>v<EFBFBD><76><EFBFBD>ǦC
for (int i = 0; i < iDeqLen / 2; i++)
{
double dAngle = i * dFixedFactors;
deqWeights.push_back (CComplex (cos (dAngle), sin (dAngle)));
}
for (int i = 0; i < iDeqLen / 2; i++)
deqWeights.push_back (CComplex (-deqWeights[i].m_dReal, -deqWeights[i].m_dImag));
//<2F>p<EFBFBD><70><EFBFBD>˧Ǧ<CBA7><C7A6>X
for (int i = 0; i < iDeqLen; i++)
{
int iIndex = 0;
for (int j = iLayers - 1; j >= 0; j--)
iIndex += (1 && (i & (1 << j))) << (iLayers - j - 1);
deqX.push_back (deqFData[iIndex]);
}
//<2F>p<EFBFBD><70>FFT
for (int L = 1; L <= iLayers; L++)
{
int iDistance = 1 << (L - 1);
int iW = 1 << (iLayers - L); //<2F>`<60><><EFBFBD>ƪ<EFBFBD><C6AA>׳Q<D7B3><51><EFBFBD>Ѫ<EFBFBD><D1AA><EFBFBD><EFBFBD><EFBFBD>
int iB = iDeqLen >> L; //<2F>ݭp<DDAD><70><EFBFBD>X<EFBFBD><58><EFBFBD><EFBFBD><EFBFBD>ƪ<EFBFBD><C6AA>׬<EFBFBD>iN<69><4E><EFBFBD>ť߸<C5A5><DFB8>
int iN = iDeqLen / iB; //<2F>ݭp<DDAD><70><EFBFBD>ť߸<C5A5><DFB8><EFBFBD><E0B4AB><EFBFBD><EFBFBD><EFBFBD>ƪ<EFBFBD><C6AA><EFBFBD>
for (int b = 0; b < iB; b++)
{
int iMid = b * iN;
for (int n = 0; n < iN / 2; n++)
{
int iIndex = n + iMid;
deqFData[iIndex] = deqX[iIndex] + deqWeights[n * iW] * deqX[iIndex + iDistance]; //Fe + W*Fo
}
for (int n = iN / 2; n < iN; n++)
{
int iIndex = n + iMid;
deqFData[iIndex] = deqX[iIndex - iDistance] + deqWeights[n * iW] * deqX[iIndex]; //Fe - W*Fo
}
}
deqX = deqFData;
}
//<2F>p<EFBFBD><EFBFBD>T
for (int i = 0; i < iDeqLen; i++)
deqAmplitude.push_back (deqFData[i].ComputeAmplitude ());
double dMaxAmp = 0.; //<2F>ŧi<C5A7>̤j<CCA4><6A><EFBFBD>T<EFBFBD>ܼ<EFBFBD>
double dCornerFreq = 1 / dUnitTime / 2; //<2F>p<EFBFBD><70><EFBFBD>I<EFBFBD><49><EFBFBD>W<EFBFBD>v
double dOutFreq = 0.; //<2F><><EFBFBD><EFBFBD><EFBFBD>̤j<CCA4><6A><EFBFBD>֥X<D6A5>{<7B><><EFBFBD>W<EFBFBD>v
//<2F><><EFBFBD><EFBFBD><EFBFBD>W<EFBFBD><EFBFBD>X<EFBFBD>{<7B>̤j<CCA4><6A><EFBFBD>T<EFBFBD><54><EFBFBD><EFBFBD><EFBFBD>m<EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>W<EFBFBD>v<EFBFBD>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD>X<EFBFBD>W<EFBFBD>v
for (int i = 0; i < iDeqLen; i++)
{
double dFreq = i / (dUnitTime * (iDeqLen - 1));
if (dFreq > dCornerFreq)
break;
if (deqAmplitude[i] > dMaxAmp)
{
dMaxAmp = deqAmplitude[i];
dOutFreq = dFreq;
}
}
return dOutFreq;
}