commit 9ab6ee652a4f94ed786f405d3fb158f8efafdadf Author: ChenSiAn Date: Fri Feb 3 10:07:52 2023 +0800 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df09299 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +#Build results +[Dd]ebug/ +[Rr]elease/ + +#Ext +*.bmp +*.txt +*.sdf +*.suo +*.db +*.opensdf + diff --git a/TestSimulator.sln b/TestSimulator.sln new file mode 100644 index 0000000..9ef1d9e --- /dev/null +++ b/TestSimulator.sln @@ -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 diff --git a/TestSimulator/BlockAnd.cpp b/TestSimulator/BlockAnd.cpp new file mode 100644 index 0000000..dad179c --- /dev/null +++ b/TestSimulator/BlockAnd.cpp @@ -0,0 +1,226 @@ +#include "stdafx.h" + +#include "BlockAnd.h" + +#include "math.h" + +#define PIN_RADIUS 8 //Pinb| + +#define GOLD RGB (255, 215, 0) //Pin}C +#define BLACK RGB (0, 0, 0) //suC + +#define NO_VALUE -10 //sbJT +#define NO_OPER_FLAG -11 //sbB⤸ +#define COMPUTE_ERROR -13 //\B +#define NO_BLOCK_HEAD -14 //sbsBlock + +#define TOLERANCE 0.001 //eԻ~t + +#define DIGITAL_VALUE 4 //ƦTflag +#define ANALOG_VALUE 5 //Tflag + +#define BLK_AND 3 //Blocks + +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޿ (YJҬ1Ah^1A_h^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) //Ysb@JIsA^"L" + return NO_VALUE; + else if (m_pBlkHead1->GetValueFlag () == NO_VALUE || m_pBlkHead2->GetValueFlag () == NO_VALUE) //Ysb@JLȡA^"L" + return NO_VALUE; + else if (m_pBlkHead1->GetValueFlag () == COMPUTE_ERROR || m_pBlkHead2->GetValueFlag () == COMPUTE_ERROR) //Ysb@Jp~A^"p~" + return COMPUTE_ERROR; + else if (m_pBlkHead1->GetValueFlag () == ANALOG_VALUE || m_pBlkHead2->GetValueFlag () == ANALOG_VALUE) //\J + return COMPUTE_ERROR; + else if (m_pBlkHead1->GetValueFlag () == NO_OPER_FLAG || m_pBlkHead2->GetValueFlag () == NO_OPER_FLAG) //]wB⤸ + return NO_OPER_FLAG; + else if (m_pBlkHead1->GetValueFlag () == DIGITAL_VALUE && m_pBlkHead2->GetValueFlag () == DIGITAL_VALUE) //YJҬƦTAh^ǼƦT + 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 (); //su_IJBlockXPin}I + CPoint ptEnd = m_rcPinIn1.CenterPoint (); //suIBlockJPin}I + int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //Ij + int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //psuBZJBlockXӹjI + int iCornerY = iCornerGridY * iGrid + ptStart.y; //suBYyЦm + 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 (); //su_IJBlockXPin}I + CPoint ptEnd = m_rcPinIn2.CenterPoint (); //suIBlockJPin}I + int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //Ij + int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //psuBZJBlockXӹjI + int iCornerY = iCornerGridY * iGrid + ptStart.y; //suBYyЦm + 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; +} \ No newline at end of file diff --git a/TestSimulator/BlockAnd.h b/TestSimulator/BlockAnd.h new file mode 100644 index 0000000..6eae7b8 --- /dev/null +++ b/TestSimulator/BlockAnd.h @@ -0,0 +1,55 @@ +#pragma once + +//BlocklOGBlock And + +#include "BlockBasis.h" + +class CBlockAnd : public CBlockBasis +{ +private: + //Block rect(sbӿJPinA@ӿXPin) + CRect m_rcPinIn1; + CRect m_rcPinIn2; + CRect m_rcPinOut; + + //s(sbӳs) + CBlockBasis* m_pBlkHead1; + CBlockBasis* m_pBlkHead2; + + //sBlocks(sbӽs) + int m_iBlkHead1Num; + int m_iBlkHead2Num; + +public: + //غcBѺcl + CBlockAnd (); + virtual ~CBlockAnd (); + + //oB]wrect + virtual void SetBlkRect (CPoint, int, int); + virtual CRect GetPinIn1Rect () const; + virtual CRect GetPinIn2Rect () const; + virtual CRect GetPinOutRect () const; + + //oB]wsBlock + virtual CBlockBasis* GetBlkHead1Ptr () const; + virtual CBlockBasis* GetBlkHead2Ptr () const; + virtual void SetBlkHead1Ptr (CBlockBasis*); + virtual void SetBlkHead2Ptr (CBlockBasis*); + + //oB]wsBlocks + virtual int GetBlkHead1Num () const; + virtual int GetBlkHead2Num () const; + virtual void SetBlkHead1Num (int) ; + virtual void SetBlkHead2Num (int) ; + + virtual double GetBlkValue () const; //oBlock + virtual int GetValueFlag () const; //oValueX + + virtual void Move (CPoint); //Block + virtual void Draw (CDC*); //øsBlock + virtual void DrawLine (CDC*); //øsBlocksu + + //P_Block + virtual int BlkTypeIs () const; +}; \ No newline at end of file diff --git a/TestSimulator/BlockBasis.cpp b/TestSimulator/BlockBasis.cpp new file mode 100644 index 0000000..8fe17c1 --- /dev/null +++ b/TestSimulator/BlockBasis.cpp @@ -0,0 +1,191 @@ +#include "stdafx.h" + +#include "BlockBasis.h" + + +#define LIGHTGRAY RGB (211, 211, 211) //BlockC + +#define NO_VALUE -10 //sbJT +#define NO_OPER_FLAG -11 //Block FunsbB⤸ +#define NO_INPUT_FLAG -12 //Block InsbJi +#define NO_BLOCK_HEAD -14 //sbsBlock + +#define NO_BLK_TYPE 0 + +CBlockBasis::CBlockBasis () +{ + m_rcBlk = CRect (); + m_iBlkNum = 0; +} + +CBlockBasis::~CBlockBasis () +{ +} + +CRect CBlockBasis::GetBlkRect () const +{ + return m_rcBlk; +} + +//HIBBlockeסBBlock׳]wBlock 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ɨ̹Цm]wBlock 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; +} \ No newline at end of file diff --git a/TestSimulator/BlockBasis.h b/TestSimulator/BlockBasis.h new file mode 100644 index 0000000..d70a6f8 --- /dev/null +++ b/TestSimulator/BlockBasis.h @@ -0,0 +1,68 @@ +#pragma once + +//Block¦O + +class CBlockBasis +{ +protected: + CRect m_rcBlk; //Block rect + + int m_iBlkNum; //Blockvectors + +public: + //غcBѺcl + CBlockBasis (); + virtual ~CBlockBasis (); + + //oB]wrect + CRect GetBlkRect () const; + virtual void SetBlkRect (CPoint, int, int); + virtual CRect GetPinIn1Rect () const; + virtual CRect GetPinIn2Rect () const; + virtual CRect GetPinOutRect () const; + + //oB]wBlocks + int GetBlkNum () const; + void SetBlkNum (int); + + //oB]wsBlock + 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 OutsvectorMw + + //oB]wsBlocks + virtual int GetBlkHead1Num () const; + virtual int GetBlkHead1Num (int) const; + virtual int GetBlkHead2Num () const; + virtual void SetBlkHead1Num (int) ; + virtual void SetBlkHead2Num (int) ; + virtual void ClearBlkHead1Num (); //MBlock Outssvector + + //oB]wsBlock Outƥ + virtual int GetBlkHeadSize () const; + virtual void SetBlkHeadSize (int); + + //oB]wBlock In, Funflag + virtual int GetInputFlag () const; + virtual void SetInputFlag (int); + virtual int GetOperFlag () const; + virtual void SetOperFlag (int); + + //oB]wBlock + virtual double GetBlkValue () const; + virtual double GetBlkValue (int) const; //oBlock Outwchannel + 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*); //øsBlock + virtual void DrawLine (CDC*); //øsBlocksu + + //P_Block + virtual int BlkTypeIs () const; +}; \ No newline at end of file diff --git a/TestSimulator/BlockFun.cpp b/TestSimulator/BlockFun.cpp new file mode 100644 index 0000000..69772a3 --- /dev/null +++ b/TestSimulator/BlockFun.cpp @@ -0,0 +1,257 @@ +#include "stdafx.h" + +#include "BlockFun.h" + +#define PIN_RADIUS 8 //Pinb| + +#define GOLD RGB (255, 215, 0) //Pin}C +#define BLACK RGB (0, 0, 0) //suC + +#define FALSE_VALUE 10 //FALSE^ǭ +#define TRUE_VALUE 11 //TRUE^ǭ +#define NO_VALUE -10 //sbJT +#define NO_OPER_FLAG -11 //sbB⤸ +#define NO_INPUT_FLAG -12 //sbJi +#define COMPUTE_ERROR -13 //\B +#define NO_BLOCK_HEAD -14 //sbsBlock + +#define PLUS 1 // + flag +#define MINUS 2 // - flag +#define MULTI 3 // * flag +#define DIV 4 // / flag + +#define DIGITAL_VALUE 4 //ƦTflag +#define ANALOG_VALUE 5 //Tflag + +#define BLK_FUN 6 //Blocks + +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: //NJȬۥ[ + return m_pBlkHead1->GetBlkValue () + m_pBlkHead2->GetBlkValue (); + break; + case MINUS: //NJȬ۴ + return m_pBlkHead1->GetBlkValue () - m_pBlkHead2->GetBlkValue (); + break; + case MULTI: //NJȬۭ + return m_pBlkHead1->GetBlkValue () * m_pBlkHead2->GetBlkValue (); + break; + case DIV: //NJȬ۰ + return m_pBlkHead1->GetBlkValue () / m_pBlkHead2->GetBlkValue (); + break; + default: + return NO_VALUE; + break; + } +} + +int CBlockFun::GetValueFlag () const +{ + if (m_pBlkHead1 == NULL || m_pBlkHead2 == NULL) //Ysb@JIsA^"L" + return NO_VALUE; + else if (m_pBlkHead1->GetValueFlag () == NO_VALUE || m_pBlkHead2->GetValueFlag () == NO_VALUE) //Ysb@JLȡA^"L" + return NO_VALUE; + else if (m_pBlkHead1->GetValueFlag () == COMPUTE_ERROR || m_pBlkHead2->GetValueFlag () == COMPUTE_ERROR) //Ysb@Jp~A^"p~" + return COMPUTE_ERROR; + else if (m_pBlkHead1->GetValueFlag () == DIGITAL_VALUE || m_pBlkHead2->GetValueFlag () == DIGITAL_VALUE) //\ƦJ + return COMPUTE_ERROR; + else if (m_iOperFlag == NO_OPER_FLAG) //]wB⤸ + return NO_OPER_FLAG; + else if (m_pBlkHead1->GetValueFlag () == NO_OPER_FLAG || m_pBlkHead2->GetValueFlag () == NO_OPER_FLAG) //]wB⤸ + return NO_OPER_FLAG; + else if (m_pBlkHead1->GetValueFlag () == ANALOG_VALUE && m_pBlkHead2->GetValueFlag () == ANALOG_VALUE) //YJҬTAh^T + 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 (); //su_IJBlockXPin}I + CPoint ptEnd = m_rcPinIn1.CenterPoint (); //suIBlockJPin}I + int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //Ij + int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //psuBZJBlockXӹjI + int iCornerY = iCornerGridY * iGrid + ptStart.y; //suBYyЦm + 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 (); //su_IJBlockXPin}I + CPoint ptEnd = m_rcPinIn2.CenterPoint (); //suIBlockJPin}I + int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //Ij + int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //psuBZJBlockXӹjI + int iCornerY = iCornerGridY * iGrid + ptStart.y; //suBYyЦm + 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; +} \ No newline at end of file diff --git a/TestSimulator/BlockFun.h b/TestSimulator/BlockFun.h new file mode 100644 index 0000000..a73a54d --- /dev/null +++ b/TestSimulator/BlockFun.h @@ -0,0 +1,62 @@ +#pragma once + +//BlocklOGBlock Fun + +#include "BlockBasis.h" + +class CBlockFun : public CBlockBasis +{ +private: + //Block rect(sbӿJPinA@ӿXPin) + CRect m_rcPinIn1; + CRect m_rcPinIn2; + CRect m_rcPinOut; + + //s(sbӳs) + CBlockBasis* m_pBlkHead1; + CBlockBasis* m_pBlkHead2; + + //sBlocks(sbӽs) + int m_iBlkHead1Num; + int m_iBlkHead2Num; + + //B⤸flag + int m_iOperFlag; + +public: + //غcBѺcl + CBlockFun (); + virtual ~CBlockFun (); + + //oB]wrect + virtual void SetBlkRect (CPoint, int, int); + virtual CRect GetPinIn1Rect () const; + virtual CRect GetPinIn2Rect () const; + virtual CRect GetPinOutRect () const; + + //oB]wsBlock + virtual CBlockBasis* GetBlkHead1Ptr () const; + virtual CBlockBasis* GetBlkHead2Ptr () const; + virtual void SetBlkHead1Ptr (CBlockBasis*); + virtual void SetBlkHead2Ptr (CBlockBasis*); + + //oB]wsBlocks + virtual int GetBlkHead1Num () const; + virtual int GetBlkHead2Num () const; + virtual void SetBlkHead1Num (int) ; + virtual void SetBlkHead2Num (int) ; + + //oB]wB⤸flag + virtual int GetOperFlag () const; + virtual void SetOperFlag (int); + + virtual double GetBlkValue () const; //oBlock + virtual int GetValueFlag () const; //oValueX + + virtual void Move (CPoint); //Block + virtual void Draw (CDC*); //øsBlock + virtual void DrawLine (CDC*); //øsBlocksu + + //P_Block + virtual int BlkTypeIs () const; +}; \ No newline at end of file diff --git a/TestSimulator/BlockIn.cpp b/TestSimulator/BlockIn.cpp new file mode 100644 index 0000000..9a1d199 --- /dev/null +++ b/TestSimulator/BlockIn.cpp @@ -0,0 +1,152 @@ +#include "stdafx.h" + +#include "BlockIn.h" + +#include "math.h" + +#define PIN_RADIUS 8 //Pinb| + +#define GOLD RGB (255, 215, 0) //Pin}C + +#define NO_VALUE -10 //sbJT +#define NO_INPUT_FLAG -12 //sbJi + +#define ZERO 0 //FALSE flag +#define ONE 1 //TRUE flag +#define SIN 2 //Sin flag +#define COS 3 //Cos flag + +#define DIGITAL_VALUE 4 //ƦTflag +#define ANALOG_VALUE 5 //Tflag + +#define BLK_IN 1 //Blocks + +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; +} + +//ΥH]wwɶIUBlock (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; + } +} + +//]wBlock (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: //JiάTRUEɡA^ǼƦT + return DIGITAL_VALUE; + break; + case ONE: //JiάFALSEɡA^ǼƦT + return DIGITAL_VALUE; + break; + case SIN: //JiάSINɡA^T + return ANALOG_VALUE; + break; + case COS: //JiάCOSɡA^T + 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; +} \ No newline at end of file diff --git a/TestSimulator/BlockIn.h b/TestSimulator/BlockIn.h new file mode 100644 index 0000000..cf607d6 --- /dev/null +++ b/TestSimulator/BlockIn.h @@ -0,0 +1,43 @@ +#pragma once + +//BlocklOGBlock In + +#include "BlockBasis.h" + +class CBlockIn : public CBlockBasis +{ +private: + //Block rect(sb@ӿXPin) + CRect m_rcPinOut; + + //Jiflag + int m_iInputFlag; + + //Block + double m_dBlkValue; + +public: + //غcBѺcl + CBlockIn (); + virtual ~CBlockIn (); + + //oB]wrect + virtual void SetBlkRect (CPoint, int, int); + virtual CRect GetPinOutRect () const; + + //oB]wJiflag + virtual int GetInputFlag () const; + virtual void SetInputFlag (int); + + //oB]wBlock + virtual double GetBlkValue () const; + virtual void SetBlkValue (double); + virtual void SetBlkValue (); + virtual int GetValueFlag () const; //oValueX + + virtual void Move (CPoint); //Block + virtual void Draw (CDC*); //øsBlock + + //P_Block + virtual int BlkTypeIs () const; +}; \ No newline at end of file diff --git a/TestSimulator/BlockNot.cpp b/TestSimulator/BlockNot.cpp new file mode 100644 index 0000000..c289b00 --- /dev/null +++ b/TestSimulator/BlockNot.cpp @@ -0,0 +1,164 @@ +#include "stdafx.h" + +#include "BlockNot.h" + +#define PIN_RADIUS 8 //Pinb| + +#define GOLD RGB (255, 215, 0) //Pin}C +#define BLACK RGB (0, 0, 0) //suC + +#define NO_VALUE -10 //sbJT +#define NO_OPER_FLAG -11 //sbB⤸ +#define COMPUTE_ERROR -13 //\B +#define NO_BLOCK_HEAD -14 //sbsBlock + +#define TOLERANCE 0.001 //eԻ~t + +#define DIGITAL_VALUE 4 //ƦTflag +#define ANALOG_VALUE 5 //Tflag + +#define BLK_NOT 5 //Blocks + +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޿ (YJ0Ah^1AϤ^0) + if (m_pBlkHead->GetBlkValue () < TOLERANCE) + return 1.; + else + return 0.; +} + +int CBlockNot::GetValueFlag () const +{ + if (m_pBlkHead == NULL) //YJIsA^"L" + return NO_VALUE; + else if (m_pBlkHead->GetValueFlag () == NO_VALUE) //YJLȡA^"L" + return NO_VALUE; + else if (m_pBlkHead->GetValueFlag () == COMPUTE_ERROR) //YJp~A^"p~" + return COMPUTE_ERROR; + else if (m_pBlkHead->GetValueFlag () == ANALOG_VALUE) //\J + return COMPUTE_ERROR; + else if (m_pBlkHead->GetValueFlag () == NO_OPER_FLAG) //]wB⤸ + return NO_OPER_FLAG; + else if (m_pBlkHead->GetValueFlag () == DIGITAL_VALUE) //YJƦTAh^ǼƦT + 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 (); //su_IJBlockXPin}I + CPoint ptEnd = m_rcPinIn.CenterPoint (); //suIBlockJPin}I + int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //Ij + int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //psuBZJBlockXӹjI + int iCornerY = iCornerGridY * iGrid + ptStart.y; //suBYyЦm + 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; +} \ No newline at end of file diff --git a/TestSimulator/BlockNot.h b/TestSimulator/BlockNot.h new file mode 100644 index 0000000..09f36a6 --- /dev/null +++ b/TestSimulator/BlockNot.h @@ -0,0 +1,47 @@ +#pragma once + +//BlocklOGBlock Not + +#include "BlockBasis.h" + +class CBlockNot : public CBlockBasis +{ +private: + //Block rect(sb@ӿJPinA@ӿXPin) + CRect m_rcPinIn; + CRect m_rcPinOut; + + //s + CBlockBasis* m_pBlkHead; + + //sBlocks + int m_iBlkHeadNum; + +public: + //غcBѺcl + CBlockNot (); + virtual ~CBlockNot (); + + //oB]wrect + virtual void SetBlkRect (CPoint, int, int); + virtual CRect GetPinIn1Rect () const; + virtual CRect GetPinOutRect () const; + + //oB]wsBlock + virtual CBlockBasis* GetBlkHead1Ptr () const; + virtual void SetBlkHead1Ptr (CBlockBasis*); + + //oB]wsBlocks + virtual int GetBlkHead1Num () const; + virtual void SetBlkHead1Num (int) ; + + virtual double GetBlkValue () const; //oBlock + virtual int GetValueFlag () const; //oValueX + + virtual void Move (CPoint); //Block + virtual void Draw (CDC*); //øsBlock + virtual void DrawLine (CDC*); //øsBlocksu + + //P_Block + virtual int BlkTypeIs () const; +}; \ No newline at end of file diff --git a/TestSimulator/BlockOr.cpp b/TestSimulator/BlockOr.cpp new file mode 100644 index 0000000..675ba06 --- /dev/null +++ b/TestSimulator/BlockOr.cpp @@ -0,0 +1,226 @@ +#include "stdafx.h" + +#include "BlockOr.h" + +#include "math.h" + +#define PIN_RADIUS 8 //Pinb| + +#define GOLD RGB (255, 215, 0) //Pin}C +#define BLACK RGB (0, 0, 0) //suC + +#define NO_VALUE -10 //sbJT +#define NO_OPER_FLAG -11 //sbB⤸ +#define COMPUTE_ERROR -13 //\B +#define NO_BLOCK_HEAD -14 //sbsBlock + +#define TOLERANCE 0.001 //eԻ~t + +#define DIGITAL_VALUE 4 //ƦTflag +#define ANALOG_VALUE 5 //Tflag + +#define BLK_OR 4 //Blocks + +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޿ (Y䤤@J1Ah^1A_h^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) //Ysb@JIsA^"L" + return NO_VALUE; + else if (m_pBlkHead1->GetValueFlag () == NO_VALUE || m_pBlkHead2->GetValueFlag () == NO_VALUE) //Ysb@JLȡA^"L" + return NO_VALUE; + else if (m_pBlkHead1->GetValueFlag () == COMPUTE_ERROR || m_pBlkHead2->GetValueFlag () == COMPUTE_ERROR) //Ysb@Jp~A^"p~" + return COMPUTE_ERROR; + else if (m_pBlkHead1->GetValueFlag () == ANALOG_VALUE || m_pBlkHead2->GetValueFlag () == ANALOG_VALUE) //\J + return COMPUTE_ERROR; + else if (m_pBlkHead1->GetValueFlag () == NO_OPER_FLAG || m_pBlkHead2->GetValueFlag () == NO_OPER_FLAG) //]wB⤸ + return NO_OPER_FLAG; + else if (m_pBlkHead1->GetValueFlag () == DIGITAL_VALUE && m_pBlkHead2->GetValueFlag () == DIGITAL_VALUE) //YJҬƦTAh^ǼƦT + 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 (); //su_IJBlockXPin}I + CPoint ptEnd = m_rcPinIn1.CenterPoint (); //suIBlockJPin}I + int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //Ij + int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //psuBZJBlockXӹjI + int iCornerY = iCornerGridY * iGrid + ptStart.y; //suBYyЦm + 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 (); //su_IJBlockXPin}I + CPoint ptEnd = m_rcPinIn2.CenterPoint (); //suIBlockJPin}I + int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //Ij + int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //psuBZJBlockXӹjI + int iCornerY = iCornerGridY * iGrid + ptStart.y; //suBYyЦm + 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; +} \ No newline at end of file diff --git a/TestSimulator/BlockOr.h b/TestSimulator/BlockOr.h new file mode 100644 index 0000000..e4c8554 --- /dev/null +++ b/TestSimulator/BlockOr.h @@ -0,0 +1,55 @@ +#pragma once + +//BlocklOGBlock Or + +#include "BlockBasis.h" + +class CBlockOr : public CBlockBasis +{ +private: + //Block rect(sbӿJPinA@ӿXPin) + CRect m_rcPinIn1; + CRect m_rcPinIn2; + CRect m_rcPinOut; + + //s(sbӳs) + CBlockBasis* m_pBlkHead1; + CBlockBasis* m_pBlkHead2; + + //sBlocks(sbӽs) + int m_iBlkHead1Num; + int m_iBlkHead2Num; + +public: + //غcBѺcl + CBlockOr (); + virtual ~CBlockOr (); + + //oB]wrect + virtual void SetBlkRect (CPoint, int, int); + virtual CRect GetPinIn1Rect () const; + virtual CRect GetPinIn2Rect () const; + virtual CRect GetPinOutRect () const; + + //oB]wsBlock + virtual CBlockBasis* GetBlkHead1Ptr () const; + virtual CBlockBasis* GetBlkHead2Ptr () const; + virtual void SetBlkHead1Ptr (CBlockBasis*); + virtual void SetBlkHead2Ptr (CBlockBasis*); + + //oB]wsBlocks + virtual int GetBlkHead1Num () const; + virtual int GetBlkHead2Num () const; + virtual void SetBlkHead1Num (int) ; + virtual void SetBlkHead2Num (int) ; + + virtual double GetBlkValue () const; //oBlock + virtual int GetValueFlag () const; //oValueX + + virtual void Move (CPoint); //Block + virtual void Draw (CDC*); //øsBlock + virtual void DrawLine (CDC*); //øsBlocksu + + //P_Block + virtual int BlkTypeIs () const; +}; \ No newline at end of file diff --git a/TestSimulator/BlockOut.cpp b/TestSimulator/BlockOut.cpp new file mode 100644 index 0000000..99a50c3 --- /dev/null +++ b/TestSimulator/BlockOut.cpp @@ -0,0 +1,163 @@ +#include "stdafx.h" + +#include "BlockOut.h" + +#define PIN_RADIUS 8 //Pinb| + +#define GOLD RGB (255, 215, 0) //Pin}C +#define BLACK RGB (0, 0, 0) //suC + +#define NO_VALUE -10 //sbJT +#define NO_BLOCK_HEAD -14 //sbsBlock + +#define BLK_OUT 2 //Blocks + +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 +{ + //^ǫwindexs + if (iIndex < m_iBlkHeadSize) + return m_vcBlkHeadPtr[iIndex]; + else + return NULL; +} + +void CBlockOut::SetBlkHead1Ptr (CBlockBasis* pBlkHead) +{ + m_vcBlkHeadPtr.push_back (pBlkHead); //sWs +} + +void CBlockOut::DeleteBlkHead1Ptr (int iIndex) +{ + m_vcBlkHeadPtr.erase (m_vcBlkHeadPtr.begin () + iIndex); //Mwindexs +} + +int CBlockOut::GetBlkHead1Num (int iIndex) const +{ + //^ǫwindexsBlocks + if (iIndex < m_iBlkHeadSize) + return m_vcBlkHeadNum[iIndex]; + else + return NO_BLOCK_HEAD; +} + +void CBlockOut::SetBlkHead1Num (int iHeadBlkNum) +{ + m_vcBlkHeadNum.push_back (iHeadBlkNum); //sWsBlocks +} + +void CBlockOut::ClearBlkHead1Num () +{ + std::vector ().swap (m_vcBlkHeadNum); //Mųssvector +} + +int CBlockOut::GetBlkHeadSize () const +{ + return m_iBlkHeadSize; //^ǿJchannelƥ +} + +void CBlockOut::SetBlkHeadSize (int iFlag) +{ + //]wJchannelƥ + if (iFlag == FALSE) //flagFALSEɡA̳ssvectorjp]w + m_iBlkHeadSize = (int) m_vcBlkHeadNum.size (); + else if (iFlag == TRUE) //flagTRUEɡA̳svectorjp]w + m_iBlkHeadSize = (int) m_vcBlkHeadPtr.size (); +} + +double CBlockOut::GetBlkValue (int iIndex) const +{ + //owchannelBlock + if (!m_vcBlkHeadPtr.empty () && iIndex < m_iBlkHeadSize) + return m_vcBlkHeadPtr[iIndex]->GetBlkValue (); + else + return NO_VALUE; +} + +int CBlockOut::GetValueFlag (int iIndex) const +{ + //owchannelValueX + 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 (); //su_IJBlockXPin}I + CPoint ptEnd = m_rcPinIn.CenterPoint (); //suIBlockJPin}I + int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //Ij + int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //psuBZJBlockXӹjI + int iCornerY = iCornerGridY * iGrid + ptStart.y; //suBYyЦm + 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; +} \ No newline at end of file diff --git a/TestSimulator/BlockOut.h b/TestSimulator/BlockOut.h new file mode 100644 index 0000000..7cc06fb --- /dev/null +++ b/TestSimulator/BlockOut.h @@ -0,0 +1,57 @@ +#pragma once + +//BlocklOGBlock Out + +#include "BlockBasis.h" + +#include + +class CBlockOut : public CBlockBasis +{ +private: + //Block rect(sb@ӿJPin) + CRect m_rcPinIn; + + //svector(sbhӿJchannel) + std::vector m_vcBlkHeadPtr; + + //ssvector(sbhӿJchannel) + std::vector m_vcBlkHeadNum; + + //Jchannelƥ + int m_iBlkHeadSize; + + +public: + //غcBѺcl + CBlockOut (); + virtual ~CBlockOut (); + + //oB]wrect + virtual void SetBlkRect (CPoint, int, int); + virtual CRect GetPinIn1Rect () const; + + //oB]wsBlock + virtual CBlockBasis* GetBlkHead1Ptr (int) const; + virtual void SetBlkHead1Ptr (CBlockBasis*); + virtual void DeleteBlkHead1Ptr (int); + + //oB]wsBlocks + virtual int GetBlkHead1Num (int) const; + virtual void SetBlkHead1Num (int) ; + virtual void ClearBlkHead1Num (); + + //oB]wJchannelƥ + virtual int GetBlkHeadSize () const; + virtual void SetBlkHeadSize (int); + + virtual double GetBlkValue (int) const; //oBlock + virtual int GetValueFlag (int) const; //oValueX + + virtual void Move (CPoint); //Block + virtual void Draw (CDC*); //øsBlock + virtual void DrawLine (CDC*); //øsBlocksu + + //P_Block + virtual int BlkTypeIs () const; +}; \ No newline at end of file diff --git a/TestSimulator/Complex.cpp b/TestSimulator/Complex.cpp new file mode 100644 index 0000000..056155e --- /dev/null +++ b/TestSimulator/Complex.cpp @@ -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); +} \ No newline at end of file diff --git a/TestSimulator/Complex.h b/TestSimulator/Complex.h new file mode 100644 index 0000000..f970a45 --- /dev/null +++ b/TestSimulator/Complex.h @@ -0,0 +1,22 @@ +#pragma once + +class CComplex +{ +public: + double m_dReal; //Ƽƹ곡 + double m_dImag; //ƼƵ곡 + +public: + //غcBѺcl + CComplex (); + CComplex (double, double); + ~CComplex (); + + //B⤸ + CComplex operator+ (const CComplex &); + CComplex operator- (const CComplex &); + CComplex operator* (const CComplex &); + + //pƼƮTjp + double ComputeAmplitude () const; +}; \ No newline at end of file diff --git a/TestSimulator/FunDlg.cpp b/TestSimulator/FunDlg.cpp new file mode 100644 index 0000000..cbaf2fc --- /dev/null +++ b/TestSimulator/FunDlg.cpp @@ -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 //sbB⤸ + +#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 (); + + //lƮŪB⤸flagAñNܩ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; //U+]wJiflagPLUS + ( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("+")); +} + + +void CFunDlg::OnBnClickedButtonMinus () +{ + m_iOperFlag = MINUS; //U-]wJiflagMINUS + ( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("-")); +} + + +void CFunDlg::OnBnClickedButtonMulti () +{ + m_iOperFlag = MULTI; //U*]wJiflagMULTI + ( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("*")); +} + + +void CFunDlg::OnBnClickedButtonDiv () +{ + m_iOperFlag = DIV; //U/]wJiflagDIV + ( (CEdit* ) GetDlgItem (IDC_EDIT_OPERATOR))->SetWindowTextA (_T ("/")); +} \ No newline at end of file diff --git a/TestSimulator/FunDlg.h b/TestSimulator/FunDlg.h new file mode 100644 index 0000000..b88c4c3 --- /dev/null +++ b/TestSimulator/FunDlg.h @@ -0,0 +1,41 @@ + +// FunDlg.h : Y +// + +#pragma once + + +// InputDlg ܤ +class CFunDlg: public CDialogEx +{ + // غc +public: + CFunDlg (CWnd* pParent = NULL); // зǫغc禡 + ~CFunDlg (); + +// ܤ + enum { IDD = IDD_DIALOG_FUN }; + +private: + int m_iOperFlag; +protected: + virtual void DoDataExchange (CDataExchange* pDX); // DDX/DDV 䴩 + + // {X@ +protected: + HICON m_hIcon; + + // ͪT禡 + virtual BOOL OnInitDialog (); + DECLARE_MESSAGE_MAP () + +public: + //oB]wB⤸flag + int GetOperFlag () const; + void SetOperFlag (int); + + afx_msg void OnBnClickedButtonPlus (); + afx_msg void OnBnClickedButtonMinus (); + afx_msg void OnBnClickedButtonMulti (); + afx_msg void OnBnClickedButtonDiv (); +}; diff --git a/TestSimulator/Initial.ini b/TestSimulator/Initial.ini new file mode 100644 index 0000000..fcd4e84 --- /dev/null +++ b/TestSimulator/Initial.ini @@ -0,0 +1,6 @@ +[BgParameter] +BgPicBOOL=FALSE +BgPicPath=None +BgColor=65535 +GridBOOL=TRUE +LockBOOL=TRUE diff --git a/TestSimulator/InputDlg.cpp b/TestSimulator/InputDlg.cpp new file mode 100644 index 0000000..ba754b7 --- /dev/null +++ b/TestSimulator/InputDlg.cpp @@ -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 //sbJi + +#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; //lƿJiflag +} + +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 (); + + //lƮŪJiflagAñNܩ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; //UTrue]wJiflagONE + ( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("True")); +} + +void CInputDlg::OnBnClickedButtonFalse () +{ + m_iInputFlag = ZERO; //UFalse]wJiflagZERO + ( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("False")); +} + +void CInputDlg::OnBnClickedButtonSin () +{ + m_iInputFlag = SIN; //USin]wJiflagSIN + ( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("Sin (t)")); +} + +void CInputDlg::OnBnClickedButtonCos () +{ + m_iInputFlag = COS; //UCos]wJiflagCOS + ( (CEdit*) GetDlgItem (IDC_EDIT_INPUT_VALUE))->SetWindowTextA (_T ("Cos (t)")); +} \ No newline at end of file diff --git a/TestSimulator/InputDlg.h b/TestSimulator/InputDlg.h new file mode 100644 index 0000000..d48e689 --- /dev/null +++ b/TestSimulator/InputDlg.h @@ -0,0 +1,42 @@ + +// InputDlg.h : Y +// + +#pragma once + + +// InputDlg ܤ +class CInputDlg : public CDialogEx +{ + // غc +public: + CInputDlg (CWnd* pParent = NULL); // зǫغc禡 + virtual ~CInputDlg (); + +// ܤ + enum { IDD = IDD_DIALOG_INPUT }; + +private: + int m_iInputFlag; + +protected: + virtual void DoDataExchange (CDataExchange* pDX); // DDX/DDV 䴩 + + // {X@ +protected: + HICON m_hIcon; + + // ͪT禡 + virtual BOOL OnInitDialog (); + DECLARE_MESSAGE_MAP () + +public: + //oB]wJiflag + int GetInputFlag () const; + void SetInputFlag (int); + + afx_msg void OnBnClickedButtonTrue(); + afx_msg void OnBnClickedButtonFalse(); + afx_msg void OnBnClickedButtonSin(); + afx_msg void OnBnClickedButtonCos(); +}; diff --git a/TestSimulator/OscDlg.cpp b/TestSimulator/OscDlg.cpp new file mode 100644 index 0000000..1a1ad48 --- /dev/null +++ b/TestSimulator/OscDlg.cpp @@ -0,0 +1,434 @@ + +// OscDlg.cpp : @ +// + +#include "stdafx.h" +#include "TestSimulator.h" +#include "OscDlg.h" +#include "afxdialogex.h" + +#include "TestSimulatorDlg.h" + +#include +#include + +//#include +//using namespace std; + +//u@ϰѼ +#define WORK_LEFT 0 +#define WORK_TOP 0 +#define WORK_RIGHT 500 +#define WORK_BOTTOM 500 + +#define BLACK RGB (0, 0, 0) //IC +#define BLUE RGB (0, 0, 255) //C +#define WHITE RGB (255, 255, 255) //y = 0uC +#define YELLOW RGB (255, 255, 0) //Zu@ӳ쪺uC +#define RED RGB (255, 0, 0) //Zuӳ쪺uC +#define GOLD RGB (255, 215, 0) //outputiC + +#define GRID 10 +#define UNITY 100 + +#define MAX_PLOT_NUM 501 //̤jøsdata +#define OFFSET_Y 250 //ܲyХWIAFøøsܪiAGøϮɻݼW[@Ӱq(0, 0)ܪiϥI + + +// 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 TBz` + +BOOL COscDlg::OnInitDialog () +{ + CDialogEx::OnInitDialog(); + + //]wüƺؤl + srand ((unsigned int) time (NULL)); + + //]wYbjCombo boxe + 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); + } + + //lYbj + m_ctrlComboYInterval.SetCurSel (0); + m_dYInterval = 0.5; + m_iYPos = 0; + m_dMaxDataValue = m_dYInterval * 2.5; + + + //]wXbjCombo boxe + 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")); + + //lXbj + 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 () +{ + //wīإ + CPaintDC dcOsc (this); //ܪiܲdc + CDC dcMem; //sdc + CBitmap bitmapMem; + CBitmap* pOldBitmap; + + dcMem.CreateCompatibleDC (&dcOsc); //إ߻Pܪiܲۮedc + bitmapMem.CreateCompatibleBitmap (&dcOsc, WORK_RIGHT, WORK_BOTTOM); + pOldBitmap = dcMem.SelectObject (&bitmapMem); + + //øsI + dcMem.SetBkMode (TRANSPARENT); + dcMem.FillSolidRect (m_rcWork, BLACK); + + //ŦAC 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); //u + dcMem.LineTo (i, m_rcWork.Height ()); + dcMem.MoveTo (0, i); //u + dcMem.LineTo (m_rcWork.Width (), i); + } + + //øsܪiu(Xb) + 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); //eu + dcMem.TextOutA (0, m_rcWork.Height () / 2, strValueZero, strValueZero.GetLength ()); //аOr + + + //Zu@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 ()); + + + //ZuUNITY (@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 ()); + + + //}l + if (m_bSim) + { + CPen penGold (PS_SOLID, 6, GOLD); + + int iDataSize = (int) m_pSimulatorDlg->m_deq2DOutputValue.size (); //odataƥ + + //dataƤj1A}løsoutputi + if (iDataSize > 1) + { + int iPlotStart = 0; //øsdata_I + if (iDataSize > MAX_PLOT_NUM) + iPlotStart = iDataSize - MAX_PLOT_NUM; + + for (int i = 0; i < m_iOutputSize; i++) + { + //]woutputeʪe + if (m_iSlctOutputNum >= 0 && i == m_iSlctOutputNum) + dcMem.SelectObject (&penGold); + else + dcMem.SelectObject (m_deqPenPtr[i]); + + for (int j = 1; j < iDataSize; j++) + { + //WXiøsdataơAhߧYXj + 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]; + + //P_dataȬO_WXܪiiܤ̤j + 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); + } + } + } + } + + //Ѥsdcܥܪiܲdc + dcOsc.BitBlt (WORK_LEFT, WORK_TOP, m_rcWork.Width (), m_rcWork.Height (), &dcMem, WORK_LEFT, WORK_TOP, SRCCOPY); + + //Mz + dcMem.SelectObject (pOldPen); + dcMem.SelectObject (pOldBitmap); + bitmapMem.DeleteObject (); + dcMem.DeleteDC (); +} + +//ѥDܲǭ(eɶ, output value, Wv) +void COscDlg::SetData (double dTime, double dValue, double dFreq) +{ + m_dTime = dTime; + m_dSlctOutputValue = dValue; + m_dFreq = dFreq; +} + +// ѥDܲǭ(eɶ, output value) +void COscDlg::SetData (double dTime, double dValue) +{ + m_dTime = dTime; + m_dSlctOutputValue = dValue; +} + +//UStart +void COscDlg::OnBnClickedButtonStart () +{ + if (!m_bSim) + { + m_bModify = FALSE; //}liXbjCombo box + m_bSim = TRUE; + m_pSimulatorDlg->SetTimer (0, 10, NULL); + } +} + +//UStop +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; +} + +//Ybj 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 (); +} + +//Xbj 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 () +{ + //MHedeque + 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 (); //Moutput combo boxe + m_bSim = FALSE; // + m_bModify = TRUE; //icombo 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 (); +} + +//]wchannelƥ +void COscDlg::SetOutputSize (int iOutSize) +{ + m_iOutputSize = iOutSize; +} + +//lƥܪiܲ(channelƥ, He) +void COscDlg::InitialData () +{ + //]woutput combo boxe + for (int i = 0; i < m_iOutputSize; i++) + { + CString strOutput; + strOutput.Format (_T ("Output %d"), i + 1); + m_ctrlComboOutput.AddString (strOutput); + } + + //إHe + 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); +} + +//oɶj +int COscDlg::GetTimeInterval () const +{ + return m_iXInterval; +} \ No newline at end of file diff --git a/TestSimulator/OscDlg.h b/TestSimulator/OscDlg.h new file mode 100644 index 0000000..361651f --- /dev/null +++ b/TestSimulator/OscDlg.h @@ -0,0 +1,72 @@ + +// OscDlg.h : Y +// + +#pragma once + +#include "afxwin.h" +#include + +class CTestSimulatorDlg; + +// COscDlg ܤ + +class COscDlg : public CDialogEx +{ +public: + COscDlg (CWnd* pParent = NULL); // зǫغc禡 + virtual ~COscDlg (); + +// ܤ + enum { IDD = IDD_DIALOG_OSC }; + +private: + CTestSimulatorDlg* m_pSimulatorDlg; //Dܲ + + CComboBox m_ctrlComboOutput; //Output combo boxܼ + CComboBox m_ctrlComboYInterval; //Ybj combo boxܼ + CComboBox m_ctrlComboXInterval; //Xbj combo boxܼ + + std::deque m_deqPenPtr; //Hedeque + + double m_dTime; //ɶ + double m_dSlctOutputValue; //output value + double m_dMaxDataValue; //ܪi̤ܳj + double m_dFreq; //Wv + + int m_iOutputSize; //channelƥ + double m_dYInterval; //Ybj + int m_iXInterval; //Xbj + int m_iYPos; //Ybj combo boxm + int m_iXPos; //Xbj combo boxm + +protected: + HICON m_hIcon; + + virtual void DoDataExchange (CDataExchange* pDX); // DDX/DDV 䴩 + + DECLARE_MESSAGE_MAP () +public: + CRect m_rcWork; //ܪiܲu@ + + int m_iSlctOutputNum; //outputs + + BOOL m_bSim; //P_ + BOOL m_bModify; //P_combo box + BOOL m_bFFT; //P_iFFT + + 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; +}; diff --git a/TestSimulator/TestSimulator.cpp b/TestSimulator/TestSimulator.cpp new file mode 100644 index 0000000..3b30a62 --- /dev/null +++ b/TestSimulator/TestSimulator.cpp @@ -0,0 +1,102 @@ + +// TestSimulator.cpp : wqε{O欰C +// + +#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 غc + +CTestSimulatorApp::CTestSimulatorApp() +{ + // 䴩sҰʺ޲z + m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; + + // TODO: b[Jغc{XA + // NҦnl]w[J InitInstance +} + + +// Ȧ@ CTestSimulatorApp + +CTestSimulatorApp theApp; + + +// CTestSimulatorApp l]w + +BOOL CTestSimulatorApp::InitInstance() +{ + // pε{TMwϥ ComCtl32.dll 6 (t) H᪩A + // ӱҰʵıƼ˦Ab Windows XP WAhݭn InitCommonControls()C + // _hإ߳NѡC + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // ]wn]tҦzQnΩε{ + // qαOC + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // إߴ߼h޲zAHܤ]t + // ߼h˵δ߼hM˵C + CShellManager *pShellManager = new CShellManager; + + // Ұ [Windows ] ıƺ޲ziҥ MFC DD + CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); + + // зǪl]w + // pGzϥγoǥ\åBQ + // ̫᧹iɤjpAziH + // qUC{XݭnlƱ`A + // ܧxs]wȪnX + // TODO: zӾA׭ק惡r + // (ҦpAqW٩β´W) + SetRegistryKey(_T(" AppWizard Ҳͪε{")); + + CTestSimulatorDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: bmϥ [Tw] Ӱϥιܤ + // Bz{X + } + else if (nResponse == IDCANCEL) + { + // TODO: bmϥ [] Ӱϥιܤ + // Bz{X + } + else if (nResponse == -1) + { + TRACE(traceAppMsg, 0, "ĵi: ܤإߥѡA]Aε{N~פC\n"); + TRACE(traceAppMsg, 0, "ĵi: pGznbܤWϥ MFC AhLk #define _AFX_NO_MFC_CONTROLS_IN_DIALOGSC\n"); + } + + // RWҫإߪ߼h޲zC + if (pShellManager != NULL) + { + delete pShellManager; + } + + // ]wgܤAǦ^ FALSEAҥHڭ̷|ε{A + // ӫDܶ}lε{TC + return FALSE; +} + diff --git a/TestSimulator/TestSimulator.h b/TestSimulator/TestSimulator.h new file mode 100644 index 0000000..5989cd0 --- /dev/null +++ b/TestSimulator/TestSimulator.h @@ -0,0 +1,32 @@ + +// TestSimulator.h : PROJECT_NAME ε{DnY +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error " PCH ]tɮ׫e]t 'stdafx.h'" +#endif + +#include "resource.h" // DnŸ + + +// CTestSimulatorApp: +// аѾ\@O TestSimulator.cpp +// + +class CTestSimulatorApp : public CWinApp +{ +public: + CTestSimulatorApp(); + +// мg +public: + virtual BOOL InitInstance(); + +// {X@ + + DECLARE_MESSAGE_MAP() +}; + +extern CTestSimulatorApp theApp; \ No newline at end of file diff --git a/TestSimulator/TestSimulator.rc b/TestSimulator/TestSimulator.rc new file mode 100644 index 0000000..54c9859 Binary files /dev/null and b/TestSimulator/TestSimulator.rc differ diff --git a/TestSimulator/TestSimulator.vcxproj b/TestSimulator/TestSimulator.vcxproj new file mode 100644 index 0000000..34ed872 --- /dev/null +++ b/TestSimulator/TestSimulator.vcxproj @@ -0,0 +1,163 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {C1F3E95D-9580-4550-A748-674E1D31DF84} + TestSimulator + MFCProj + 8.1 + + + + Application + true + v110 + MultiByte + Static + + + Application + false + v140 + true + MultiByte + Static + + + + + + + + + + + + + true + true + + + false + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0404 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0404 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TestSimulator/TestSimulator.vcxproj.filters b/TestSimulator/TestSimulator.vcxproj.filters new file mode 100644 index 0000000..8e65d90 --- /dev/null +++ b/TestSimulator/TestSimulator.vcxproj.filters @@ -0,0 +1,129 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + 標頭檔 + + + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + 原始程式檔 + + + + + 資源檔 + + + + + 資源檔 + + + + + 資源檔 + + + \ No newline at end of file diff --git a/TestSimulator/TestSimulator.vcxproj.user b/TestSimulator/TestSimulator.vcxproj.user new file mode 100644 index 0000000..deea718 --- /dev/null +++ b/TestSimulator/TestSimulator.vcxproj.user @@ -0,0 +1,7 @@ + + + + $(TargetPath) + WindowsLocalDebugger + + \ No newline at end of file diff --git a/TestSimulator/TestSimulatorDlg.cpp b/TestSimulator/TestSimulatorDlg.cpp new file mode 100644 index 0000000..6147074 --- /dev/null +++ b/TestSimulator/TestSimulatorDlg.cpp @@ -0,0 +1,1582 @@ + +// TestSimulatorDlg.cpp : @ +// + + +#include "stdafx.h" +#include "TestSimulator.h" +#include "TestSimulatorDlg.h" +#include "afxdialogex.h" + +#define _USE_MATH_DEFINES +#include "math.h" + +//#include +//using namespace std; + +#define WIN_WIDTH 1316 //ܲȤϼe +#define WIN_HEIGHT 559 //ܲȤϰ +#define GRID_R 1 //@Ib|jp +#define MAX_STR_LEN 100 //̤jr (ΩŪini) + +#define WHITE RGB (255, 255, 255) //u@ϭIw]C +#define GRAY RGB (240, 240, 240) //IC +#define LIGHT_BLUE RGB (176, 224, 230) //BlockC +#define RED RGB (255, 0, 0) //BlockC +#define BLACK RGB (0, 0, 0) //suC + +#define MARK_FONTSIZE 120 //ҦMarkrjp +#define MARK_WIDTH 90 //Markϰe +#define MARK_LOCK_WIDTH 60 //Lock Markϰe +#define MARK_HEIGHT 40 //Markϰ찪 + +#define NO_VALUE -10 //sbJT +#define NO_OPER_FLAG -11 //sbB⤸ +#define NO_INPUT_FLAG -12 //sbJi +#define COMPUTE_ERROR -13 //\B +#define NO_BLOCK_HEAD -14 //sbsBlock +#define NO_SEL_NUM -15 //sbBlocks + +#define NO_BLK_TYPE 0 //Blockݩ{type +#define BLK_IN 1 //BlockIN +#define BLK_OUT 2 //BlockOUT +#define BLK_AND 3 //BlockAND +#define BLK_OR 4 //BlockOR +#define BLK_NOT 5 //BlockNOT +#define BLK_FUN 6 //BlockFUN + +#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 //̤jxsdataƥ (2) + + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + + +// App About ϥ CAboutDlg ܤ + +class CAboutDlg : public CDialogEx +{ +public: + CAboutDlg(); + +// ܤ + enum { IDD = IDD_ABOUTBOX }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 䴩 + +// {X@ +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 ܤ + + + +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 TBz` + +BOOL CTestSimulatorDlg::OnInitDialog() +{ + this->SetWindowPos (NULL, 0, 0, WIN_WIDTH, WIN_HEIGHT, SWP_NOZORDER | SWP_NOMOVE); //]wܲȤϰ + m_rcWork.SetRect (m_iWorkLeft, m_iWorkTop, m_iWorkRight, m_iWorkBottom); //]wu@ϰ + this->GetClientRect (&m_rcClient); //ŪܲȤϰ + m_dcBgPic.CreateCompatibleDC (NULL); //إ߻PܲۮedcAHJIϤ + + CString strIniPath (_T (".\\Initial.ini")); //.ini| + CString strAppName (_T ("BgParameter")); //.ini[`W] + + CString strBgPicBOOL; //xsIϤLȪr + CString strBgPicPath; //xsIϤ|r + CString strBgColor; //xsICȪr + CString strGridBOOL; //xsILȪr + CString strLockBOOL; //xswLȪr + + CString strKeyName (_T ("BgPicBOOL")); //.iniܼƦW + 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); + + //JIϤ(orC) + if (strBgPicBOOL == _T ("TRUE")) + { + m_strPicPath = strBgPicPath; + + //NŪ.bmpwHBITMAP + HBITMAP hbBgPic; + //QHBITMAP[ϡALoadImage (handle, Ϥ|, J˦, ϥܼe(), ϥܪ(), LR_LOADFROMFILE: ھڸ|ȸ˦bϹ) + 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); + + //]wIlA + if (strGridBOOL == _T ("TRUE")) + m_bGrid = TRUE; + + //JwlA + if (strLockBOOL == _T ("TRUE")) + m_bLock = TRUE; + + + CDialogEx::OnInitDialog(); + + // N [...] \[JtΥ\C + + // IDM_ABOUTBOX btΩROd򤧤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); + } + } + + // ]wܤϥܡCε{DOܤɡA + // ج[|۰ʱqƦ@~ + SetIcon(m_hIcon, TRUE); // ]wjϥ + SetIcon(m_hIcon, FALSE); // ]wpϥ + + m_bInitDlg = TRUE; + + return TRUE; // Ǧ^ TRUEADzﱱ]wJI +} + +void CTestSimulatorDlg::OnSysCommand(UINT nID, LPARAM lParam) +{ + if ((nID & 0xFFF0) == IDM_ABOUTBOX) + { + CAboutDlg dlgAbout; + dlgAbout.DoModal(); + } + else + { + CDialogEx::OnSysCommand(nID, lParam); + } +} + +// pGN̤pƫs[JzܤAzݭnUC{XA +// HKøsϥܡCϥΤ/˵Ҧ MFC ε{A +// ج[|۰ʧ@~C + +void CTestSimulatorDlg::OnPaint () +{ + //wīإ + CPaintDC dcSim (this); //Dܲdc + CDC dcMem; //sdc + CBitmap bitmapMem; + CBitmap * pOldBitmap; + + dcMem.CreateCompatibleDC (&dcSim); //إ߻PDܲۮedc + bitmapMem.CreateCompatibleBitmap (&dcSim, m_iWorkRight, m_iWorkBottom); + pOldBitmap = dcMem.SelectObject (&bitmapMem); + + //øsI + dcMem.SetBkMode (TRANSPARENT); + dcMem.FillSolidRect (m_rcWork, m_clrBg); + + //ҦMarkrect + CPoint ptMarkTL (m_iWorkRight - MARK_WIDTH, m_iWorkTop); + CPoint ptMarkBR (m_iWorkRight, m_iWorkTop + MARK_HEIGHT); + CRect rcModeMark (ptMarkTL, ptMarkBR); + + //ҦMarkr + CFont fontModeMark, * pOldFont; + fontModeMark.CreatePointFont (MARK_FONTSIZE, _T ("Arial"), &dcMem); + + //ѦsIϤdcܤsdc + if (m_bBgPic) + dcMem.BitBlt (m_iWorkLeft, m_iWorkTop, m_rcWork.Width (), m_rcWork.Height (), &m_dcBgPic, 0, 0, SRCCOPY); + + //øsI + 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); + } + + //øswMark + 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); + } + + //øsBlocksu + for (int i = 0; i < m_iContainerSize; i++) + m_vcBlkContainer[i]->DrawLine (&dcMem); + + //øsBlock + 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ҦMarkPBlock + if (m_bSimulate) + { + //øsҦMark + pOldFont = dcMem.SelectObject (&fontModeMark); + dcMem.DrawText (_T ("Simulation"), -1, &rcModeMark, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + dcMem.SelectObject (pOldFont); + + //øsBlock + 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); + + //øssuҦMarkPsuuuq + if (m_bLineMode) + { + //øssuҦMar + pOldFont = dcMem.SelectObject (&fontModeMark); + dcMem.DrawText (_T ("LineMode"), -1, &rcModeMark, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + dcMem.SelectObject (pOldFont); + + //øssuuuq + if (m_bConnect) + { + CPen penBlack (PS_DASH, 1, BLACK); + CPen* pOldPen; + + pOldPen = dcMem.SelectObject (&penBlack); + + CPoint ptLStart = m_vcBlkContainer[m_iHeadBlkNum]->GetPinOutRect ().CenterPoint (); //uq_IBlockXPinI + int iCornerGridY = (int) (((ptLStart.y + m_ptLEnd.y) / 2. - m_iWorkTop) / m_iGridY + 0.5); //suBZu@ϤWXӮI + int iCornerY = iCornerGridY * m_iGridY + m_iWorkTop; //suBYy + 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); + } + } + + //ѤsdcܥDܲdc + dcSim.BitBlt (m_iWorkLeft, m_iWorkTop, m_rcWork.Width (), m_rcWork.Height (), &dcMem, m_iWorkLeft, m_iWorkTop, SRCCOPY); + + //Mz + dcMem.SelectObject (pOldBitmap); + bitmapMem.DeleteObject (); + dcMem.DeleteDC (); +} + +// ϥΪ̩즲̤pƵɡA +// tΩIsoӥ\oܡC +HCURSOR CTestSimulatorDlg::OnQueryDragIcon () +{ + return static_cast(m_hIcon); +} + +//UINs +void CTestSimulatorDlg::OnBnClickedButtonIn () +{ + m_bLineMode = FALSE; //suҦ + + CBlockBasis* pBlk = new CBlockIn; //new@CBlockIn + pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //]wBlock Inrect + pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //]wBlocks + m_vcBlkContainer.push_back (pBlk); //sJBlockvector + m_iContainerSize = (int) m_vcBlkContainer.size (); //Blockvector size + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); +} + +//UOUTs +void CTestSimulatorDlg::OnBnClickedButtonOut () +{ + m_bLineMode = FALSE; //suҦ + + CBlockBasis* pBlk = new CBlockOut; //new@CBlockOut + pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //]wBlock Outrect + pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //]wBlocks + m_vcBlkContainer.push_back (pBlk); //sJBlockvector + m_iContainerSize = (int) m_vcBlkContainer.size (); //Blockvector size + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); +} + +//UANDs +void CTestSimulatorDlg::OnBnClickedButtonAnd () +{ + m_bLineMode = FALSE; //suҦ + + CBlockBasis* pBlk = new CBlockAnd; //new@CBlockAnd + pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //]wBlock Andrect + pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //]wBlocks + m_vcBlkContainer.push_back (pBlk); //sJBlockvector + m_iContainerSize = (int) m_vcBlkContainer.size (); //Blockvector size + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); +} + +//UORs +void CTestSimulatorDlg::OnBnClickedButtonOr () +{ + m_bLineMode = FALSE; //suҦ + + CBlockBasis* pBlk = new CBlockOr; //new@CBlockOr + pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //]wBlock Orrect + pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //]wBlocks + m_vcBlkContainer.push_back (pBlk); //sJBlockvector + m_iContainerSize = (int) m_vcBlkContainer.size (); //Blockvector size + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); +} + +//UNOTs +void CTestSimulatorDlg::OnBnClickedButtonNot () +{ + m_bLineMode = FALSE; //suҦ + + CBlockBasis* pBlk = new CBlockNot; //new@CBlockNot + pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //]wBlock Notrect + pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //]wBlocks + m_vcBlkContainer.push_back (pBlk); //sJBlockvector + m_iContainerSize = (int) m_vcBlkContainer.size (); //Blockvector size + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); +} + +//UFunctions +void CTestSimulatorDlg::OnBnClickedButtonFunction () +{ + m_bLineMode = FALSE; //suҦ + + CBlockBasis* pBlk = new CBlockFun; //new@CBlockFun + pBlk->SetBlkRect (CPoint (m_rcWork.CenterPoint ().x, m_rcWork.CenterPoint ().y), m_iBlkWidth, m_iBlkHeight); //]wBlock Funrect + pBlk->SetBlkNum ((int) m_vcBlkContainer.size ()); //]wBlocks + m_vcBlkContainer.push_back (pBlk); //sJBlockvector + m_iContainerSize = (int) m_vcBlkContainer.size (); //Blockvector size + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); +} + +//ULines +void CTestSimulatorDlg::OnBnClickedButtonLine () +{ + //]wsuҦíøu@ + if (!m_bSimulate) + { + if (m_bLineMode) + m_bLineMode = FALSE; + else + { + if (!m_vcBlkContainer.empty ()) + { + m_bLineMode = TRUE; + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); + } + } + } +} + +//USimulates +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; //]wBlocks + m_bSimulate = TRUE; //]wҦ + m_bLineMode = FALSE; //suҦ + m_bDelBlk = FALSE; //TRBlock + + //YܪiܲХwOAhnew@ӥܪiܲ + 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); + } + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); + } + else + MessageBox (_T ("Please select output block and check if it is connected.")); + } +} + +//UGrids +void CTestSimulatorDlg::OnBnClickedButtonGrid () +{ + //]wIҦ + if (!m_bGrid) + m_bGrid = TRUE; + else + { + m_bGrid = FALSE; + m_bLock = FALSE; + } + + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); +} + +//ULocks +void CTestSimulatorDlg::OnBnClickedButtonLock () +{ + if (m_bGrid) + { + if (!m_bLock) + { + m_bLock = TRUE; //]wwҦ + + //]w{Blockw̬F񪺮IW + 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; + } + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); +} + +//UIϤs +void CTestSimulatorDlg::OnBnClickedButtonBgpic () +{ + //إCFileDialog (TRUE}ɮ, w]ɦW, lɮצW, OFN_HIDEREADONLY: , z) + CFileDialog fileDlg (TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, _T (" bitmap (*.bmp)|*.bmp||")); + + //YFileܲUTw + if (fileDlg.DoModal () == IDOK) + { + m_strPicPath = fileDlg.GetPathName (); //Ūɮ׸| + + //NŪ.bmpwHBITMAP + 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); + + //ȩ󭺦JϤɬlbitmap + if (!m_bBgPic) + m_pOldBitmap = m_dcBgPic.SelectObject (&m_bitmapBgPic); + else + m_dcBgPic.SelectObject (&m_bitmapBgPic); + + m_bBgPic = TRUE; + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); + } +} + +//UICs +void CTestSimulatorDlg::OnBnClickedButtonBgcolor () +{ + //إߦmܲ + CColorDialog clrDlg (m_clrBg, CC_PREVENTFULLOPEN); + + //YmܲUTw + if (clrDlg.DoModal () == IDOK) + { + if (m_bBgPic && m_pOldBitmap != NULL) + { + m_dcBgPic.SelectObject (m_pOldBitmap); + m_bBgPic = FALSE; + } + + m_clrBg = clrDlg.GetColor (); //]wIC + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); + } +} + +//UOpens +void CTestSimulatorDlg::OnBnClickedButtonOpen () +{ + //ҦUiiŪ + if (!m_bSimulate) + { + //إCFileDialog (TRUE}ɮ, w]ɦW, lɮצW, OFN_HIDEREADONLY: , z) + CFileDialog fileDlg (TRUE, _T ("txt"), NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, _T (" txt (*.txt)|*.txt||")); + + //إCStdioFileHŪɮ׸ + CStdioFile fileSim; + + //Yɮ׹ܲUTw + if (fileDlg.DoModal () == IDOK) + { + //}ɮ (ɮ׸|, CFile::modeNoTruncate: MŤ󤺮e | CFile::modeRead: Ū) + fileSim.Open (fileDlg.GetPathName (), CFile::modeNoTruncate | CFile::modeRead); + + CString strData; //xsC@Cr + CStringArray strArray; //xsC@BlockU + + fileSim.ReadString (strData); //Ūɮ׸ƶir + if (strData == "BlockData: ") //ƶ}YBlockDate + { + //Ūɮ׮ɨBlock + m_bSelectBlk = FALSE; + m_iSlctBlkNum = NO_SEL_NUM; + + //Mܪiܲ + if (m_pOscDlg != NULL) + { + m_pOscDlg->DestroyWindow (); + delete m_pOscDlg; + m_pOscDlg = NULL; + } + + //MsBlockvector + for (int i = 0; i < m_iContainerSize; i++) + delete m_vcBlkContainer[i]; + std::vector ().swap (m_vcBlkContainer); + + //CɮŪ@ + while (fileSim.ReadString (strData)) + { + SplitString (strData, ',', strArray); //NŪ쪺rjBlockUơAxsܰ}C + + if (strArray[0] == "IN") //Block InƤe]tIm, iflag + { + 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Ƥe]tIm, Jchannelƥ, JBlocks + { + 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Ƥe]tIm, JBlocks + { + 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Ƥe]tIm, JBlocks + { + 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Ƥe]tIm, JBlocks + { + 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Ƥe]tIm, JBlocks, B⤸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 (); + } + } + + //ŪAɮ + fileSim.Close (); + + //Ū쪺JBlocksAs]wC@BlocksBlock + 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]); + } + } + } + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); + } + else + fileSim.Close (); + } + } +} + +//USaves +void CTestSimulatorDlg::OnBnClickedButtonSave () +{ + //إCFileDialog (FALSExsɮ, w]ɦW, lɮצW, OFN_HIDEREADONLY: , z) + CFileDialog fileDlg (FALSE, _T ("txt"), _T ("Simulator"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T (" txt (*.txt)|*.txt||")); + + //إCStdioFileHxs + CStdioFile fileSim; + + //Yɮ׹ܲUTw + if (fileDlg.DoModal () == IDOK) + { + // }ɮ (ɮ׸|, CFile::modeCreate: Hsؤ覡} | CFile::modeWrite: ug) + fileSim.Open (fileDlg.GetPathName (), CFile::modeCreate | CFile::modeWrite); + + CString strData; //ΥHgJɮתr + 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 Inxse]tIm, iflag + 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 Outxse]tIm, Jchannelƥ, JBlocks + 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 Andxse]tIm, JBlocks + 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 Orxse]tIm, JBlocks + 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 Notxse]tIm, JBlocks + 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 Funxse]tIm, JBlocks, B⤸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); //NrꤺegJɮ + } + + fileSim.Close (); //gJAɮ + } +} + +//ƹU +void CTestSimulatorDlg::OnLButtonDown (UINT nFlags, CPoint ptCursor) +{ + SetCapture (); + + m_bDelBlk = FALSE; //ƹUɸTRBlock + + //P_ЬO_Block rectd + for (int i = m_iContainerSize - 1; i >= 0; i--) + { + if (m_vcBlkContainer[i]->GetBlkRect ().PtInRect (ptCursor)) + { + SetCursor (LoadCursor (NULL, IDC_SIZEALL)); + m_iSlctBlkNum = i; //Blocks + m_bSelectBlk = TRUE; + m_bMoveBlk = TRUE; + m_bLineMode = FALSE; //suҦ + break; + } + else //IDBlockmɡAаO + { + m_bSelectBlk = FALSE; + m_iSlctBlkNum = NO_SEL_NUM; + } + } + + //YBlockAߧYøu@ + if (m_bSelectBlk) + { + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); + } + + //suҦɡAP_ЫUmO_XPin}d + 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); +} + +//ƹ +void CTestSimulatorDlg::OnMouseMove (UINT nFlags, CPoint ptCursor) +{ + //ʿBlock + if (m_bMoveBlk) + { + //wҦUp⹫Цm̾F񤧮IANʪBlock߳]mӮIm + 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); + } + + //suҦ + if (m_bLineMode) + { + for (int i = 0; i < m_iContainerSize ; i++) + { + //оaBlockXPin}ɡA]wм˦QrbY + if (m_vcBlkContainer[i]->GetPinOutRect ().PtInRect (ptCursor)) + SetCursor (LoadCursor (NULL, IDC_CROSS)); + + //suɡA]wЦmuuq + if (m_bConnect) + m_ptLEnd = ptCursor; + } + } + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); + + CDialogEx::OnMouseMove (nFlags, ptCursor); +} + +//ƹ} +void CTestSimulatorDlg::OnLButtonUp (UINT nFlags, CPoint ptCursor) +{ + //BlockɡAiRBlock + if (m_bSelectBlk) + m_bDelBlk = TRUE; + + if (m_bMoveBlk) + { + //BlockAUAƹ}mWXu@ϡAh]wBlock^u@Ϥ + 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; + } + + //suҦU + if (m_bLineMode && m_bConnect) + { + //P_ƹ}mO_BlockJPin}dAYOAh]wBlocks_lBlock + 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; //ƹ}ɡAsuuq + } + + ReleaseCapture (); + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); + + CDialogEx::OnLButtonUp(nFlags, ptCursor); +} + +//ƹ +void CTestSimulatorDlg::OnLButtonDblClk (UINT nFlags, CPoint ptCursor) +{ + //ҦUiBlock 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) //Block InJiflag + { + 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) //Block FunB⤸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 (); //oϥΪ̳]wɶj(ms) + double dTime = m_iStep * iTimeInterval * MSEC; //i`ɶ(s) + + std::deque deqRowValue; //ΥHxsC@ӮɶIUUinput channel + + //eP_inputO_Xz(ȧP_@) + if (m_iStep == 0) + { + m_iOutSize = m_vcBlkContainer[m_iSimBlkNum]->GetBlkHeadSize (); //Ūchannelƥ + + for (int i = 0; i < m_iOutSize; i++) + { + int iValueFlag = m_vcBlkContainer[m_iSimBlkNum]->GetValueFlag (i); + + if (iValueFlag == NO_VALUE) //sbinput 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) //sb\B覡 + { + 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]wB⤸ + { + 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; + } + } + + //inputXzBA}l + if (m_pOscDlg->m_bSim) + { + if (m_iStep == 0) + { + m_pOscDlg->SetOutputSize (m_iOutSize); //]wܪiܲchannel + m_pOscDlg->InitialData (); //lƥܪiܲ(channelƥ, He) + m_deq2DOutputValue.clear (); //}leMŤGx} + } + + //]wӮɶUAC@Block In + 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); + } + } + + //oBlock Out(hchannel) + for (int i = 0; i < m_iOutSize; i++) + { + double dValue = m_vcBlkContainer[m_iSimBlkNum]->GetBlkValue (i); + deqRowValue.push_back (dValue); //sJCVq(ӮɶIUC@input channel) + } + + int iDataSize = (int) m_deq2DOutputValue.size (); //Ū`dataƥ + + //Y`dataƥضWLw]̤jdataơARĤ@dataAåѥݥ[Jsdata + if (iDataSize < MAX_DATA_NUM) + m_deq2DOutputValue.push_back (deqRowValue); + else + { + m_deq2DOutputValue.pop_front (); + m_deq2DOutputValue.push_back (deqRowValue); + } + + //FFTDYWv + double dOutFreq = 0.; + if (iDataSize == MAX_DATA_NUM /*&& m_pOscDlg->m_bFFT*/) + { + std::deque 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); + } + + //ǭȦܥܪiܲ(eɶ, output value, Wv) + m_pOscDlg->SetData(dTime, deqRowValue[m_pOscDlg->m_iSlctOutputNum], dOutFreq); + //m_pOscDlg->SetData (dTime, deqRowValue[m_pOscDlg->m_iSlctOutputNum]); + + m_iStep++; + + //sܪiܲ + 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); +} + +//Dܲjp +void CTestSimulatorDlg::OnSize (UINT nType, int cx, int cy) +{ + CDialogEx::OnSize(nType, cx, cy); + + //ͦDܲɤiJ + if (m_bInitDlg) + { + //P_O_̤p + if (!IsIconic ()) + { + //oDܲȤ + CRect rcCurClient; + this->GetClientRect (&rcCurClient); + + //px, yVY + 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 (); + + //]wsu@ϰ + 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); + + //]wsmPjp + 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); + + //sJIϤ + 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); + } + + //]wsBlockmPjp + 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); + + //øu@ + Invalidate (TRUE); + UpdateWindow (); + + //YsbܪiܲAhܵ + if (m_bSimulate && m_pOscDlg != NULL) + m_pOscDlg->ShowWindow (SW_SHOW); + } + } +} + +BOOL CTestSimulatorDlg::PreTranslateMessage (MSG* pMsg) +{ + if (pMsg->message == WM_KEYDOWN) + { + //UR + if (pMsg->wParam == VK_DELETE && !m_vcBlkContainer.empty () && m_bDelBlk && !m_bSimulate) + { + //P_LBlockO_sܸӧRBlockAYAhMs + 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); + } + } + } + } + + //MBlock + delete m_vcBlkContainer[m_iSlctBlkNum]; + + m_vcBlkContainer.erase (m_vcBlkContainer.begin () + m_iSlctBlkNum); + m_iContainerSize = (int) m_vcBlkContainer.size (); + + //ss + for (int i = 0; i < m_iContainerSize; i++) + m_vcBlkContainer[i]->SetBlkNum (i); + + //s]wss + 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); + } + } + } + + //RA + m_bSelectBlk = FALSE; + m_iSlctBlkNum = NO_SEL_NUM; + m_bDelBlk = FALSE; + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); + } + //UESC + 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; + + //øu@ + InvalidateRect (m_rcWork, FALSE); + UpdateWindow (); + + return TRUE; + } + //UENTER + else if (pMsg->wParam == VK_RETURN) + return TRUE; + } + + return CDialogEx::PreTranslateMessage(pMsg); +} + +void CTestSimulatorDlg::OnDestroy () +{ + CString strIniPath (_T (".\\Initial.ini")); //.ini| + CString strAppName (_T ("BgParameter")); //.ini[`W] + CString strColorRef; //Cܼ + strColorRef.Format (_T ("%u"), m_clrBg); //NCରr + + //IT + CString strKeyName (_T ("BgPicBOOL")); //.iniܼƦW + if (m_bBgPic) + { + WritePrivateProfileString (strAppName, strKeyName, _T ("TRUE"), strIniPath); //JIϤ + strKeyName.Format (_T ("BgPicPath")); + WritePrivateProfileString (strAppName, strKeyName, m_strPicPath, strIniPath); //IϤ| + strKeyName.Format (_T ("BgColor")); + WritePrivateProfileString (strAppName, strKeyName, _T ("None"), strIniPath); //IC⬰None + } + else + { + WritePrivateProfileString (strAppName, strKeyName, _T ("FALSE"), strIniPath); //JIϤ + strKeyName.Format (_T ("BgPicPath")); + WritePrivateProfileString (strAppName, strKeyName, _T ("None"), strIniPath); //IϤ|None + strKeyName.Format (_T ("BgColor")); + WritePrivateProfileString (strAppName, strKeyName, strColorRef, strIniPath); //IC + } + + //I}һP_ + strKeyName.Format (_T ("GridBOOL")); + if (m_bGrid) + WritePrivateProfileString (strAppName, strKeyName, _T ("TRUE"), strIniPath); + else + WritePrivateProfileString (strAppName, strKeyName, _T ("FALSE"), strIniPath); + + //w}һP_ + strKeyName.Format (_T ("LockBOOL")); + if (m_bLock) + WritePrivateProfileString (strAppName, strKeyName, _T ("TRUE"), strIniPath); + else + WritePrivateProfileString (strAppName, strKeyName, _T ("FALSE"), strIniPath); + + //MsIϤdc + m_dcBgPic.SelectObject (m_pOldBitmap); + m_dcBgPic.DeleteDC (); + + //Mܪiܲ + if (m_pOscDlg != NULL) + { + m_pOscDlg->DestroyWindow (); + delete m_pOscDlg; + } + + //MBlock vector + for (int i = 0; i < m_iContainerSize; i++) + delete m_vcBlkContainer[i]; + + CDialogEx::OnDestroy(); +} + +//N@Cr̾ڤjŸάWߦr +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); +} + +//s]wmΤjp +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); +} + +//s]wBlockmΤjp +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); +} + +//pdatah(Ω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; + } +} + +//FFTDYWv +double CTestSimulatorDlg::FFT (const std::deque & deq2dData, int iSize, double dUnitTime) +{ + std::deque deqFData; + std::deque deqWeights; + std::deque deqX; + std::deque 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; + + //pvǦ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)); + + //p˧Ǧ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]); + } + + //pFFT + for (int L = 1; L <= iLayers; L++) + { + int iDistance = 1 << (L - 1); + int iW = 1 << (iLayers - L); //`ƪ׳QѪ + + int iB = iDeqLen >> L; //ݭpXƪ׬iNť߸ഫ + int iN = iDeqLen / iB; //ݭpť߸ഫƪ + + 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; + } + + //p⮶T + for (int i = 0; i < iDeqLen; i++) + deqAmplitude.push_back (deqFData[i].ComputeAmplitude ()); + + double dMaxAmp = 0.; //ŧi̤jTܼ + double dCornerFreq = 1 / dUnitTime / 2; //pIWv + double dOutFreq = 0.; //̤j֥X{Wv + + //W줤X{̤jTmAWvYXWv + 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; +} \ No newline at end of file diff --git a/TestSimulator/TestSimulatorDlg.h b/TestSimulator/TestSimulatorDlg.h new file mode 100644 index 0000000..6dabef0 --- /dev/null +++ b/TestSimulator/TestSimulatorDlg.h @@ -0,0 +1,116 @@ + +// TestSimulatorDlg.h : Y +// + +#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 +#include + + +// CTestSimulatorDlg ܤ +class CTestSimulatorDlg : public CDialogEx +{ +// غc +public: + CTestSimulatorDlg(CWnd* pParent = NULL); // зǫغc禡 + +// ܤ + enum { IDD = IDD_TESTSIMULATOR_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 䴩 + +private: + std::vector m_vcBlkContainer; //s񤣦PBlockvector + + CRect m_rcWork; //u@ + CRect m_rcClient; //ܲȤ + CPoint m_ptLEnd; //suuqI + COscDlg* m_pOscDlg; //ܪiܲ + CDC m_dcBgPic; //sIϤdc + CBitmap m_bitmapBgPic; //sIϤbitmap + CBitmap* m_pOldBitmap; //Vbitmap + CString m_strPicPath; //IϤ| + COLORREF m_clrBg; //IC + + BOOL m_bInitDlg; //P_ܵl + BOOL m_bSelectBlk; //P_Block + BOOL m_bMoveBlk; //P_Block + BOOL m_bLineMode; //P_euҦ + BOOL m_bConnect; //P_su + BOOL m_bDelBlk; //P_BlockR + BOOL m_bBgPic; //P_JIϤ + BOOL m_bGrid; //P_I + BOOL m_bLock; //P_wI + + int m_iWorkLeft; //u@ϥy + int m_iWorkTop; //u@ϤWy + int m_iWorkRight; //u@ϥky + int m_iWorkBottom; //u@ϤUy + int m_iBlkWidth; //Blocke + int m_iBlkHeight; //Block + int m_iGridX; //XVIj + int m_iGridY; //YVIj + int m_iContainerSize; //sBlockvectorjp + int m_iSlctBlkNum; //Blocks + int m_iHeadBlkNum; //sBlocks + int m_iSimBlkNum; //Blocks + int m_iOutSize; //Blockchannelƥ + +// {X@ +protected: + HICON m_hIcon; + + // ͪT禡 + 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 > m_deq2DOutputValue; //soutput valuedeque + BOOL m_bSimulate; //P_Ҧ + int m_iStep; //iB + + 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 &, int, double); +}; diff --git a/TestSimulator/res/TestSimulator.ico b/TestSimulator/res/TestSimulator.ico new file mode 100644 index 0000000..d56fbcd Binary files /dev/null and b/TestSimulator/res/TestSimulator.ico differ diff --git a/TestSimulator/res/TestSimulator.rc2 b/TestSimulator/res/TestSimulator.rc2 new file mode 100644 index 0000000..1770830 Binary files /dev/null and b/TestSimulator/res/TestSimulator.rc2 differ diff --git a/TestSimulator/resource.h b/TestSimulator/resource.h new file mode 100644 index 0000000..e442f48 Binary files /dev/null and b/TestSimulator/resource.h differ diff --git a/TestSimulator/stdafx.cpp b/TestSimulator/stdafx.cpp new file mode 100644 index 0000000..d10ef63 --- /dev/null +++ b/TestSimulator/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : ȥ]tз Include ɪl{ +// TestSimulator.pch |sĶY +// stdafx.obj |]tsĶOT + +#include "stdafx.h" + + diff --git a/TestSimulator/stdafx.h b/TestSimulator/stdafx.h new file mode 100644 index 0000000..e25c3ed --- /dev/null +++ b/TestSimulator/stdafx.h @@ -0,0 +1,54 @@ + +// stdafx.h : ibYɤ]tзǪt Include ɡA +// άOg`ϥΫoܤܧ +// MױM Include ɮ + +#pragma once + +#ifndef VC_EXTRALEAN +#define VC_EXTRALEAN // q Windows Yư`ϥΪ +#endif + +#include "targetver.h" + +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // Twq CString غc禡 + +// MFC ä@DZ`ΥiĵiT\ +#define _AFX_ALL_WARNINGS + +#include // MFC ֤߻PзǤ +#include // MFC XR\ + + +#include // MFC Automation O + + + +#ifndef _AFX_NO_OLE_SUPPORT +#include // MFC 䴩 Internet Explorer 4 qα +#endif +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC 䴩 Windows qα +#endif // _AFX_NO_AFXCMN_SUPPORT + +#include // \ϩMC 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 + + diff --git a/TestSimulator/targetver.h b/TestSimulator/targetver.h new file mode 100644 index 0000000..b7ae53c --- /dev/null +++ b/TestSimulator/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// [W SDKDDKVer.h iwq̰iΪ Windows xC + +// pGnwe Windows xظmε{AХ[W WinSDKVer.hA +// æb[W SDKDDKVer.h eN _WIN32_WINNT ]n䴩xC + +#include