164 lines
4.6 KiB
C++
164 lines
4.6 KiB
C++
|
#include "stdafx.h"
|
|||
|
|
|||
|
#include "BlockNot.h"
|
|||
|
|
|||
|
#define PIN_RADIUS 8 //Pin<69>b<EFBFBD>|
|
|||
|
|
|||
|
#define GOLD RGB (255, 215, 0) //Pin<69>}<7D>C<EFBFBD><43>
|
|||
|
#define BLACK RGB (0, 0, 0) //<2F>s<EFBFBD>u<EFBFBD>C<EFBFBD><43>
|
|||
|
|
|||
|
#define NO_VALUE -10 //<2F><><EFBFBD>s<EFBFBD>b<EFBFBD><62><EFBFBD>J<EFBFBD>T<EFBFBD><54>
|
|||
|
#define NO_OPER_FLAG -11 //<2F><><EFBFBD>s<EFBFBD>b<EFBFBD>B<EFBFBD>⤸
|
|||
|
#define COMPUTE_ERROR -13 //<2F><><EFBFBD><EFBFBD><EFBFBD>\<5C><><EFBFBD>B<EFBFBD><42>
|
|||
|
#define NO_BLOCK_HEAD -14 //<2F><><EFBFBD>s<EFBFBD>b<EFBFBD>s<EFBFBD><73>Block
|
|||
|
|
|||
|
#define TOLERANCE 0.001 //<2F>e<EFBFBD>Ի~<7E>t<EFBFBD><74>
|
|||
|
|
|||
|
#define DIGITAL_VALUE 4 //<2F>Ʀ<EFBFBD><C6A6>T<EFBFBD><54>flag
|
|||
|
#define ANALOG_VALUE 5 //<2F><><EFBFBD><EFBFBD><EFBFBD>T<EFBFBD><54>flag
|
|||
|
|
|||
|
#define BLK_NOT 5 //Block<63><6B><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD><73>
|
|||
|
|
|||
|
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<6F><EFBFBD> (<28>Y<EFBFBD><59><EFBFBD>J<EFBFBD><4A>0<EFBFBD>A<EFBFBD>h<EFBFBD>^<5E><>1<EFBFBD>A<EFBFBD>Ϥ<EFBFBD><CFA4>^<5E><>0)
|
|||
|
if (m_pBlkHead->GetBlkValue () < TOLERANCE)
|
|||
|
return 1.;
|
|||
|
else
|
|||
|
return 0.;
|
|||
|
}
|
|||
|
|
|||
|
int CBlockNot::GetValueFlag () const
|
|||
|
{
|
|||
|
if (m_pBlkHead == NULL) //<2F>Y<EFBFBD><59><EFBFBD>J<EFBFBD><4A><EFBFBD>I<EFBFBD><49><EFBFBD>s<EFBFBD><73><EFBFBD>A<EFBFBD>^<5E><>"<22>L<EFBFBD><4C>"
|
|||
|
return NO_VALUE;
|
|||
|
else if (m_pBlkHead->GetValueFlag () == NO_VALUE) //<2F>Y<EFBFBD><59><EFBFBD>J<EFBFBD><4A><EFBFBD>L<EFBFBD>ȡA<C8A1>^<5E><>"<22>L<EFBFBD><4C>"
|
|||
|
return NO_VALUE;
|
|||
|
else if (m_pBlkHead->GetValueFlag () == COMPUTE_ERROR) //<2F>Y<EFBFBD><59><EFBFBD>J<EFBFBD><4A><EFBFBD>p<EFBFBD><70><EFBFBD><EFBFBD><EFBFBD>~<7E>A<EFBFBD>^<5E><>"<22>p<EFBFBD><70><EFBFBD><EFBFBD><EFBFBD>~"
|
|||
|
return COMPUTE_ERROR;
|
|||
|
else if (m_pBlkHead->GetValueFlag () == ANALOG_VALUE) //<2F><><EFBFBD><EFBFBD><EFBFBD>\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>J
|
|||
|
return COMPUTE_ERROR;
|
|||
|
else if (m_pBlkHead->GetValueFlag () == NO_OPER_FLAG) //<2F><><EFBFBD>]<5D>w<EFBFBD>B<EFBFBD>⤸
|
|||
|
return NO_OPER_FLAG;
|
|||
|
else if (m_pBlkHead->GetValueFlag () == DIGITAL_VALUE) //<2F>Y<EFBFBD><59><EFBFBD>J<EFBFBD><4A><EFBFBD>Ʀ<EFBFBD><C6A6>T<EFBFBD><54><EFBFBD>A<EFBFBD>h<EFBFBD>^<5E>ǼƦ<C7BC><C6A6>T<EFBFBD><54>
|
|||
|
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 (); //<2F>s<EFBFBD>u<EFBFBD>_<EFBFBD>I<EFBFBD><49><EFBFBD><EFBFBD><EFBFBD>JBlock<63><6B><EFBFBD><EFBFBD><EFBFBD>XPin<69>}<7D><><EFBFBD><EFBFBD><EFBFBD>I
|
|||
|
CPoint ptEnd = m_rcPinIn.CenterPoint (); //<2F>s<EFBFBD>u<EFBFBD><75><EFBFBD>I<EFBFBD><49><EFBFBD><EFBFBD>Block<63><6B><EFBFBD><EFBFBD><EFBFBD>JPin<69>}<7D><><EFBFBD><EFBFBD><EFBFBD>I
|
|||
|
int iGrid = (int) (m_rcBlk.Height () / 2. + 0.5); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>j
|
|||
|
int iCornerGridY = (int) (((ptStart.y + ptEnd.y) / 2. - ptStart.y) / iGrid + 0.5); //<2F>p<EFBFBD><70><EFBFBD>s<EFBFBD>u<EFBFBD><75><EFBFBD><EFBFBD><EFBFBD>B<EFBFBD>Z<EFBFBD><5A><EFBFBD><EFBFBD><EFBFBD>JBlock<63>X<EFBFBD>ӹj<D3B9>I
|
|||
|
int iCornerY = iCornerGridY * iGrid + ptStart.y; //<2F>s<EFBFBD>u<EFBFBD><75><EFBFBD><EFBFBD><EFBFBD>BY<42>y<EFBFBD>Ц<EFBFBD><D0A6>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;
|
|||
|
}
|