First commit

This commit is contained in:
ChenSiAn 2023-02-03 10:07:52 +08:00
commit 9ab6ee652a
39 changed files with 4887 additions and 0 deletions

12
.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
#Build results
[Dd]ebug/
[Rr]elease/
#Ext
*.bmp
*.txt
*.sdf
*.suo
*.db
*.opensdf

20
TestSimulator.sln Normal file
View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSimulator", "TestSimulator\TestSimulator.vcxproj", "{C1F3E95D-9580-4550-A748-674E1D31DF84}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C1F3E95D-9580-4550-A748-674E1D31DF84}.Debug|Win32.ActiveCfg = Debug|Win32
{C1F3E95D-9580-4550-A748-674E1D31DF84}.Debug|Win32.Build.0 = Debug|Win32
{C1F3E95D-9580-4550-A748-674E1D31DF84}.Release|Win32.ActiveCfg = Release|Win32
{C1F3E95D-9580-4550-A748-674E1D31DF84}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

226
TestSimulator/BlockAnd.cpp Normal file
View File

@ -0,0 +1,226 @@
#include "stdafx.h"
#include "BlockAnd.h"
#include "math.h"
#define PIN_RADIUS 8 //Pin半徑
#define GOLD RGB (255, 215, 0) //Pin腳顏色
#define BLACK RGB (0, 0, 0) //連線顏色
#define NO_VALUE -10 //不存在輸入訊號
#define NO_OPER_FLAG -11 //不存在運算元
#define COMPUTE_ERROR -13 //不允許的運算
#define NO_BLOCK_HEAD -14 //不存在連接Block
#define TOLERANCE 0.001 //容忍誤差值
#define DIGITAL_VALUE 4 //數位訊號flag
#define ANALOG_VALUE 5 //類比訊號flag
#define BLK_AND 3 //Block種類編號
CBlockAnd::CBlockAnd ()
{
m_rcPinIn1 = CRect ();
m_rcPinIn2 = CRect ();
m_rcPinOut = CRect ();
m_pBlkHead1 = NULL;
m_pBlkHead2 = NULL;
m_iBlkHead1Num = NO_BLOCK_HEAD;
m_iBlkHead2Num = NO_BLOCK_HEAD;
}
CBlockAnd::~CBlockAnd ()
{
}
void CBlockAnd::SetBlkRect (CPoint ptCenter, int iWidth, int iHeight)
{
CBlockBasis::SetBlkRect (ptCenter, iWidth, iHeight);
m_rcPinIn1.left = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn1.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn1.right = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn1.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinIn2.left = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn2.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn2.right = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn2.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinOut.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinOut.top = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinOut.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinOut.bottom = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) + PIN_RADIUS;
}
CRect CBlockAnd::GetPinIn1Rect () const
{
return m_rcPinIn1;
}
CRect CBlockAnd::GetPinIn2Rect () const
{
return m_rcPinIn2;
}
CRect CBlockAnd::GetPinOutRect () const
{
return m_rcPinOut;
}
CBlockBasis* CBlockAnd::GetBlkHead1Ptr () const
{
return m_pBlkHead1;
}
CBlockBasis* CBlockAnd::GetBlkHead2Ptr () const
{
return m_pBlkHead2;
}
void CBlockAnd::SetBlkHead1Ptr (CBlockBasis* pBlkHead)
{
m_pBlkHead1 = pBlkHead;
}
void CBlockAnd::SetBlkHead2Ptr (CBlockBasis* pBlkHead)
{
m_pBlkHead2 = pBlkHead;
}
int CBlockAnd::GetBlkHead1Num () const
{
return m_iBlkHead1Num;
}
int CBlockAnd::GetBlkHead2Num () const
{
return m_iBlkHead2Num;
}
void CBlockAnd::SetBlkHead1Num (int iHeadBlkNum)
{
m_iBlkHead1Num = iHeadBlkNum;
}
void CBlockAnd::SetBlkHead2Num (int iHeadBlkNum)
{
m_iBlkHead2Num = iHeadBlkNum;
}
double CBlockAnd::GetBlkValue () const
{
//And邏輯 (若兩輸入皆為1則回傳1否則回傳0)
if (abs (m_pBlkHead1->GetBlkValue () - 1) < TOLERANCE && abs (m_pBlkHead2->GetBlkValue () - 1) < TOLERANCE)
return 1.;
else
return 0.;
}
int CBlockAnd::GetValueFlag () const
{
if (m_pBlkHead1 == NULL || m_pBlkHead2 == NULL) //若存在任一輸入接點未連接,回傳"無值"
return NO_VALUE;
else if (m_pBlkHead1->GetValueFlag () == NO_VALUE || m_pBlkHead2->GetValueFlag () == NO_VALUE) //若存在任一輸入為無值,回傳"無值"
return NO_VALUE;
else if (m_pBlkHead1->GetValueFlag () == COMPUTE_ERROR || m_pBlkHead2->GetValueFlag () == COMPUTE_ERROR) //若存在任一輸入為計算錯誤,回傳"計算錯誤"
return COMPUTE_ERROR;
else if (m_pBlkHead1->GetValueFlag () == ANALOG_VALUE || m_pBlkHead2->GetValueFlag () == ANALOG_VALUE) //不允許類比輸入
return COMPUTE_ERROR;
else if (m_pBlkHead1->GetValueFlag () == NO_OPER_FLAG || m_pBlkHead2->GetValueFlag () == NO_OPER_FLAG) //未設定運算元
return NO_OPER_FLAG;
else if (m_pBlkHead1->GetValueFlag () == DIGITAL_VALUE && m_pBlkHead2->GetValueFlag () == DIGITAL_VALUE) //若輸入皆為數位訊號,則回傳數位訊號
return DIGITAL_VALUE;
else
return NO_VALUE;
}
void CBlockAnd::Move (CPoint ptCursor)
{
CBlockBasis::Move (ptCursor);
m_rcPinIn1.left = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn1.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn1.right = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn1.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinIn2.left = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn2.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn2.right = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn2.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinOut.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinOut.top = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinOut.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinOut.bottom = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) + PIN_RADIUS;
}
void CBlockAnd::Draw (CDC* pDC)
{
CBrush brushPin (GOLD), * pbrushOld;
pbrushOld = pDC->SelectObject (&brushPin);
pDC->Ellipse (m_rcPinIn1);
pDC->Ellipse (m_rcPinIn2);
pDC->Ellipse (m_rcPinOut);
pDC->SelectObject (pbrushOld);
CBlockBasis::Draw (pDC);
pDC->DrawTextA (_T ("AND"), -1, &m_rcBlk, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
void CBlockAnd::DrawLine (CDC* pDC)
{
if (m_pBlkHead1 != NULL)
{
CPen penLine (PS_SOLID, 5, BLACK);
CPen* pOldPen;
pOldPen = pDC->SelectObject (&penLine);
CPoint ptStart = m_pBlkHead1->GetPinOutRect ().CenterPoint (); //連線起點為輸入Block的輸出Pin腳中心點
CPoint ptEnd = m_rcPinIn1.CenterPoint (); //連線終點為此Block的輸入Pin腳中心點
int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //垂直格點間隔
int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //計算連線轉折處距離輸入Block幾個隔點
int iCornerY = iCornerGridY * iGrid + ptStart.y; //連線轉折處Y座標位置
pDC->MoveTo (ptStart);
pDC->LineTo (CPoint (ptStart.x, iCornerY));
pDC->MoveTo (CPoint (ptStart.x, iCornerY));
pDC->LineTo (CPoint (ptEnd.x, iCornerY));
pDC->MoveTo (CPoint (ptEnd.x, iCornerY));
pDC->LineTo (ptEnd);
pDC->SelectObject (pOldPen);
}
if (m_pBlkHead2 != NULL)
{
CPen penLine (PS_SOLID, 5, BLACK);
CPen* pOldPen;
pOldPen = pDC->SelectObject (&penLine);
CPoint ptStart = m_pBlkHead2->GetPinOutRect ().CenterPoint (); //連線起點為輸入Block的輸出Pin腳中心點
CPoint ptEnd = m_rcPinIn2.CenterPoint (); //連線終點為此Block的輸入Pin腳中心點
int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //垂直格點間隔
int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //計算連線轉折處距離輸入Block幾個隔點
int iCornerY = iCornerGridY * iGrid + ptStart.y; //連線轉折處Y座標位置
pDC->MoveTo (ptStart);
pDC->LineTo (CPoint (ptStart.x, iCornerY));
pDC->MoveTo (CPoint (ptStart.x, iCornerY));
pDC->LineTo (CPoint (ptEnd.x, iCornerY));
pDC->MoveTo (CPoint (ptEnd.x, iCornerY));
pDC->LineTo (ptEnd);
pDC->SelectObject (pOldPen);
}
}
int CBlockAnd::BlkTypeIs () const
{
return BLK_AND;
}

55
TestSimulator/BlockAnd.h Normal file
View File

@ -0,0 +1,55 @@
#pragma once
//Block衍生類別Block And
#include "BlockBasis.h"
class CBlockAnd : public CBlockBasis
{
private:
//Block rect(存在兩個輸入Pin一個輸出Pin)
CRect m_rcPinIn1;
CRect m_rcPinIn2;
CRect m_rcPinOut;
//連接指標(存在兩個連接指標)
CBlockBasis* m_pBlkHead1;
CBlockBasis* m_pBlkHead2;
//連接Block編號(存在兩個編號)
int m_iBlkHead1Num;
int m_iBlkHead2Num;
public:
//建構、解構子
CBlockAnd ();
virtual ~CBlockAnd ();
//取得、設定rect
virtual void SetBlkRect (CPoint, int, int);
virtual CRect GetPinIn1Rect () const;
virtual CRect GetPinIn2Rect () const;
virtual CRect GetPinOutRect () const;
//取得、設定連接至Block的指標
virtual CBlockBasis* GetBlkHead1Ptr () const;
virtual CBlockBasis* GetBlkHead2Ptr () const;
virtual void SetBlkHead1Ptr (CBlockBasis*);
virtual void SetBlkHead2Ptr (CBlockBasis*);
//取得、設定連接至Block的編號
virtual int GetBlkHead1Num () const;
virtual int GetBlkHead2Num () const;
virtual void SetBlkHead1Num (int) ;
virtual void SetBlkHead2Num (int) ;
virtual double GetBlkValue () const; //取得Block值
virtual int GetValueFlag () const; //取得Value旗標
virtual void Move (CPoint); //移動Block
virtual void Draw (CDC*); //繪製Block
virtual void DrawLine (CDC*); //繪製Block連接線
//判斷Block種類
virtual int BlkTypeIs () const;
};

View File

@ -0,0 +1,191 @@
#include "stdafx.h"
#include "BlockBasis.h"
#define LIGHTGRAY RGB (211, 211, 211) //Block顏色
#define NO_VALUE -10 //不存在輸入訊號
#define NO_OPER_FLAG -11 //Block Fun不存在運算元
#define NO_INPUT_FLAG -12 //Block In不存在輸入波形
#define NO_BLOCK_HEAD -14 //不存在連接Block
#define NO_BLK_TYPE 0
CBlockBasis::CBlockBasis ()
{
m_rcBlk = CRect ();
m_iBlkNum = 0;
}
CBlockBasis::~CBlockBasis ()
{
}
CRect CBlockBasis::GetBlkRect () const
{
return m_rcBlk;
}
//以中心點、Block寬度、Block高度設定Block rect
void CBlockBasis::SetBlkRect (CPoint ptCenter, int iWidth, int iHeight)
{
m_rcBlk.SetRect (CPoint (ptCenter.x - int (iWidth / 2), ptCenter.y - int (iHeight / 2)),
CPoint (ptCenter.x + int (iWidth / 2), ptCenter.y + int (iHeight / 2)));
}
CRect CBlockBasis::GetPinIn1Rect () const
{
return CRect ();
}
CRect CBlockBasis::GetPinIn2Rect () const
{
return CRect ();
}
CRect CBlockBasis::GetPinOutRect () const
{
return CRect ();
}
int CBlockBasis::GetBlkNum () const
{
return m_iBlkNum;
}
void CBlockBasis::SetBlkNum (int iNum)
{
m_iBlkNum = iNum;
}
CBlockBasis* CBlockBasis::GetBlkHead1Ptr () const
{
return NULL;
}
CBlockBasis* CBlockBasis::GetBlkHead1Ptr (int iIndex) const
{
return NULL;
}
CBlockBasis* CBlockBasis::GetBlkHead2Ptr () const
{
return NULL;
}
void CBlockBasis::SetBlkHead1Ptr (CBlockBasis* pBlkHead)
{
}
void CBlockBasis::SetBlkHead2Ptr (CBlockBasis* pBlkHead)
{
}
void CBlockBasis::DeleteBlkHead1Ptr (int iIndex)
{
}
int CBlockBasis::GetBlkHead1Num () const
{
return NO_BLOCK_HEAD;
}
int CBlockBasis::GetBlkHead1Num (int iIndex) const
{
return NO_BLOCK_HEAD;
}
int CBlockBasis::GetBlkHead2Num () const
{
return NO_BLOCK_HEAD;
}
void CBlockBasis::SetBlkHead1Num (int iHeadBlkNum)
{
}
void CBlockBasis::SetBlkHead2Num (int iHeadBlkNum)
{
}
void CBlockBasis::ClearBlkHead1Num ()
{
}
int CBlockBasis::GetBlkHeadSize () const
{
return NO_BLOCK_HEAD;
}
void CBlockBasis::SetBlkHeadSize (int)
{
}
int CBlockBasis::GetInputFlag () const
{
return NO_INPUT_FLAG;
}
void CBlockBasis::SetInputFlag (int iInputFlag)
{
}
int CBlockBasis::GetOperFlag () const
{
return NO_OPER_FLAG;
}
void CBlockBasis::SetOperFlag (int iInputFlag)
{
}
double CBlockBasis::GetBlkValue () const
{
return NO_VALUE;
}
double CBlockBasis::GetBlkValue (int iIndex) const
{
return NO_VALUE;
}
void CBlockBasis::SetBlkValue (double dBlkValue)
{
}
void CBlockBasis::SetBlkValue ()
{
}
int CBlockBasis::GetValueFlag () const
{
return NO_VALUE;
}
int CBlockBasis::GetValueFlag (int iIndex) const
{
return NO_VALUE;
}
//移動Block時依鼠標位置設定Block rect
void CBlockBasis::Move (CPoint ptCursor)
{
m_rcBlk.SetRect (CPoint (ptCursor.x - int (m_rcBlk.Width () / 2.), ptCursor.y - int (m_rcBlk.Height () / 2.)),
CPoint (ptCursor.x + int (m_rcBlk.Width () / 2.), ptCursor.y + int (m_rcBlk.Height () / 2.)));
}
void CBlockBasis::Draw (CDC* pDC)
{
pDC->FillSolidRect (m_rcBlk, LIGHTGRAY);
pDC->DrawEdge (m_rcBlk, EDGE_RAISED, BF_RECT);
}
void CBlockBasis::DrawLine (CDC* pDC)
{
}
int CBlockBasis::BlkTypeIs () const
{
return NO_BLK_TYPE;
}

View File

@ -0,0 +1,68 @@
#pragma once
//Block基礎類別
class CBlockBasis
{
protected:
CRect m_rcBlk; //Block rect
int m_iBlkNum; //Block於vector中的編號
public:
//建構、解構子
CBlockBasis ();
virtual ~CBlockBasis ();
//取得、設定rect
CRect GetBlkRect () const;
virtual void SetBlkRect (CPoint, int, int);
virtual CRect GetPinIn1Rect () const;
virtual CRect GetPinIn2Rect () const;
virtual CRect GetPinOutRect () const;
//取得、設定Block編號
int GetBlkNum () const;
void SetBlkNum (int);
//取得、設定連接至Block的指標
virtual CBlockBasis* GetBlkHead1Ptr () const;
virtual CBlockBasis* GetBlkHead1Ptr (int) const;
virtual CBlockBasis* GetBlkHead2Ptr () const;
virtual void SetBlkHead1Ptr (CBlockBasis*);
virtual void SetBlkHead2Ptr (CBlockBasis*);
virtual void DeleteBlkHead1Ptr (int); //自Block Out連接指標vector中清除指定的指標
//取得、設定連接至Block的編號
virtual int GetBlkHead1Num () const;
virtual int GetBlkHead1Num (int) const;
virtual int GetBlkHead2Num () const;
virtual void SetBlkHead1Num (int) ;
virtual void SetBlkHead2Num (int) ;
virtual void ClearBlkHead1Num (); //清空Block Out連接編號vector
//取得、設定連接Block Out的數目
virtual int GetBlkHeadSize () const;
virtual void SetBlkHeadSize (int);
//取得、設定Block In, Fun的flag
virtual int GetInputFlag () const;
virtual void SetInputFlag (int);
virtual int GetOperFlag () const;
virtual void SetOperFlag (int);
//取得、設定Block值
virtual double GetBlkValue () const;
virtual double GetBlkValue (int) const; //取得Block Out指定channel的值
virtual void SetBlkValue (double);
virtual void SetBlkValue ();
virtual int GetValueFlag () const;
virtual int GetValueFlag (int) const;
virtual void Move (CPoint); //移動Block
virtual void Draw (CDC*); //繪製Block
virtual void DrawLine (CDC*); //繪製Block連接線
//判斷Block種類
virtual int BlkTypeIs () const;
};

257
TestSimulator/BlockFun.cpp Normal file
View File

@ -0,0 +1,257 @@
#include "stdafx.h"
#include "BlockFun.h"
#define PIN_RADIUS 8 //Pin半徑
#define GOLD RGB (255, 215, 0) //Pin腳顏色
#define BLACK RGB (0, 0, 0) //連線顏色
#define FALSE_VALUE 10 //FALSE回傳值
#define TRUE_VALUE 11 //TRUE回傳值
#define NO_VALUE -10 //不存在輸入訊號
#define NO_OPER_FLAG -11 //不存在運算元
#define NO_INPUT_FLAG -12 //不存在輸入波形
#define COMPUTE_ERROR -13 //不允許的運算
#define NO_BLOCK_HEAD -14 //不存在連接Block
#define PLUS 1 // + flag
#define MINUS 2 // - flag
#define MULTI 3 // * flag
#define DIV 4 // / flag
#define DIGITAL_VALUE 4 //數位訊號flag
#define ANALOG_VALUE 5 //類比訊號flag
#define BLK_FUN 6 //Block種類編號
CBlockFun::CBlockFun ()
{
m_rcPinIn1 = CRect ();
m_rcPinIn2 = CRect ();
m_rcPinOut = CRect ();
m_pBlkHead1 = NULL;
m_pBlkHead2 = NULL;
m_iBlkHead1Num = NO_BLOCK_HEAD;
m_iBlkHead2Num = NO_BLOCK_HEAD;
m_iOperFlag = NO_OPER_FLAG;
}
CBlockFun::~CBlockFun ()
{
}
void CBlockFun::SetBlkRect (CPoint ptCenter, int iWidth, int iHeight)
{
CBlockBasis::SetBlkRect (ptCenter, iWidth, iHeight);
m_rcPinIn1.left = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn1.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn1.right = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn1.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinIn2.left = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn2.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn2.right = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn2.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinOut.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinOut.top = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinOut.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinOut.bottom = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) + PIN_RADIUS;
}
CRect CBlockFun::GetPinIn1Rect () const
{
return m_rcPinIn1;
}
CRect CBlockFun::GetPinIn2Rect () const
{
return m_rcPinIn2;
}
CRect CBlockFun::GetPinOutRect () const
{
return m_rcPinOut;
}
CBlockBasis* CBlockFun::GetBlkHead1Ptr () const
{
return m_pBlkHead1;
}
CBlockBasis* CBlockFun::GetBlkHead2Ptr () const
{
return m_pBlkHead2;
}
void CBlockFun::SetBlkHead1Ptr (CBlockBasis* pBlkHead1)
{
m_pBlkHead1 = pBlkHead1;
}
void CBlockFun::SetBlkHead2Ptr (CBlockBasis* pBlkHead2)
{
m_pBlkHead2 = pBlkHead2;
}
int CBlockFun::GetBlkHead1Num () const
{
return m_iBlkHead1Num;
}
int CBlockFun::GetBlkHead2Num () const
{
return m_iBlkHead2Num;
}
void CBlockFun::SetBlkHead1Num (int iHeadBlkNum)
{
m_iBlkHead1Num = iHeadBlkNum;
}
void CBlockFun::SetBlkHead2Num (int iHeadBlkNum)
{
m_iBlkHead2Num = iHeadBlkNum;
}
double CBlockFun::GetBlkValue () const
{
switch (m_iOperFlag)
{
case PLUS: //將兩輸入值相加
return m_pBlkHead1->GetBlkValue () + m_pBlkHead2->GetBlkValue ();
break;
case MINUS: //將兩輸入值相減
return m_pBlkHead1->GetBlkValue () - m_pBlkHead2->GetBlkValue ();
break;
case MULTI: //將兩輸入值相乘
return m_pBlkHead1->GetBlkValue () * m_pBlkHead2->GetBlkValue ();
break;
case DIV: //將兩輸入值相除
return m_pBlkHead1->GetBlkValue () / m_pBlkHead2->GetBlkValue ();
break;
default:
return NO_VALUE;
break;
}
}
int CBlockFun::GetValueFlag () const
{
if (m_pBlkHead1 == NULL || m_pBlkHead2 == NULL) //若存在任一輸入接點未連接,回傳"無值"
return NO_VALUE;
else if (m_pBlkHead1->GetValueFlag () == NO_VALUE || m_pBlkHead2->GetValueFlag () == NO_VALUE) //若存在任一輸入為無值,回傳"無值"
return NO_VALUE;
else if (m_pBlkHead1->GetValueFlag () == COMPUTE_ERROR || m_pBlkHead2->GetValueFlag () == COMPUTE_ERROR) //若存在任一輸入為計算錯誤,回傳"計算錯誤"
return COMPUTE_ERROR;
else if (m_pBlkHead1->GetValueFlag () == DIGITAL_VALUE || m_pBlkHead2->GetValueFlag () == DIGITAL_VALUE) //不允許數位輸入
return COMPUTE_ERROR;
else if (m_iOperFlag == NO_OPER_FLAG) //未設定運算元
return NO_OPER_FLAG;
else if (m_pBlkHead1->GetValueFlag () == NO_OPER_FLAG || m_pBlkHead2->GetValueFlag () == NO_OPER_FLAG) //未設定運算元
return NO_OPER_FLAG;
else if (m_pBlkHead1->GetValueFlag () == ANALOG_VALUE && m_pBlkHead2->GetValueFlag () == ANALOG_VALUE) //若輸入皆為類比訊號,則回傳類比訊號
return ANALOG_VALUE;
else
return NO_VALUE;
}
int CBlockFun::GetOperFlag () const
{
return m_iOperFlag;
}
void CBlockFun::SetOperFlag (int iOperFlag)
{
m_iOperFlag = iOperFlag;
}
void CBlockFun::Move (CPoint ptCursor)
{
CBlockBasis::Move (ptCursor);
m_rcPinIn1.left = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn1.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn1.right = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn1.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinIn2.left = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn2.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn2.right = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn2.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinOut.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinOut.top = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinOut.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinOut.bottom = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) + PIN_RADIUS;
}
void CBlockFun::Draw (CDC* pDC)
{
CBrush brushPin (GOLD), * pOldBrush;
pOldBrush = pDC->SelectObject (&brushPin);
pDC->Ellipse (m_rcPinIn1);
pDC->Ellipse (m_rcPinIn2);
pDC->Ellipse (m_rcPinOut);
pDC->SelectObject (pOldBrush);
CBlockBasis::Draw (pDC);
pDC->DrawTextA (_T ("FUN"), -1, &m_rcBlk, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
void CBlockFun::DrawLine (CDC* pDC)
{
if (m_pBlkHead1 != NULL)
{
CPen penLine (PS_SOLID, 5, BLACK);
CPen* pOldPen;
pOldPen = pDC->SelectObject (&penLine);
CPoint ptStart = m_pBlkHead1->GetPinOutRect ().CenterPoint (); //連線起點為輸入Block的輸出Pin腳中心點
CPoint ptEnd = m_rcPinIn1.CenterPoint (); //連線終點為此Block的輸入Pin腳中心點
int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //垂直格點間隔
int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //計算連線轉折處距離輸入Block幾個隔點
int iCornerY = iCornerGridY * iGrid + ptStart.y; //連線轉折處Y座標位置
pDC->MoveTo (ptStart);
pDC->LineTo (CPoint (ptStart.x, iCornerY));
pDC->MoveTo (CPoint (ptStart.x, iCornerY));
pDC->LineTo (CPoint (ptEnd.x, iCornerY));
pDC->MoveTo (CPoint (ptEnd.x, iCornerY));
pDC->LineTo (ptEnd);
pDC->SelectObject (pOldPen);
}
if (m_pBlkHead2 != NULL)
{
CPen penLine (PS_SOLID, 5, BLACK);
CPen* pOldPen;
pOldPen = pDC->SelectObject (&penLine);
CPoint ptStart = m_pBlkHead2->GetPinOutRect ().CenterPoint (); //連線起點為輸入Block的輸出Pin腳中心點
CPoint ptEnd = m_rcPinIn2.CenterPoint (); //連線終點為此Block的輸入Pin腳中心點
int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //垂直格點間隔
int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //計算連線轉折處距離輸入Block幾個隔點
int iCornerY = iCornerGridY * iGrid + ptStart.y; //連線轉折處Y座標位置
pDC->MoveTo (ptStart);
pDC->LineTo (CPoint (ptStart.x, iCornerY));
pDC->MoveTo (CPoint (ptStart.x, iCornerY));
pDC->LineTo (CPoint (ptEnd.x, iCornerY));
pDC->MoveTo (CPoint (ptEnd.x, iCornerY));
pDC->LineTo (ptEnd);
pDC->SelectObject (pOldPen);
}
}
int CBlockFun::BlkTypeIs () const
{
return BLK_FUN;
}

62
TestSimulator/BlockFun.h Normal file
View File

@ -0,0 +1,62 @@
#pragma once
//Block衍生類別Block Fun
#include "BlockBasis.h"
class CBlockFun : public CBlockBasis
{
private:
//Block rect(存在兩個輸入Pin一個輸出Pin)
CRect m_rcPinIn1;
CRect m_rcPinIn2;
CRect m_rcPinOut;
//連接指標(存在兩個連接指標)
CBlockBasis* m_pBlkHead1;
CBlockBasis* m_pBlkHead2;
//連接Block編號(存在兩個編號)
int m_iBlkHead1Num;
int m_iBlkHead2Num;
//運算元flag
int m_iOperFlag;
public:
//建構、解構子
CBlockFun ();
virtual ~CBlockFun ();
//取得、設定rect
virtual void SetBlkRect (CPoint, int, int);
virtual CRect GetPinIn1Rect () const;
virtual CRect GetPinIn2Rect () const;
virtual CRect GetPinOutRect () const;
//取得、設定連接至Block的指標
virtual CBlockBasis* GetBlkHead1Ptr () const;
virtual CBlockBasis* GetBlkHead2Ptr () const;
virtual void SetBlkHead1Ptr (CBlockBasis*);
virtual void SetBlkHead2Ptr (CBlockBasis*);
//取得、設定連接至Block的編號
virtual int GetBlkHead1Num () const;
virtual int GetBlkHead2Num () const;
virtual void SetBlkHead1Num (int) ;
virtual void SetBlkHead2Num (int) ;
//取得、設定運算元flag
virtual int GetOperFlag () const;
virtual void SetOperFlag (int);
virtual double GetBlkValue () const; //取得Block值
virtual int GetValueFlag () const; //取得Value旗標
virtual void Move (CPoint); //移動Block
virtual void Draw (CDC*); //繪製Block
virtual void DrawLine (CDC*); //繪製Block連接線
//判斷Block種類
virtual int BlkTypeIs () const;
};

152
TestSimulator/BlockIn.cpp Normal file
View File

@ -0,0 +1,152 @@
#include "stdafx.h"
#include "BlockIn.h"
#include "math.h"
#define PIN_RADIUS 8 //Pin半徑
#define GOLD RGB (255, 215, 0) //Pin腳顏色
#define NO_VALUE -10 //不存在輸入訊號
#define NO_INPUT_FLAG -12 //不存在輸入波形
#define ZERO 0 //FALSE flag
#define ONE 1 //TRUE flag
#define SIN 2 //Sin flag
#define COS 3 //Cos flag
#define DIGITAL_VALUE 4 //數位訊號flag
#define ANALOG_VALUE 5 //類比訊號flag
#define BLK_IN 1 //Block種類編號
CBlockIn::CBlockIn ()
{
m_rcPinOut = CRect ();
m_iInputFlag = NO_INPUT_FLAG;
m_dBlkValue = NO_VALUE;
}
CBlockIn::~CBlockIn ()
{
}
void CBlockIn::SetBlkRect (CPoint ptCenter, int iWidth, int iHeight)
{
CBlockBasis::SetBlkRect (ptCenter, iWidth, iHeight);
m_rcPinOut.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinOut.top = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinOut.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinOut.bottom = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) + PIN_RADIUS;
}
CRect CBlockIn::GetPinOutRect () const
{
return m_rcPinOut;
}
int CBlockIn::GetInputFlag() const
{
return m_iInputFlag;
}
void CBlockIn::SetInputFlag(int iInputFlag)
{
m_iInputFlag = iInputFlag;
}
double CBlockIn::GetBlkValue () const
{
return m_dBlkValue;
}
//用以設定指定時間點下Block值 (Sin, Cos)
void CBlockIn::SetBlkValue (double dTime)
{
switch (m_iInputFlag)
{
case ZERO:
m_dBlkValue = 0.;
break;
case ONE:
m_dBlkValue = 1.;
break;
case SIN:
m_dBlkValue = sin (dTime);
break;
case COS:
m_dBlkValue = cos (dTime);
break;
default:
m_dBlkValue = NO_VALUE;
break;
}
}
//設定Block值 (TRUE, FALSE)
void CBlockIn::SetBlkValue ()
{
switch (m_iInputFlag)
{
case ZERO:
m_dBlkValue = 0.;
break;
case ONE:
m_dBlkValue = 1.;
break;
default:
m_dBlkValue = NO_VALUE;
break;
}
}
int CBlockIn::GetValueFlag () const
{
switch (m_iInputFlag)
{
case ZERO: //輸入波形為TRUE時回傳數位訊號
return DIGITAL_VALUE;
break;
case ONE: //輸入波形為FALSE時回傳數位訊號
return DIGITAL_VALUE;
break;
case SIN: //輸入波形為SIN時回傳類比訊號
return ANALOG_VALUE;
break;
case COS: //輸入波形為COS時回傳類比訊號
return ANALOG_VALUE;
break;
default:
return NO_VALUE;
break;
}
}
void CBlockIn::Move (CPoint ptCursor)
{
CBlockBasis::Move (ptCursor);
m_rcPinOut.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinOut.top = m_rcBlk.bottom - PIN_RADIUS;
m_rcPinOut.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinOut.bottom = m_rcBlk.bottom + PIN_RADIUS;
}
void CBlockIn::Draw (CDC* pDC)
{
CBrush brushPin (GOLD), * pbrushOld;
pbrushOld = pDC->SelectObject (&brushPin);
pDC->Ellipse (m_rcPinOut);
pDC->SelectObject (pbrushOld);
CBlockBasis::Draw (pDC);
pDC->DrawTextA (_T ("IN"), -1, &m_rcBlk, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
int CBlockIn::BlkTypeIs () const
{
return BLK_IN;
}

43
TestSimulator/BlockIn.h Normal file
View File

@ -0,0 +1,43 @@
#pragma once
//Block衍生類別Block In
#include "BlockBasis.h"
class CBlockIn : public CBlockBasis
{
private:
//Block rect(存在一個輸出Pin)
CRect m_rcPinOut;
//輸入波形flag
int m_iInputFlag;
//Block值
double m_dBlkValue;
public:
//建構、解構子
CBlockIn ();
virtual ~CBlockIn ();
//取得、設定rect
virtual void SetBlkRect (CPoint, int, int);
virtual CRect GetPinOutRect () const;
//取得、設定輸入波形flag
virtual int GetInputFlag () const;
virtual void SetInputFlag (int);
//取得、設定Block值
virtual double GetBlkValue () const;
virtual void SetBlkValue (double);
virtual void SetBlkValue ();
virtual int GetValueFlag () const; //取得Value旗標
virtual void Move (CPoint); //移動Block
virtual void Draw (CDC*); //繪製Block
//判斷Block種類
virtual int BlkTypeIs () const;
};

164
TestSimulator/BlockNot.cpp Normal file
View File

@ -0,0 +1,164 @@
#include "stdafx.h"
#include "BlockNot.h"
#define PIN_RADIUS 8 //Pin半徑
#define GOLD RGB (255, 215, 0) //Pin腳顏色
#define BLACK RGB (0, 0, 0) //連線顏色
#define NO_VALUE -10 //不存在輸入訊號
#define NO_OPER_FLAG -11 //不存在運算元
#define COMPUTE_ERROR -13 //不允許的運算
#define NO_BLOCK_HEAD -14 //不存在連接Block
#define TOLERANCE 0.001 //容忍誤差值
#define DIGITAL_VALUE 4 //數位訊號flag
#define ANALOG_VALUE 5 //類比訊號flag
#define BLK_NOT 5 //Block種類編號
CBlockNot::CBlockNot ()
{
m_rcPinIn = CRect ();
m_rcPinOut = CRect ();
m_pBlkHead = NULL;
m_iBlkHeadNum = NO_BLOCK_HEAD;
}
CBlockNot::~CBlockNot ()
{
}
void CBlockNot::SetBlkRect (CPoint ptCenter, int iWidth, int iHeight)
{
CBlockBasis::SetBlkRect (ptCenter, iWidth, iHeight);
m_rcPinIn.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinIn.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinIn.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinOut.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinOut.top = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinOut.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinOut.bottom = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) + PIN_RADIUS;
}
CRect CBlockNot::GetPinIn1Rect () const
{
return m_rcPinIn;
}
CRect CBlockNot::GetPinOutRect () const
{
return m_rcPinOut;
}
CBlockBasis* CBlockNot::GetBlkHead1Ptr () const
{
return m_pBlkHead;
}
void CBlockNot::SetBlkHead1Ptr (CBlockBasis* pBlkHead)
{
m_pBlkHead = pBlkHead;
}
int CBlockNot::GetBlkHead1Num () const
{
return m_iBlkHeadNum;
}
void CBlockNot::SetBlkHead1Num (int iHeadBlkNum)
{
m_iBlkHeadNum = iHeadBlkNum;
}
double CBlockNot::GetBlkValue () const
{
//Not邏輯 (若輸入為0則回傳1反之回傳0)
if (m_pBlkHead->GetBlkValue () < TOLERANCE)
return 1.;
else
return 0.;
}
int CBlockNot::GetValueFlag () const
{
if (m_pBlkHead == NULL) //若輸入接點未連接,回傳"無值"
return NO_VALUE;
else if (m_pBlkHead->GetValueFlag () == NO_VALUE) //若輸入為無值,回傳"無值"
return NO_VALUE;
else if (m_pBlkHead->GetValueFlag () == COMPUTE_ERROR) //若輸入為計算錯誤,回傳"計算錯誤"
return COMPUTE_ERROR;
else if (m_pBlkHead->GetValueFlag () == ANALOG_VALUE) //不允許類比輸入
return COMPUTE_ERROR;
else if (m_pBlkHead->GetValueFlag () == NO_OPER_FLAG) //未設定運算元
return NO_OPER_FLAG;
else if (m_pBlkHead->GetValueFlag () == DIGITAL_VALUE) //若輸入為數位訊號,則回傳數位訊號
return DIGITAL_VALUE;
else
return NO_VALUE;
}
void CBlockNot::Move (CPoint ptCursor)
{
CBlockBasis::Move (ptCursor);
m_rcPinIn.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinIn.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinIn.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinOut.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinOut.top = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinOut.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinOut.bottom = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) + PIN_RADIUS;
}
void CBlockNot::Draw (CDC* pDC)
{
CBrush brushPin (GOLD), * pbrushOld;
pbrushOld = pDC->SelectObject (&brushPin);
pDC->Ellipse (m_rcPinIn);
pDC->Ellipse (m_rcPinOut);
pDC->SelectObject (pbrushOld);
CBlockBasis::Draw (pDC);
pDC->DrawTextA (_T ("NOT"), -1, &m_rcBlk, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
void CBlockNot::DrawLine (CDC* pDC)
{
if (m_pBlkHead != NULL)
{
CPen penLine (PS_SOLID, 5, BLACK);
CPen* pOldPen;
pOldPen = pDC->SelectObject (&penLine);
CPoint ptStart = m_pBlkHead->GetPinOutRect ().CenterPoint (); //連線起點為輸入Block的輸出Pin腳中心點
CPoint ptEnd = m_rcPinIn.CenterPoint (); //連線終點為此Block的輸入Pin腳中心點
int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //垂直格點間隔
int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //計算連線轉折處距離輸入Block幾個隔點
int iCornerY = iCornerGridY * iGrid + ptStart.y; //連線轉折處Y座標位置
pDC->MoveTo (ptStart);
pDC->LineTo (CPoint (ptStart.x, iCornerY));
pDC->MoveTo (CPoint (ptStart.x, iCornerY));
pDC->LineTo (CPoint (ptEnd.x, iCornerY));
pDC->MoveTo (CPoint (ptEnd.x, iCornerY));
pDC->LineTo (ptEnd);
pDC->SelectObject (pOldPen);
}
}
int CBlockNot::BlkTypeIs () const
{
return BLK_NOT;
}

47
TestSimulator/BlockNot.h Normal file
View File

@ -0,0 +1,47 @@
#pragma once
//Block衍生類別Block Not
#include "BlockBasis.h"
class CBlockNot : public CBlockBasis
{
private:
//Block rect(存在一個輸入Pin一個輸出Pin)
CRect m_rcPinIn;
CRect m_rcPinOut;
//連接指標
CBlockBasis* m_pBlkHead;
//連接Block編號
int m_iBlkHeadNum;
public:
//建構、解構子
CBlockNot ();
virtual ~CBlockNot ();
//取得、設定rect
virtual void SetBlkRect (CPoint, int, int);
virtual CRect GetPinIn1Rect () const;
virtual CRect GetPinOutRect () const;
//取得、設定連接至Block的指標
virtual CBlockBasis* GetBlkHead1Ptr () const;
virtual void SetBlkHead1Ptr (CBlockBasis*);
//取得、設定連接至Block的編號
virtual int GetBlkHead1Num () const;
virtual void SetBlkHead1Num (int) ;
virtual double GetBlkValue () const; //取得Block值
virtual int GetValueFlag () const; //取得Value旗標
virtual void Move (CPoint); //移動Block
virtual void Draw (CDC*); //繪製Block
virtual void DrawLine (CDC*); //繪製Block連接線
//判斷Block種類
virtual int BlkTypeIs () const;
};

226
TestSimulator/BlockOr.cpp Normal file
View File

@ -0,0 +1,226 @@
#include "stdafx.h"
#include "BlockOr.h"
#include "math.h"
#define PIN_RADIUS 8 //Pin半徑
#define GOLD RGB (255, 215, 0) //Pin腳顏色
#define BLACK RGB (0, 0, 0) //連線顏色
#define NO_VALUE -10 //不存在輸入訊號
#define NO_OPER_FLAG -11 //不存在運算元
#define COMPUTE_ERROR -13 //不允許的運算
#define NO_BLOCK_HEAD -14 //不存在連接Block
#define TOLERANCE 0.001 //容忍誤差值
#define DIGITAL_VALUE 4 //數位訊號flag
#define ANALOG_VALUE 5 //類比訊號flag
#define BLK_OR 4 //Block種類編號
CBlockOr::CBlockOr ()
{
m_rcPinIn1 = CRect ();
m_rcPinIn2 = CRect ();
m_rcPinOut = CRect ();
m_pBlkHead1 = NULL;
m_pBlkHead2 = NULL;
m_iBlkHead1Num = NO_BLOCK_HEAD;
m_iBlkHead2Num = NO_BLOCK_HEAD;
}
CBlockOr::~CBlockOr ()
{
}
void CBlockOr::SetBlkRect (CPoint ptCenter, int iWidth, int iHeight)
{
CBlockBasis::SetBlkRect (ptCenter, iWidth, iHeight);
m_rcPinIn1.left = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn1.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn1.right = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn1.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinIn2.left = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn2.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn2.right = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn2.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinOut.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinOut.top = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinOut.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinOut.bottom = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) + PIN_RADIUS;
}
CRect CBlockOr::GetPinIn1Rect () const
{
return m_rcPinIn1;
}
CRect CBlockOr::GetPinIn2Rect () const
{
return m_rcPinIn2;
}
CRect CBlockOr::GetPinOutRect () const
{
return m_rcPinOut;
}
CBlockBasis* CBlockOr::GetBlkHead1Ptr () const
{
return m_pBlkHead1;
}
CBlockBasis* CBlockOr::GetBlkHead2Ptr () const
{
return m_pBlkHead2;
}
void CBlockOr::SetBlkHead1Ptr (CBlockBasis* pBlkHead)
{
m_pBlkHead1 = pBlkHead;
}
void CBlockOr::SetBlkHead2Ptr (CBlockBasis* pBlkHead)
{
m_pBlkHead2 = pBlkHead;
}
int CBlockOr::GetBlkHead1Num () const
{
return m_iBlkHead1Num;
}
int CBlockOr::GetBlkHead2Num () const
{
return m_iBlkHead2Num;
}
void CBlockOr::SetBlkHead1Num (int iHeadBlkNum)
{
m_iBlkHead1Num = iHeadBlkNum;
}
void CBlockOr::SetBlkHead2Num (int iHeadBlkNum)
{
m_iBlkHead2Num = iHeadBlkNum;
}
double CBlockOr::GetBlkValue () const
{
//Or邏輯 (若其中一輸入為1則回傳1否則回傳0)
if (abs (m_pBlkHead1->GetBlkValue () - 1) < TOLERANCE || abs (m_pBlkHead2->GetBlkValue () - 1) < TOLERANCE)
return 1.;
else
return 0.;
}
int CBlockOr::GetValueFlag () const
{
if (m_pBlkHead1 == NULL || m_pBlkHead2 == NULL) //若存在任一輸入接點未連接,回傳"無值"
return NO_VALUE;
else if (m_pBlkHead1->GetValueFlag () == NO_VALUE || m_pBlkHead2->GetValueFlag () == NO_VALUE) //若存在任一輸入為無值,回傳"無值"
return NO_VALUE;
else if (m_pBlkHead1->GetValueFlag () == COMPUTE_ERROR || m_pBlkHead2->GetValueFlag () == COMPUTE_ERROR) //若存在任一輸入為計算錯誤,回傳"計算錯誤"
return COMPUTE_ERROR;
else if (m_pBlkHead1->GetValueFlag () == ANALOG_VALUE || m_pBlkHead2->GetValueFlag () == ANALOG_VALUE) //不允許類比輸入
return COMPUTE_ERROR;
else if (m_pBlkHead1->GetValueFlag () == NO_OPER_FLAG || m_pBlkHead2->GetValueFlag () == NO_OPER_FLAG) //未設定運算元
return NO_OPER_FLAG;
else if (m_pBlkHead1->GetValueFlag () == DIGITAL_VALUE && m_pBlkHead2->GetValueFlag () == DIGITAL_VALUE) //若輸入皆為數位訊號,則回傳數位訊號
return DIGITAL_VALUE;
else
return NO_VALUE;
}
void CBlockOr::Move (CPoint ptCursor)
{
CBlockBasis::Move (ptCursor);
m_rcPinIn1.left = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn1.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn1.right = m_rcBlk.CenterPoint ().x - int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn1.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinIn2.left = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) - PIN_RADIUS;
m_rcPinIn2.top = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinIn2.right = m_rcBlk.CenterPoint ().x + int (m_rcBlk.Width () / 4) + PIN_RADIUS;
m_rcPinIn2.bottom = m_rcBlk.CenterPoint ().y - int (m_rcBlk.Height () / 2) + PIN_RADIUS;
m_rcPinOut.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinOut.top = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) - PIN_RADIUS;
m_rcPinOut.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinOut.bottom = m_rcBlk.CenterPoint ().y + int (m_rcBlk.Height () / 2) + PIN_RADIUS;
}
void CBlockOr::Draw (CDC* pDC)
{
CBrush brushPin (GOLD), * pbrushOld;
pbrushOld = pDC->SelectObject (&brushPin);
pDC->Ellipse (m_rcPinIn1);
pDC->Ellipse (m_rcPinIn2);
pDC->Ellipse (m_rcPinOut);
pDC->SelectObject (pbrushOld);
CBlockBasis::Draw (pDC);
pDC->DrawTextA (_T ("OR"), -1, &m_rcBlk, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
void CBlockOr::DrawLine (CDC* pDC)
{
if (m_pBlkHead1 != NULL)
{
CPen penLine (PS_SOLID, 5, BLACK);
CPen* pOldPen;
pOldPen = pDC->SelectObject (&penLine);
CPoint ptStart = m_pBlkHead1->GetPinOutRect ().CenterPoint (); //連線起點為輸入Block的輸出Pin腳中心點
CPoint ptEnd = m_rcPinIn1.CenterPoint (); //連線終點為此Block的輸入Pin腳中心點
int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //垂直格點間隔
int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //計算連線轉折處距離輸入Block幾個隔點
int iCornerY = iCornerGridY * iGrid + ptStart.y; //連線轉折處Y座標位置
pDC->MoveTo (ptStart);
pDC->LineTo (CPoint (ptStart.x, iCornerY));
pDC->MoveTo (CPoint (ptStart.x, iCornerY));
pDC->LineTo (CPoint (ptEnd.x, iCornerY));
pDC->MoveTo (CPoint (ptEnd.x, iCornerY));
pDC->LineTo (ptEnd);
pDC->SelectObject (pOldPen);
}
if (m_pBlkHead2 != NULL)
{
CPen penLine (PS_SOLID, 5, BLACK);
CPen* pOldPen;
pOldPen = pDC->SelectObject (&penLine);
CPoint ptStart = m_pBlkHead2->GetPinOutRect ().CenterPoint (); //連線起點為輸入Block的輸出Pin腳中心點
CPoint ptEnd = m_rcPinIn2.CenterPoint (); //連線終點為此Block的輸入Pin腳中心點
int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //垂直格點間隔
int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //計算連線轉折處距離輸入Block幾個隔點
int iCornerY = iCornerGridY * iGrid + ptStart.y; //連線轉折處Y座標位置
pDC->MoveTo (ptStart);
pDC->LineTo (CPoint (ptStart.x, iCornerY));
pDC->MoveTo (CPoint (ptStart.x, iCornerY));
pDC->LineTo (CPoint (ptEnd.x, iCornerY));
pDC->MoveTo (CPoint (ptEnd.x, iCornerY));
pDC->LineTo (ptEnd);
pDC->SelectObject (pOldPen);
}
}
int CBlockOr::BlkTypeIs () const
{
return BLK_OR;
}

55
TestSimulator/BlockOr.h Normal file
View File

@ -0,0 +1,55 @@
#pragma once
//Block衍生類別Block Or
#include "BlockBasis.h"
class CBlockOr : public CBlockBasis
{
private:
//Block rect(存在兩個輸入Pin一個輸出Pin)
CRect m_rcPinIn1;
CRect m_rcPinIn2;
CRect m_rcPinOut;
//連接指標(存在兩個連接指標)
CBlockBasis* m_pBlkHead1;
CBlockBasis* m_pBlkHead2;
//連接Block編號(存在兩個編號)
int m_iBlkHead1Num;
int m_iBlkHead2Num;
public:
//建構、解構子
CBlockOr ();
virtual ~CBlockOr ();
//取得、設定rect
virtual void SetBlkRect (CPoint, int, int);
virtual CRect GetPinIn1Rect () const;
virtual CRect GetPinIn2Rect () const;
virtual CRect GetPinOutRect () const;
//取得、設定連接至Block的指標
virtual CBlockBasis* GetBlkHead1Ptr () const;
virtual CBlockBasis* GetBlkHead2Ptr () const;
virtual void SetBlkHead1Ptr (CBlockBasis*);
virtual void SetBlkHead2Ptr (CBlockBasis*);
//取得、設定連接至Block的編號
virtual int GetBlkHead1Num () const;
virtual int GetBlkHead2Num () const;
virtual void SetBlkHead1Num (int) ;
virtual void SetBlkHead2Num (int) ;
virtual double GetBlkValue () const; //取得Block值
virtual int GetValueFlag () const; //取得Value旗標
virtual void Move (CPoint); //移動Block
virtual void Draw (CDC*); //繪製Block
virtual void DrawLine (CDC*); //繪製Block連接線
//判斷Block種類
virtual int BlkTypeIs () const;
};

163
TestSimulator/BlockOut.cpp Normal file
View File

@ -0,0 +1,163 @@
#include "stdafx.h"
#include "BlockOut.h"
#define PIN_RADIUS 8 //Pin半徑
#define GOLD RGB (255, 215, 0) //Pin腳顏色
#define BLACK RGB (0, 0, 0) //連線顏色
#define NO_VALUE -10 //不存在輸入訊號
#define NO_BLOCK_HEAD -14 //不存在連接Block
#define BLK_OUT 2 //Block種類編號
CBlockOut::CBlockOut ()
{
m_rcPinIn = CRect ();
m_iBlkHeadSize = (int) m_vcBlkHeadPtr.size ();
}
CBlockOut::~CBlockOut ()
{
}
void CBlockOut::SetBlkRect (CPoint ptCenter, int iWidth, int iHeight)
{
CBlockBasis::SetBlkRect (ptCenter, iWidth, iHeight);
m_rcPinIn.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinIn.top = m_rcBlk.top - PIN_RADIUS;
m_rcPinIn.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinIn.bottom = m_rcBlk.top + PIN_RADIUS;
}
CRect CBlockOut::GetPinIn1Rect () const
{
return m_rcPinIn;
}
CBlockBasis* CBlockOut::GetBlkHead1Ptr (int iIndex) const
{
//回傳指定index的連接指標
if (iIndex < m_iBlkHeadSize)
return m_vcBlkHeadPtr[iIndex];
else
return NULL;
}
void CBlockOut::SetBlkHead1Ptr (CBlockBasis* pBlkHead)
{
m_vcBlkHeadPtr.push_back (pBlkHead); //新增連接指標
}
void CBlockOut::DeleteBlkHead1Ptr (int iIndex)
{
m_vcBlkHeadPtr.erase (m_vcBlkHeadPtr.begin () + iIndex); //清除指定index的連接指標
}
int CBlockOut::GetBlkHead1Num (int iIndex) const
{
//回傳指定index的連接Block編號
if (iIndex < m_iBlkHeadSize)
return m_vcBlkHeadNum[iIndex];
else
return NO_BLOCK_HEAD;
}
void CBlockOut::SetBlkHead1Num (int iHeadBlkNum)
{
m_vcBlkHeadNum.push_back (iHeadBlkNum); //新增連接Block編號
}
void CBlockOut::ClearBlkHead1Num ()
{
std::vector <int> ().swap (m_vcBlkHeadNum); //清空連接編號vector
}
int CBlockOut::GetBlkHeadSize () const
{
return m_iBlkHeadSize; //回傳輸入channel數目
}
void CBlockOut::SetBlkHeadSize (int iFlag)
{
//設定輸入channel數目
if (iFlag == FALSE) //當flag為FALSE時依連接編號vector大小設定
m_iBlkHeadSize = (int) m_vcBlkHeadNum.size ();
else if (iFlag == TRUE) //當flag為TRUE時依連接指標vector大小設定
m_iBlkHeadSize = (int) m_vcBlkHeadPtr.size ();
}
double CBlockOut::GetBlkValue (int iIndex) const
{
//取得指定channel的Block值
if (!m_vcBlkHeadPtr.empty () && iIndex < m_iBlkHeadSize)
return m_vcBlkHeadPtr[iIndex]->GetBlkValue ();
else
return NO_VALUE;
}
int CBlockOut::GetValueFlag (int iIndex) const
{
//取得指定channel的Value旗標
if (!m_vcBlkHeadPtr.empty () && iIndex < m_iBlkHeadSize)
return m_vcBlkHeadPtr[iIndex]->GetValueFlag ();
else
return NO_VALUE;
}
void CBlockOut::Move (CPoint ptCursor)
{
CBlockBasis::Move (ptCursor);
m_rcPinIn.left = m_rcBlk.CenterPoint ().x - PIN_RADIUS;
m_rcPinIn.top = m_rcBlk.top - PIN_RADIUS;
m_rcPinIn.right = m_rcBlk.CenterPoint ().x + PIN_RADIUS;
m_rcPinIn.bottom = m_rcBlk.top + PIN_RADIUS;
}
void CBlockOut::Draw (CDC* pDC)
{
CBrush brushPin (GOLD), * pbrushOld;
pbrushOld = pDC->SelectObject (&brushPin);
pDC->Ellipse (m_rcPinIn);
pDC->SelectObject (pbrushOld);
CBlockBasis::Draw (pDC);
pDC->DrawTextA (_T ("OUT"), -1, &m_rcBlk, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
void CBlockOut::DrawLine (CDC* pDC)
{
if (!m_vcBlkHeadPtr.empty ())
{
CPen penLine (PS_SOLID, 5, BLACK);
CPen* pOldPen;
pOldPen = pDC->SelectObject (&penLine);
for (int i = 0; i < m_iBlkHeadSize; i++)
{
CPoint ptStart = m_vcBlkHeadPtr[i]->GetPinOutRect ().CenterPoint (); //連線起點為輸入Block的輸出Pin腳中心點
CPoint ptEnd = m_rcPinIn.CenterPoint (); //連線終點為此Block的輸入Pin腳中心點
int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //垂直格點間隔
int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //計算連線轉折處距離輸入Block幾個隔點
int iCornerY = iCornerGridY * iGrid + ptStart.y; //連線轉折處Y座標位置
pDC->MoveTo (ptStart);
pDC->LineTo (CPoint (ptStart.x, iCornerY));
pDC->MoveTo (CPoint (ptStart.x, iCornerY));
pDC->LineTo (CPoint (ptEnd.x, iCornerY));
pDC->MoveTo (CPoint (ptEnd.x, iCornerY));
pDC->LineTo (ptEnd);
}
pDC->SelectObject (pOldPen);
}
}
int CBlockOut::BlkTypeIs () const
{
return BLK_OUT;
}

57
TestSimulator/BlockOut.h Normal file
View File

@ -0,0 +1,57 @@
#pragma once
//Block衍生類別Block Out
#include "BlockBasis.h"
#include <vector>
class CBlockOut : public CBlockBasis
{
private:
//Block rect(存在一個輸入Pin)
CRect m_rcPinIn;
//連接指標vector(存在多個輸入channel)
std::vector <CBlockBasis*> m_vcBlkHeadPtr;
//連接編號vector(存在多個輸入channel)
std::vector <int> m_vcBlkHeadNum;
//輸入channel數目
int m_iBlkHeadSize;
public:
//建構、解構子
CBlockOut ();
virtual ~CBlockOut ();
//取得、設定rect
virtual void SetBlkRect (CPoint, int, int);
virtual CRect GetPinIn1Rect () const;
//取得、設定連接至Block的指標
virtual CBlockBasis* GetBlkHead1Ptr (int) const;
virtual void SetBlkHead1Ptr (CBlockBasis*);
virtual void DeleteBlkHead1Ptr (int);
//取得、設定連接至Block的編號
virtual int GetBlkHead1Num (int) const;
virtual void SetBlkHead1Num (int) ;
virtual void ClearBlkHead1Num ();
//取得、設定輸入channel數目
virtual int GetBlkHeadSize () const;
virtual void SetBlkHeadSize (int);
virtual double GetBlkValue (int) const; //取得Block值
virtual int GetValueFlag (int) const; //取得Value旗標
virtual void Move (CPoint); //移動Block
virtual void Draw (CDC*); //繪製Block
virtual void DrawLine (CDC*); //繪製Block連接線
//判斷Block種類
virtual int BlkTypeIs () const;
};

51
TestSimulator/Complex.cpp Normal file
View File

@ -0,0 +1,51 @@
#include "stdafx.h"
#include "Complex.h"
#include "math.h"
CComplex::CComplex ()
{
m_dReal = 0.;
m_dImag = 0.;
}
CComplex::CComplex (double dReal, double dImag)
{
m_dReal = dReal;
m_dImag = dImag;
}
CComplex::~CComplex ()
{
}
CComplex CComplex::operator+ (const CComplex & complexNumber)
{
double dTempReal = m_dReal + complexNumber.m_dReal;
double dTempImag = m_dImag + complexNumber.m_dImag;
return CComplex (dTempReal, dTempImag);
}
CComplex CComplex::operator- (const CComplex & complexNumber)
{
double dTempReal = m_dReal - complexNumber.m_dReal;
double dTempImag = m_dImag - complexNumber.m_dImag;
return CComplex (dTempReal, dTempImag);
}
CComplex CComplex::operator* (const CComplex & complexNumber)
{
double dTempReal = m_dReal * complexNumber.m_dReal - m_dImag * complexNumber.m_dImag;
double dTempImag = m_dReal * complexNumber.m_dImag + m_dImag * complexNumber.m_dReal;
return CComplex (dTempReal, dTempImag);
}
double CComplex::ComputeAmplitude () const
{
return sqrt (m_dReal * m_dReal + m_dImag * m_dImag);
}

22
TestSimulator/Complex.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
class CComplex
{
public:
double m_dReal; //複數實部
double m_dImag; //複數虛部
public:
//建構、解構子
CComplex ();
CComplex (double, double);
~CComplex ();
//重載運算元
CComplex operator+ (const CComplex &);
CComplex operator- (const CComplex &);
CComplex operator* (const CComplex &);
//計算複數振幅大小
double ComputeAmplitude () const;
};

113
TestSimulator/FunDlg.cpp Normal file
View File

@ -0,0 +1,113 @@
// FunDlg.cpp : 實作檔
//
#include "stdafx.h"
#include "TestSimulator.h"
#include "FunDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define NO_OPER_FLAG -11 //不存在運算元
#define PLUS 1 // + flag
#define MINUS 2 // - flag
#define MULTI 3 // * flag
#define DIV 4 // / flag
CFunDlg::CFunDlg (CWnd* pParent)
: CDialogEx (CFunDlg::IDD, pParent)
{
m_hIcon = AfxGetApp ()->LoadIcon (IDR_MAINFRAME);
m_iOperFlag = NO_OPER_FLAG;
}
CFunDlg::~CFunDlg ()
{
}
BEGIN_MESSAGE_MAP (CFunDlg, CDialogEx)
ON_BN_CLICKED(IDC_BUTTON_PLUS, &CFunDlg::OnBnClickedButtonPlus)
ON_BN_CLICKED(IDC_BUTTON_MINUS, &CFunDlg::OnBnClickedButtonMinus)
ON_BN_CLICKED(IDC_BUTTON_MULTI, &CFunDlg::OnBnClickedButtonMulti)
ON_BN_CLICKED(IDC_BUTTON_DIV, &CFunDlg::OnBnClickedButtonDiv)
END_MESSAGE_MAP ()
void CFunDlg::DoDataExchange (CDataExchange* pDX)
{
CDialogEx::DoDataExchange (pDX);
}
BOOL CFunDlg::OnInitDialog ()
{
CDialogEx::OnInitDialog ();
( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetReadOnly ();
//視窗初始化時讀取運算元flag並將其顯示於Edit中
switch (m_iOperFlag)
{
case PLUS:
( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("+"));
break;
case MINUS:
( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("-"));
break;
case MULTI:
( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("*"));
break;
case DIV:
( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("/"));
break;
default:
( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("Please select operator"));
break;
}
return TRUE;
}
int CFunDlg::GetOperFlag () const
{
return m_iOperFlag;
}
void CFunDlg::SetOperFlag (int iOperFlag)
{
m_iOperFlag = iOperFlag;
}
void CFunDlg::OnBnClickedButtonPlus ()
{
m_iOperFlag = PLUS; //按下+鍵設定輸入波形flag為PLUS
( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("+"));
}
void CFunDlg::OnBnClickedButtonMinus ()
{
m_iOperFlag = MINUS; //按下-鍵設定輸入波形flag為MINUS
( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("-"));
}
void CFunDlg::OnBnClickedButtonMulti ()
{
m_iOperFlag = MULTI; //按下*鍵設定輸入波形flag為MULTI
( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("*"));
}
void CFunDlg::OnBnClickedButtonDiv ()
{
m_iOperFlag = DIV; //按下/鍵設定輸入波形flag為DIV
( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("/"));
}

41
TestSimulator/FunDlg.h Normal file
View File

@ -0,0 +1,41 @@
// FunDlg.h : 標頭檔
//
#pragma once
// InputDlg 對話方塊
class CFunDlg: public CDialogEx
{
// 建構
public:
CFunDlg (CWnd* pParent = NULL); // 標準建構函式
~CFunDlg ();
// 對話方塊資料
enum { IDD = IDD_DIALOG_FUN };
private:
int m_iOperFlag;
protected:
virtual void DoDataExchange (CDataExchange* pDX); // DDX/DDV 支援
// 程式碼實作
protected:
HICON m_hIcon;
// 產生的訊息對應函式
virtual BOOL OnInitDialog ();
DECLARE_MESSAGE_MAP ()
public:
//取得、設定運算元flag
int GetOperFlag () const;
void SetOperFlag (int);
afx_msg void OnBnClickedButtonPlus ();
afx_msg void OnBnClickedButtonMinus ();
afx_msg void OnBnClickedButtonMulti ();
afx_msg void OnBnClickedButtonDiv ();
};

View File

@ -0,0 +1,6 @@
[BgParameter]
BgPicBOOL=FALSE
BgPicPath=None
BgColor=65535
GridBOOL=TRUE
LockBOOL=TRUE

107
TestSimulator/InputDlg.cpp Normal file
View File

@ -0,0 +1,107 @@
// InputDlg.cpp : 實作檔
//
#include "stdafx.h"
#include "TestSimulator.h"
#include "InputDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define NO_INPUT_FLAG -12 //不存在輸入波形
#define ZERO 0 //FALSE flag
#define ONE 1 //TRUE flag
#define SIN 2 //Sin flag
#define COS 3 //Cos flag
CInputDlg::CInputDlg (CWnd* pParent)
: CDialogEx (CInputDlg::IDD, pParent)
{
m_hIcon = AfxGetApp ()->LoadIcon (IDR_MAINFRAME);
m_iInputFlag = NO_INPUT_FLAG; //初始化輸入波形flag
}
CInputDlg::~CInputDlg ()
{
}
BEGIN_MESSAGE_MAP (CInputDlg, CDialogEx)
ON_BN_CLICKED(IDC_BUTTON_TRUE, &CInputDlg::OnBnClickedButtonTrue)
ON_BN_CLICKED(IDC_BUTTON_FALSE, &CInputDlg::OnBnClickedButtonFalse)
ON_BN_CLICKED(IDC_BUTTON_SIN, &CInputDlg::OnBnClickedButtonSin)
ON_BN_CLICKED(IDC_BUTTON_COS, &CInputDlg::OnBnClickedButtonCos)
END_MESSAGE_MAP ()
void CInputDlg::DoDataExchange (CDataExchange* pDX)
{
CDialogEx::DoDataExchange (pDX);
}
BOOL CInputDlg::OnInitDialog ()
{
CDialogEx::OnInitDialog ();
( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetReadOnly ();
//視窗初始化時讀取輸入波形flag並將其顯示於Edit中
switch (m_iInputFlag)
{
case ZERO:
( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("False"));
break;
case ONE:
( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("True"));
break;
case SIN:
( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("Sin (t)"));
break;
case COS:
( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("Cos (t)"));
break;
default:
( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("Please select input"));
}
return TRUE;
}
int CInputDlg::GetInputFlag () const
{
return m_iInputFlag;
}
void CInputDlg::SetInputFlag (int iInputFlag)
{
m_iInputFlag = iInputFlag;
}
void CInputDlg::OnBnClickedButtonTrue ()
{
m_iInputFlag = ONE; //按下True鍵設定輸入波形flag為ONE
( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("True"));
}
void CInputDlg::OnBnClickedButtonFalse ()
{
m_iInputFlag = ZERO; //按下False鍵設定輸入波形flag為ZERO
( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("False"));
}
void CInputDlg::OnBnClickedButtonSin ()
{
m_iInputFlag = SIN; //按下Sin鍵設定輸入波形flag為SIN
( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("Sin (t)"));
}
void CInputDlg::OnBnClickedButtonCos ()
{
m_iInputFlag = COS; //按下Cos鍵設定輸入波形flag為COS
( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("Cos (t)"));
}

42
TestSimulator/InputDlg.h Normal file
View File

@ -0,0 +1,42 @@
// InputDlg.h : 標頭檔
//
#pragma once
// InputDlg 對話方塊
class CInputDlg : public CDialogEx
{
// 建構
public:
CInputDlg (CWnd* pParent = NULL); // 標準建構函式
virtual ~CInputDlg ();
// 對話方塊資料
enum { IDD = IDD_DIALOG_INPUT };
private:
int m_iInputFlag;
protected:
virtual void DoDataExchange (CDataExchange* pDX); // DDX/DDV 支援
// 程式碼實作
protected:
HICON m_hIcon;
// 產生的訊息對應函式
virtual BOOL OnInitDialog ();
DECLARE_MESSAGE_MAP ()
public:
//取得、設定輸入波形flag
int GetInputFlag () const;
void SetInputFlag (int);
afx_msg void OnBnClickedButtonTrue();
afx_msg void OnBnClickedButtonFalse();
afx_msg void OnBnClickedButtonSin();
afx_msg void OnBnClickedButtonCos();
};

434
TestSimulator/OscDlg.cpp Normal file
View File

@ -0,0 +1,434 @@
// OscDlg.cpp : 實作檔
//
#include "stdafx.h"
#include "TestSimulator.h"
#include "OscDlg.h"
#include "afxdialogex.h"
#include "TestSimulatorDlg.h"
#include <cstdlib>
#include <ctime>
//#include <iostream>
//using namespace std;
//工作區域參數
#define WORK_LEFT 0
#define WORK_TOP 0
#define WORK_RIGHT 500
#define WORK_BOTTOM 500
#define BLACK RGB (0, 0, 0) //背景顏色
#define BLUE RGB (0, 0, 255) //網格顏色
#define WHITE RGB (255, 255, 255) //y = 0中線顏色
#define YELLOW RGB (255, 255, 0) //距離中線一個單位的線條顏色
#define RED RGB (255, 0, 0) //距離中線兩個單位的線條顏色
#define GOLD RGB (255, 215, 0) //選取output波形顏色
#define GRID 10
#define UNITY 100
#define MAX_PLOT_NUM 501 //最大繪製data數
#define OFFSET_Y 250 //對話盒座標左上角為原點,為了使繪圖繪製於示波器中央,故繪圖時需增加一個偏移量使(0, 0)位於示波圖左中點
// COscDlg 對話方塊
COscDlg::COscDlg (CWnd* pParent /*=NULL*/)
: CDialogEx(COscDlg::IDD, pParent)
{
m_hIcon = AfxGetApp ()->LoadIcon (IDR_MAINFRAME);
m_pSimulatorDlg = (CTestSimulatorDlg*) pParent;
m_rcWork.SetRect (WORK_LEFT, WORK_TOP, WORK_RIGHT, WORK_BOTTOM);
m_dTime = 0.;
m_dSlctOutputValue = 0.;
m_dMaxDataValue = 0.;
m_dFreq = 0.;
m_iOutputSize = 0;
m_iSlctOutputNum = 0;
m_dYInterval = 0;
m_iXInterval = 0;
m_iYPos = 0;
m_iXPos = 0;
m_bSim = FALSE;
m_bModify = TRUE;
m_bFFT = TRUE;
}
COscDlg::~COscDlg ()
{
if (!m_deqPenPtr.empty ())
{
int iSize = (int) m_deqPenPtr.size ();
for (int i = 0; i < iSize; i++)
delete m_deqPenPtr[i];
}
}
void COscDlg::DoDataExchange (CDataExchange* pDX)
{
CDialogEx::DoDataExchange (pDX);
DDX_Text (pDX, IDC_EDIT_TIME, m_dTime);
DDX_Text (pDX, IDC_EDIT_VALUE, m_dSlctOutputValue);
DDX_Control (pDX, IDC_COMBO_OUTPUT, m_ctrlComboOutput);
DDX_Control (pDX, IDC_COMBO_VALUE_INTERVAL, m_ctrlComboYInterval);
DDX_Control (pDX, IDC_COMBO_TIME_INTERVAL, m_ctrlComboXInterval);
DDX_Text (pDX, IDC_EDIT_FREQUENCY, m_dFreq);
}
BEGIN_MESSAGE_MAP (COscDlg, CDialogEx)
ON_WM_CLOSE()
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTTON_START, &COscDlg::OnBnClickedButtonStart)
ON_BN_CLICKED(IDC_BUTTON_STOP, &COscDlg::OnBnClickedButtonStop)
ON_CBN_SELCHANGE(IDC_COMBO_OUTPUT, &COscDlg::OnCbnSelchangeComboOutput)
ON_CBN_SELCHANGE(IDC_COMBO_VALUE_INTERVAL, &COscDlg::OnCbnSelchangeComboValueInterval)
ON_CBN_SELCHANGE(IDC_COMBO_TIME_INTERVAL, &COscDlg::OnCbnSelchangeComboTimeInterval)
END_MESSAGE_MAP ()
// COscDlg 訊息處理常式
BOOL COscDlg::OnInitDialog ()
{
CDialogEx::OnInitDialog();
//設定亂數種子
srand ((unsigned int) time (NULL));
//設定Y軸間隔Combo box內容
for (int i = 0; i < 4; i++)
{
CString strYInterval;
double dInterval = 0.5;
for (int j = 0 ; j < i; j++)
dInterval *= 2;
strYInterval.Format (_T ("%g"), dInterval);
m_ctrlComboYInterval.AddString (strYInterval);
}
//初始化Y軸間隔
m_ctrlComboYInterval.SetCurSel (0);
m_dYInterval = 0.5;
m_iYPos = 0;
m_dMaxDataValue = m_dYInterval * 2.5;
//設定X軸間隔Combo box內容
m_ctrlComboXInterval.AddString (_T ("5"));
m_ctrlComboXInterval.AddString (_T ("10"));
m_ctrlComboXInterval.AddString (_T ("50"));
m_ctrlComboXInterval.AddString (_T ("100"));
m_ctrlComboXInterval.AddString (_T ("500"));
//初始化X軸間隔
m_ctrlComboXInterval.SetCurSel (0);
m_iXInterval = 5;
m_iXPos = 0;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX 屬性頁應傳回 FALSE
}
void COscDlg::OnPaint ()
{
//雙緩衝建立
CPaintDC dcOsc (this); //示波器對話盒dc
CDC dcMem; //內存dc
CBitmap bitmapMem;
CBitmap* pOldBitmap;
dcMem.CreateCompatibleDC (&dcOsc); //建立與示波器對話盒相容的dc
bitmapMem.CreateCompatibleBitmap (&dcOsc, WORK_RIGHT, WORK_BOTTOM);
pOldBitmap = dcMem.SelectObject (&bitmapMem);
//繪製背景
dcMem.SetBkMode (TRANSPARENT);
dcMem.FillSolidRect (m_rcWork, BLACK);
//藍色網格,每格邊長為 10 pixels
CPen penBlue (PS_SOLID, 1, BLUE);
CPen* pOldPen = dcMem.SelectObject (&penBlue);
for (int i = 0; i < m_rcWork.Width (); i += GRID)
{
dcMem.MoveTo (i, 0); //垂直線
dcMem.LineTo (i, m_rcWork.Height ());
dcMem.MoveTo (0, i); //水平線
dcMem.LineTo (m_rcWork.Width (), i);
}
//繪製示波器中線(X軸)
CPen penWhite (PS_SOLID, 2, WHITE);
CString strValueZero ("Value = 0");
dcMem.SelectObject (&penWhite);
SetTextColor (dcMem, WHITE);
dcMem.MoveTo (0, m_rcWork.Height () / 2);
dcMem.LineTo (m_rcWork.Width (), m_rcWork.Height () / 2); //畫線
dcMem.TextOutA (0, m_rcWork.Height () / 2, strValueZero, strValueZero.GetLength ()); //標記文字
//距離中線一個UNITY (一個UNITY為 100 piexls)
CPen penYellow (PS_SOLID, 1, YELLOW);
CString strValueNOne;
strValueNOne.Format (_T ("Value = %g"), -m_dYInterval);
CString strValuePOne;
strValuePOne.Format (_T ("Value = %g"), m_dYInterval);
dcMem.SelectObject (&penYellow);
SetTextColor (dcMem, YELLOW);
dcMem.MoveTo (0, m_rcWork.Height () / 2 + UNITY);
dcMem.LineTo (m_rcWork.Width (), m_rcWork.Height () / 2 + UNITY);
dcMem.TextOutA (0, m_rcWork.Height () / 2 + UNITY, strValueNOne, strValueNOne.GetLength ());
dcMem.MoveTo (0, m_rcWork.Height () / 2 - UNITY);
dcMem.LineTo (m_rcWork.Width (), m_rcWork.Height () / 2 - UNITY);
dcMem.TextOutA (0, m_rcWork.Height () / 2 - UNITY, strValuePOne, strValuePOne.GetLength ());
//距離中線兩個UNITY (一個UNITY為 100 piexls)
CPen penRed (PS_SOLID, 2, RED);
CString strValueNTwo;
strValueNTwo.Format (_T ("Value = %g"), -2 * m_dYInterval);
CString strValuePTwo;
strValuePTwo.Format (_T ("Value = %g"), 2 * m_dYInterval);
dcMem.SelectObject (&penRed);
SetTextColor (dcMem, RED);
dcMem.MoveTo (0, m_rcWork.Height () / 2 + (2 * UNITY));
dcMem.LineTo (m_rcWork.Width (), m_rcWork.Height () / 2 + (2 * UNITY));
dcMem.TextOutA (0, m_rcWork.Height () / 2 + (2 * UNITY), strValueNTwo, strValueNTwo.GetLength ());
dcMem.MoveTo (0, m_rcWork.Height () / 2 - (2 * UNITY));
dcMem.LineTo (m_rcWork.Width (), m_rcWork.Height () / 2 - (2 * UNITY));
dcMem.TextOutA (0, m_rcWork.Height () / 2 - (2 * UNITY), strValuePTwo, strValuePTwo.GetLength ());
//模擬開始
if (m_bSim)
{
CPen penGold (PS_SOLID, 6, GOLD);
int iDataSize = (int) m_pSimulatorDlg->m_deq2DOutputValue.size (); //取得data數目
//當data數大於1開始繪製output波形
if (iDataSize > 1)
{
int iPlotStart = 0; //繪製data起點
if (iDataSize > MAX_PLOT_NUM)
iPlotStart = iDataSize - MAX_PLOT_NUM;
for (int i = 0; i < m_iOutputSize; i++)
{
//設定選取output的畫筆為金色較粗的畫筆
if (m_iSlctOutputNum >= 0 && i == m_iSlctOutputNum)
dcMem.SelectObject (&penGold);
else
dcMem.SelectObject (m_deqPenPtr[i]);
for (int j = 1; j < iDataSize; j++)
{
//超出可繪製data數則立即跳出迴圈
if (j >= MAX_PLOT_NUM)
break;
double dForwardValue = m_pSimulatorDlg->m_deq2DOutputValue[j - 1 + iPlotStart][i];
double dPostValue = m_pSimulatorDlg->m_deq2DOutputValue[j + iPlotStart][i];
//判斷data值是否超出示波器可顯示之最大值
if (dForwardValue > m_dMaxDataValue)
dForwardValue = m_dMaxDataValue;
else if (dForwardValue < -m_dMaxDataValue)
dForwardValue = -m_dMaxDataValue;
if (dPostValue > m_dMaxDataValue)
dPostValue = m_dMaxDataValue;
else if (dPostValue < -m_dMaxDataValue)
dPostValue = -m_dMaxDataValue;
dcMem.MoveTo (j - 1, -(int) (dForwardValue / m_dYInterval * UNITY) + OFFSET_Y);
dcMem.LineTo (j, -(int) (dPostValue / m_dYInterval * UNITY) + OFFSET_Y);
}
}
}
}
//由內存dc拷貝至示波器對話盒dc
dcOsc.BitBlt (WORK_LEFT, WORK_TOP, m_rcWork.Width (), m_rcWork.Height (), &dcMem, WORK_LEFT, WORK_TOP, SRCCOPY);
//清理
dcMem.SelectObject (pOldPen);
dcMem.SelectObject (pOldBitmap);
bitmapMem.DeleteObject ();
dcMem.DeleteDC ();
}
//由主對話盒傳值(當前時間, 選取output value, 頻率)
void COscDlg::SetData (double dTime, double dValue, double dFreq)
{
m_dTime = dTime;
m_dSlctOutputValue = dValue;
m_dFreq = dFreq;
}
// 由主對話盒傳值(當前時間, 選取output value)
void COscDlg::SetData (double dTime, double dValue)
{
m_dTime = dTime;
m_dSlctOutputValue = dValue;
}
//按下Start鍵
void COscDlg::OnBnClickedButtonStart ()
{
if (!m_bSim)
{
m_bModify = FALSE; //開始模擬不可更改X軸間隔Combo box
m_bSim = TRUE;
m_pSimulatorDlg->SetTimer (0, 10, NULL);
}
}
//按下Stop鍵
void COscDlg::OnBnClickedButtonStop ()
{
if (m_bSim)
{
m_bSim = FALSE;
m_pSimulatorDlg->KillTimer (0);
}
}
//改變output combo box
void COscDlg::OnCbnSelchangeComboOutput ()
{
m_iSlctOutputNum = m_ctrlComboOutput.GetCurSel ();
m_bFFT = TRUE;
}
//改變Y軸間隔 combo box
void COscDlg::OnCbnSelchangeComboValueInterval ()
{
m_iYPos = m_ctrlComboYInterval.GetCurSel ();
double dIni = 0.5;
for (int i = 0; i < m_iYPos; i++)
dIni *= 2;
m_dYInterval = dIni;
m_dMaxDataValue = 2.5 * m_dYInterval;
InvalidateRect (m_rcWork, FALSE);
UpdateWindow ();
}
//改變X軸間隔 combo box
void COscDlg::OnCbnSelchangeComboTimeInterval ()
{
if (m_bModify && (!m_bSim))
{
m_iXPos = m_ctrlComboXInterval.GetCurSel ();
switch (m_iXPos)
{
case 0:
m_iXInterval = 5;
break;
case 1:
m_iXInterval = 10;
break;
case 2:
m_iXInterval = 50;
break;
case 3:
m_iXInterval = 100;
break;
case 4:
m_iXInterval = 500;
break;
default:
break;
}
}
else
m_ctrlComboXInterval.SetCurSel (m_iXPos);
}
BOOL COscDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN)
return TRUE;
}
return CDialogEx::PreTranslateMessage(pMsg);
}
//關閉視窗
void COscDlg::OnClose ()
{
//清除隨機畫筆deque
if (!m_deqPenPtr.empty ())
{
for (int i = 0; i < m_iOutputSize; i++)
delete m_deqPenPtr[i];
}
m_pSimulatorDlg->m_bSimulate = FALSE; //停止模擬
m_deqPenPtr.clear ();
m_ctrlComboOutput.ResetContent (); //清空output combo box內容
m_bSim = FALSE; //停止模擬
m_bModify = TRUE; //停止模擬後可更改combo box
m_bFFT = TRUE;
m_iSlctOutputNum = 0;
m_dTime = 0.;
m_dSlctOutputValue = 0.;
m_dFreq = 0.;
m_pSimulatorDlg->m_iStep = 0;
m_pSimulatorDlg->KillTimer (0);
CDialogEx::OnClose ();
}
//設定channel數目
void COscDlg::SetOutputSize (int iOutSize)
{
m_iOutputSize = iOutSize;
}
//初始化示波器對話盒資料(channel數目, 隨機畫筆)
void COscDlg::InitialData ()
{
//設定output combo box內容
for (int i = 0; i < m_iOutputSize; i++)
{
CString strOutput;
strOutput.Format (_T ("Output %d"), i + 1);
m_ctrlComboOutput.AddString (strOutput);
}
//建立隨機畫筆
for (int i = 0; i < m_iOutputSize; i++)
{
CPen* pRandPen = new CPen (PS_SOLID, 3, RGB (rand () % 256, rand () % 256, rand () % 256));
m_deqPenPtr.push_back (pRandPen);
}
m_ctrlComboOutput.SetCurSel (0);
}
//取得時間間隔
int COscDlg::GetTimeInterval () const
{
return m_iXInterval;
}

72
TestSimulator/OscDlg.h Normal file
View File

@ -0,0 +1,72 @@
// OscDlg.h : 標頭檔
//
#pragma once
#include "afxwin.h"
#include <deque>
class CTestSimulatorDlg;
// COscDlg 對話方塊
class COscDlg : public CDialogEx
{
public:
COscDlg (CWnd* pParent = NULL); // 標準建構函式
virtual ~COscDlg ();
// 對話方塊資料
enum { IDD = IDD_DIALOG_OSC };
private:
CTestSimulatorDlg* m_pSimulatorDlg; //主對話盒指標
CComboBox m_ctrlComboOutput; //Output combo box變數
CComboBox m_ctrlComboYInterval; //Y軸間隔 combo box變數
CComboBox m_ctrlComboXInterval; //X軸間隔 combo box變數
std::deque <CPen*> m_deqPenPtr; //隨機畫筆deque
double m_dTime; //模擬時間
double m_dSlctOutputValue; //選取output value
double m_dMaxDataValue; //示波器顯示最大值
double m_dFreq; //頻率
int m_iOutputSize; //channel數目
double m_dYInterval; //Y軸間隔
int m_iXInterval; //X軸間隔
int m_iYPos; //Y軸間隔 combo box位置
int m_iXPos; //X軸間隔 combo box位置
protected:
HICON m_hIcon;
virtual void DoDataExchange (CDataExchange* pDX); // DDX/DDV 支援
DECLARE_MESSAGE_MAP ()
public:
CRect m_rcWork; //示波器對話盒工作區
int m_iSlctOutputNum; //選取output編號
BOOL m_bSim; //判斷模擬
BOOL m_bModify; //判斷combo box更改
BOOL m_bFFT; //判斷進行FFT
virtual BOOL OnInitDialog ();
afx_msg void OnPaint ();
afx_msg void OnBnClickedButtonStart ();
afx_msg void OnBnClickedButtonStop ();
afx_msg void OnCbnSelchangeComboOutput ();
afx_msg void OnCbnSelchangeComboValueInterval ();
afx_msg void OnCbnSelchangeComboTimeInterval ();
virtual BOOL PreTranslateMessage (MSG* pMsg);
afx_msg void OnClose ();
void SetData (double, double, double);
void SetData (double, double);
void SetOutputSize (int);
void InitialData ();
int GetTimeInterval () const;
};

View File

@ -0,0 +1,102 @@
// TestSimulator.cpp : 定義應用程式的類別行為。
//
#include "stdafx.h"
#include "TestSimulator.h"
#include "TestSimulatorDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CTestSimulatorApp
BEGIN_MESSAGE_MAP(CTestSimulatorApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CTestSimulatorApp 建構
CTestSimulatorApp::CTestSimulatorApp()
{
// 支援重新啟動管理員
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
// TODO: 在此加入建構程式碼,
// 將所有重要的初始設定加入 InitInstance 中
}
// 僅有的一個 CTestSimulatorApp 物件
CTestSimulatorApp theApp;
// CTestSimulatorApp 初始設定
BOOL CTestSimulatorApp::InitInstance()
{
// 假如應用程式資訊清單指定使用 ComCtl32.dll 6 (含) 以後版本,
// 來啟動視覺化樣式,在 Windows XP 上,則需要 InitCommonControls()。
// 否則任何視窗的建立都將失敗。
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// 設定要包含所有您想要用於應用程式中的
// 通用控制項類別。
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
// 建立殼層管理員,以防對話方塊包含
// 任何殼層樹狀檢視或殼層清單檢視控制項。
CShellManager *pShellManager = new CShellManager;
// 啟動 [Windows 原生] 視覺化管理員可啟用 MFC 控制項中的主題
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
// 標準初始設定
// 如果您不使用這些功能並且想減少
// 最後完成的可執行檔大小,您可以
// 從下列程式碼移除不需要的初始化常式,
// 變更儲存設定值的登錄機碼
// TODO: 您應該適度修改此字串
// (例如,公司名稱或組織名稱)
SetRegistryKey(_T("本機 AppWizard 所產生的應用程式"));
CTestSimulatorDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: 在此放置於使用 [確定] 來停止使用對話方塊時
// 處理的程式碼
}
else if (nResponse == IDCANCEL)
{
// TODO: 在此放置於使用 [取消] 來停止使用對話方塊時
// 處理的程式碼
}
else if (nResponse == -1)
{
TRACE(traceAppMsg, 0, "警告: 對話方塊建立失敗,因此,應用程式意外終止。\n");
TRACE(traceAppMsg, 0, "警告: 如果您要在對話方塊上使用 MFC 控制項,則無法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
}
// 刪除上面所建立的殼層管理員。
if (pShellManager != NULL)
{
delete pShellManager;
}
// 因為已經關閉對話方塊,傳回 FALSE所以我們會結束應用程式
// 而非提示開始應用程式的訊息。
return FALSE;
}

View File

@ -0,0 +1,32 @@
// TestSimulator.h : PROJECT_NAME 應用程式的主要標頭檔
//
#pragma once
#ifndef __AFXWIN_H__
#error "對 PCH 包含此檔案前先包含 'stdafx.h'"
#endif
#include "resource.h" // 主要符號
// CTestSimulatorApp:
// 請參閱實作此類別的 TestSimulator.cpp
//
class CTestSimulatorApp : public CWinApp
{
public:
CTestSimulatorApp();
// 覆寫
public:
virtual BOOL InitInstance();
// 程式碼實作
DECLARE_MESSAGE_MAP()
};
extern CTestSimulatorApp theApp;

Binary file not shown.

View File

@ -0,0 +1,163 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C1F3E95D-9580-4550-A748-674E1D31DF84}</ProjectGuid>
<RootNamespace>TestSimulator</RootNamespace>
<Keyword>MFCProj</Keyword>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0404</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0404</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="BlockAnd.h" />
<ClInclude Include="BlockBasis.h" />
<ClInclude Include="BlockFun.h" />
<ClInclude Include="BlockIn.h" />
<ClInclude Include="BlockNot.h" />
<ClInclude Include="BlockOr.h" />
<ClInclude Include="BlockOut.h" />
<ClInclude Include="Complex.h" />
<ClInclude Include="FunDlg.h" />
<ClInclude Include="InputDlg.h" />
<ClInclude Include="OscDlg.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="TestSimulator.h" />
<ClInclude Include="TestSimulatorDlg.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="BlockAnd.cpp" />
<ClCompile Include="BlockBasis.cpp" />
<ClCompile Include="BlockFun.cpp" />
<ClCompile Include="BlockIn.cpp" />
<ClCompile Include="BlockNot.cpp" />
<ClCompile Include="BlockOr.cpp" />
<ClCompile Include="BlockOut.cpp" />
<ClCompile Include="Complex.cpp" />
<ClCompile Include="FunDlg.cpp" />
<ClCompile Include="InputDlg.cpp" />
<ClCompile Include="OscDlg.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TestSimulator.cpp" />
<ClCompile Include="TestSimulatorDlg.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="TestSimulator.rc" />
</ItemGroup>
<ItemGroup>
<None Include="res\TestSimulator.rc2" />
</ItemGroup>
<ItemGroup>
<Image Include="res\TestSimulator.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties RESOURCE_FILE="TestSimulator.rc" />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="原始程式檔">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="標頭檔">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="資源檔">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="TestSimulator.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="TestSimulatorDlg.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="BlockBasis.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="BlockIn.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="BlockOut.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="BlockAnd.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="BlockOr.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="BlockNot.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="InputDlg.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="BlockFun.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="FunDlg.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="OscDlg.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="Complex.h">
<Filter>標頭檔</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="TestSimulator.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="TestSimulatorDlg.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="BlockBasis.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="BlockIn.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="BlockOut.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="BlockAnd.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="BlockNot.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="InputDlg.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="BlockFun.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="FunDlg.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="OscDlg.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="BlockOr.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
<ClCompile Include="Complex.cpp">
<Filter>原始程式檔</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="TestSimulator.rc">
<Filter>資源檔</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="res\TestSimulator.rc2">
<Filter>資源檔</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Image Include="res\TestSimulator.ico">
<Filter>資源檔</Filter>
</Image>
</ItemGroup>
</Project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommand>$(TargetPath)</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,116 @@
// TestSimulatorDlg.h : 標頭檔
//
#pragma once
#include "BlockBasis.h"
#include "BlockIn.h"
#include "BlockOut.h"
#include "BlockAnd.h"
#include "BlockOr.h"
#include "BlockNot.h"
#include "BlockFun.h"
#include "InputDlg.h"
#include "FunDlg.h"
#include "OscDlg.h"
#include "Complex.h"
#include <vector>
#include <deque>
// CTestSimulatorDlg 對話方塊
class CTestSimulatorDlg : public CDialogEx
{
// 建構
public:
CTestSimulatorDlg(CWnd* pParent = NULL); // 標準建構函式
// 對話方塊資料
enum { IDD = IDD_TESTSIMULATOR_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支援
private:
std::vector <CBlockBasis*> m_vcBlkContainer; //存放不同Block的vector
CRect m_rcWork; //工作區
CRect m_rcClient; //對話盒客戶區
CPoint m_ptLEnd; //連線中線段終點
COscDlg* m_pOscDlg; //示波器對話盒指標
CDC m_dcBgPic; //存放背景圖片的dc
CBitmap m_bitmapBgPic; //存放背景圖片的bitmap
CBitmap* m_pOldBitmap; //指向原bitmap的指標
CString m_strPicPath; //背景圖片路徑
COLORREF m_clrBg; //背景顏色
BOOL m_bInitDlg; //判斷對話窗初始化
BOOL m_bSelectBlk; //判斷Block選取
BOOL m_bMoveBlk; //判斷Block移動
BOOL m_bLineMode; //判斷畫線模式
BOOL m_bConnect; //判斷連線
BOOL m_bDelBlk; //判斷Block刪除
BOOL m_bBgPic; //判斷載入背景圖片
BOOL m_bGrid; //判斷格點顯示
BOOL m_bLock; //判斷鎖定格點
int m_iWorkLeft; //工作區左側座標
int m_iWorkTop; //工作區上方座標
int m_iWorkRight; //工作區右側座標
int m_iWorkBottom; //工作區下方座標
int m_iBlkWidth; //Block寬度
int m_iBlkHeight; //Block高度
int m_iGridX; //X方向格點間隔
int m_iGridY; //Y方向格點間隔
int m_iContainerSize; //存放Block的vector大小
int m_iSlctBlkNum; //選取Block編號
int m_iHeadBlkNum; //連接Block編號
int m_iSimBlkNum; //模擬Block編號
int m_iOutSize; //模擬Block其channel數目
// 程式碼實作
protected:
HICON m_hIcon;
// 產生的訊息對應函式
virtual BOOL OnInitDialog ();
afx_msg void OnSysCommand (UINT nID, LPARAM lParam);
afx_msg void OnPaint ();
afx_msg HCURSOR OnQueryDragIcon ();
DECLARE_MESSAGE_MAP ()
public:
std::deque <std::deque <double> > m_deq2DOutputValue; //存放output value的deque
BOOL m_bSimulate; //判斷模擬模式
int m_iStep; //模擬進行步數
afx_msg void OnBnClickedButtonIn ();
afx_msg void OnBnClickedButtonOut ();
afx_msg void OnBnClickedButtonAnd ();
afx_msg void OnBnClickedButtonOr ();
afx_msg void OnBnClickedButtonNot ();
afx_msg void OnBnClickedButtonFunction ();
afx_msg void OnBnClickedButtonLine ();
afx_msg void OnBnClickedButtonSimulate ();
afx_msg void OnBnClickedButtonGrid ();
afx_msg void OnBnClickedButtonLock ();
afx_msg void OnBnClickedButtonBgpic ();
afx_msg void OnBnClickedButtonBgcolor ();
afx_msg void OnBnClickedButtonOpen ();
afx_msg void OnBnClickedButtonSave ();
afx_msg void OnLButtonDown (UINT nFlags, CPoint ptCursor);
afx_msg void OnMouseMove (UINT nFlags, CPoint ptCursor);
afx_msg void OnLButtonUp (UINT nFlags, CPoint ptCursor);
afx_msg void OnLButtonDblClk (UINT nFlags, CPoint point);
afx_msg void OnTimer (UINT_PTR nIDEvent);
afx_msg void OnSize (UINT nType, int cx, int cy);
virtual BOOL PreTranslateMessage (MSG* pMsg);
afx_msg void OnDestroy ();
void SplitString (CString, char, CStringArray&);
void Resize (int nID, double dMulWid, double dMulHei);
void Resize (CBlockBasis* pBlk, double dMulWid, double dMulHei);
int GetComputationLayers (int iDataSize);
double FFT (const std::deque <double> &, int, double);
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

BIN
TestSimulator/resource.h Normal file

Binary file not shown.

8
TestSimulator/stdafx.cpp Normal file
View File

@ -0,0 +1,8 @@
// stdafx.cpp : 僅包含標準 Include 檔的原始程式檔
// TestSimulator.pch 會成為先行編譯標頭檔
// stdafx.obj 會包含先行編譯型別資訊
#include "stdafx.h"

54
TestSimulator/stdafx.h Normal file
View File

@ -0,0 +1,54 @@
// stdafx.h : 可在此標頭檔中包含標準的系統 Include 檔,
// 或是經常使用卻很少變更的
// 專案專用 Include 檔案
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // 從 Windows 標頭排除不常使用的成員
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 明確定義部分的 CString 建構函式
// 關閉 MFC 隱藏一些常見或可忽略警告訊息的功能
#define _AFX_ALL_WARNINGS
#include <afxwin.h> // MFC 核心與標準元件
#include <afxext.h> // MFC 擴充功能
#include <afxdisp.h> // MFC Automation 類別
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC 支援的 Internet Explorer 4 通用控制項
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC 支援的 Windows 通用控制項
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxcontrolbars.h> // 功能區和控制列的 MFC 支援
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif

View File

@ -0,0 +1,8 @@
#pragma once
// 加上 SDKDDKVer.h 可定義最高可用的 Windows 平台。
// 如果要針對先前的 Windows 平台建置應用程式,請加上 WinSDKVer.h
// 並在加上 SDKDDKVer.h 之前將 _WIN32_WINNT 巨集設為要支援的平台。
#include <SDKDDKVer.h>