📄 xreducetestdlg.cpp
字号:
else{
for( j = 1 ; j <= 4; j++ )
if( lno[j] ) break;
rect = rectBlock;
pt.y = dh*(j-1); pt.x = dw*(line-1);
rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x = center.x + 10; center.x -= 10;
dc->Arc( &rect,pt,center );
rect = rectBlock;
pt.y = dh*(j + count - 2); pt.x = dw*(line-1);
rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x = center.x + 10; center.x -= 10;
dc->Arc( &rect,center,pt );
//画直线
dc->MoveTo( rectBlock.left + dw*(line-1),rectBlock.top + dh*(j-1) + dh/2 );
dc->LineTo( rectBlock.left + dw*(line-1),rectBlock.top + dh*(j+count-2) + dh/2 );
dc->MoveTo( rectBlock.left + dw*line,rectBlock.top + dh*(j-1) + dh/2 );
dc->LineTo( rectBlock.left + dw*line,rectBlock.top + dh*(j+count-2) + dh/2 );
}
}
//选中两行
else if( 2 == lno_count ){
int array2;
for( line = 1 ; line <= 4; line++ )
if( lno[line] ) break;
for( array = 1 ; array <= 4; array++ )
if( ano[array] ) break;
for( array2 = 4 ; array2 >= 1; array2-- )
if( ano[array2] ) break;
//不相临列,只有可能:2个选择项,同时分布在1,4列
if( (ano_count == 2) && (ano[1]&&ano[4]) && (lno[1]&&lno[4]) ){//四个角
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = -dw; pt.y = -dh; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x = center.x + 10; center.y += 10;
dc->Arc( &rect,center,pt );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = 3*dw; pt.y = -dh; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x -= 10; center.y += 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = -dw; pt.y =3*dh; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x += 10; center.y -= 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = 3*dw; pt.y =3*dh; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.y -= 10; center.x -= 10;
dc->Arc( &rect,pt,center );
}
else if( (ano_count == 2) && (ano[1]&&ano[4]) ){//左右两边
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = -dw; pt.y = (line-1)*dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.y += 10; center.y -= 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = 3*dw; pt.y = (line-1)*dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.y -= 10; center.y += 10;
dc->Arc( &rect,pt,center );
}
else if( lno[1]&&lno[4] ){//上下两头
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = (array-1)*dw; pt.y = -dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x -= 10; center.y += 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = (array2-2)*dw; pt.y = -dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.y += 10; center.x += 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x =(array-1)*dw; pt.y = 3*dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.y -= 10; center.x -= 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x =(array2-2)*dw; pt.y = 3*dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x += 10; center.y -= 10;
dc->Arc( &rect,pt,center );
//画直线
dc->MoveTo( rectBlock.right + dw*(array-1),rectBlock.bottom );
dc->LineTo( rectBlock.left + dw*(array2-1),rectBlock.bottom );
dc->MoveTo( rectBlock.right + dw*(array-1),rectBlock.top + dh*3 );
dc->LineTo( rectBlock.left + dw*(array2-1),rectBlock.top + dh*3 );
}
else{//闭合图形
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = (array-1)*dw; pt.y = (line-1)*dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.y -= 10; center.y += 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = (array2-2)*dw; pt.y = (line-1)*dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.y += 10; center.y -= 10;
dc->Arc( &rect,pt,center );
//画直线
dc->MoveTo( rectBlock.right + dw*(array-1),rectBlock.top + dh*(line-1) );
dc->LineTo( rectBlock.left + dw*(array2-1),rectBlock.top + dh*(line-1) );
dc->MoveTo( rectBlock.right + dw*(array-1),rectBlock.top + dh*(line+1) );
dc->LineTo( rectBlock.left + dw*(array2-1),rectBlock.top + dh*(line+1) );
}
}
else{
for( array = 1 ; array <= 4; array++ )
if( ano[array] ) break;
//不相临列,只有可能:2个选择项,同时分布在1,4列
if( ano[1]&&ano[4] ){//左右两列
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = -dw; pt.y = 0 ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x += 10; center.y -= 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = -dw; pt.y = 2*dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.y += 10; center.x += 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = 3*dw; pt.y = 0 ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.y -= 10; center.x -= 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = 3*dw; pt.y = 2*dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x -= 10; center.y += 10;
dc->Arc( &rect,pt,center );
}
else{
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = (array-1)*dw; pt.y = 0 ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x += 10; center.x -= 10;
dc->Arc( &rect,pt,center );
rect = rectBlock; rect.right += dw; rect.bottom += dh; pt.x = (array-1)*dw; pt.y = 2*dh ; rect += pt;
center = rect.CenterPoint(); pt = center;
pt.x -= 10; center.x += 10;
dc->Arc( &rect,pt,center );
//画直线
dc->MoveTo( rectBlock.left + dw*(array-1),rectBlock.bottom );
dc->LineTo( rectBlock.left + dw*(array-1),rectBlock.bottom + dh*2 );
dc->MoveTo( rectBlock.right + dw*array,rectBlock.bottom );
dc->LineTo( rectBlock.right + dw*array,rectBlock.bottom + dh*2 );
}
}
}
//清除化简过程
void XReduceTestDlg::OnBnClickedButton5()
{
if( timer_on ) return;
tabSelfReducing.Init();
intProcessState = 2;
InvalidateRect(NULL);
}
//化简结束
void XReduceTestDlg::OnBnClickedButton6()
{
if( intProcessState != 2 ) return;
//检查确保所有的项都已包含
if( !tabSelfReducing.CheckAll( intTabValue ) ){
AfxMessageBox( "还有最小项没有化简" );
return;
}
//进入下一个步骤
intProcessState = 3;//用户已化简完毕
}
//显示用户化简过程以及化简结果
void XReduceTestDlg::OnBnClickedButton7()
{
if( timer_on ) return;
OnBnClickedButton6();
if( 3 != intProcessState ) return;
old_state = intProcessState;
intProcessState = 4;
curProcess = 0;
m_timer = SetTimer( 10,1000,NULL );
timer_on = true;
InvalidateRect(NULL);
//csReduceResult
}
void XReduceTestDlg::DrawSelfReduingProcess(CDC * dc)
{
//若变量还未确定,则不显示具体数值,此时显示没有意义
//if( intProcessState != 4 ) return;
XTabDataManager tabSelfReducing_t;
bool auto_red = false;
if( (intProcessState == 4) || (intProcessState == 5) )
tabSelfReducing_t = tabSelfReducing;
else if( intProcessState == 10 ){
tabSelfReducing_t = tabAutoReducing[cur_autonum];
auto_red = true;
}
CRect rect,rectBlock = rectDrawArea;
CPoint pt;
rectBlock.DeflateRect( 40,40,0,0 );
int dw = rectBlock.Width() / 4;
int lnum = (intValNum - 2)*2;
int dh = rectBlock.Height() / lnum;
int Pos[17][2] = { {1,1},{1,2},{1,4},{1,3},//(行,列)
{2,1},{2,2},{2,4},{2,3},
{4,1},{4,2},{4,4,},{4,3},
{3,1},{3,2},{3,4},{3,3} };
//把已经化简好,用框化出
int line_idx,count;
int data[17];
COLORREF p_col[] = {
RGB(255,0,0), RGB(0,128,0) , RGB(0,128,128), RGB(0,0,255),RGB(128,0,128),
RGB(255,128,64), RGB(255,0,255),RGB(128,128,64),RGB(255,0,128) ,RGB(0,128,255) , RGB(128,0,255),RGB(00,255,0),RGB(128,128,128)
};
CPen * pen;//
CPen * old_pen;
CBrush * brush;//
CBrush * old_brush;
CBitmap res;
int maskbit;
UINT bmpIDY = IDB_Y;
UINT bmpADD = IDB_ADD;
UINT bmpID[] = { IDB_A,IDB_B,IDB_C,IDB_D };
UINT bmpIDINV[] = { IDB_AINV,IDB_BINV,IDB_CINV,IDB_DINV };
UINT bmpIDORDER[] = { IDB_0,IDB_1,IDB_2,IDB_3,IDB_4,IDB_5,IDB_6,IDB_7,IDB_8,IDB_9 };
UINT bmpIDdot = IDB_DOT;
int bmph = 25, bmpw = 19;
CDC mem_dc;
mem_dc.CreateCompatibleDC( dc );
int px = 50 ,py = 340;
CBitmap * old_bmp;
//每次显示一行和以前行
mem_dc.SetROP2(R2_MERGEPEN);
if( auto_red ){//显示总共自动 3/4
//获取cur_autonum的位数
int bit_num = (int)log10(cur_autonum) + 1;
int bit10 = (int)pow( 10,bit_num-1);
int num = cur_autonum/bit10;
int leftnum = cur_autonum%bit10;
for( int i = 1; i <= bit_num; i++ ){
//取其中的一位
//py += bmph;
res.LoadBitmap( bmpIDORDER[num] );
old_bmp = mem_dc.SelectObject( &res );
res.DeleteObject();
dc->BitBlt( px,py,bmpw/2,bmph,&mem_dc,0,0,SRCCOPY );
px += bmpw/2;
if( i < bit_num ){
bit10 /= 10;
num = leftnum/bit10;
leftnum = leftnum%bit10;
}
}
res.LoadBitmap( bmpIDdot );
old_bmp = mem_dc.SelectObject( &res );
res.DeleteObject();
dc->BitBlt( px,py,bmpw/2,bmph,&mem_dc,0,0,SRCCOPY );
px += bmpw/2;
bit_num = (int)log10(autonum) + 1;
bit10 = pow( 10,bit_num-1);
num = autonum/bit10;
leftnum = autonum%bit10;
for( int i = 1; i <= bit_num; i++ ){
//取其中的一位
res.LoadBitmap( bmpIDORDER[num] );
old_bmp = mem_dc.SelectObject( &res );
res.DeleteObject();
dc->BitBlt( px,py,bmpw/2,bmph,&mem_dc,0,0,SRCCOPY );
px += bmpw/2;
if( i < bit_num ){
bit10 /= 10;
num = leftnum/bit10;
leftnum = leftnum%bit10;
}
}
//py += bmph;
}
res.LoadBitmap( bmpIDY );
old_bmp = mem_dc.SelectObject( &res );
res.DeleteObject();
dc->BitBlt( px,py,bmpw*2,bmph,&mem_dc,0,0,SRCCOPY );
px += bmpw*2;
for( line_idx = 0 ; line_idx <= curProcess; line_idx++ ){
//取出一行
tabSelfReducing_t.GetThisLine( line_idx,data, count );
pen = new CPen(PS_SOLID,3,p_col[line_idx%13] );
old_pen = dc->SelectObject( pen );
DrawThisBlock( dc, data, count );
dc->SelectObject( old_pen );
delete pen;
//获取化简结果 data[0]
tabSelfReducing_t.GetThisLineRes( line_idx , count, maskbit );
for( int i = intValNum-1,j=0; i >= 0 ; i--,j++ ) {
if( maskbit & ( 0x1<<i ) ){
if( data[0] & ( 0x1<<i ) )
res.LoadBitmap( bmpID[j] );
else
res.LoadBitmap( bmpIDINV[j] );
//mem_dc.SelectObject( old_bmp );
mem_dc.SelectObject( &res );
brush = new CBrush( p_col[line_idx%13] );
old_brush = mem_dc.SelectObject( brush );
mem_dc.Rectangle( 0,0,2*bmpw,bmph );
mem_dc.SelectObject( old_brush );
delete brush;
res.DeleteObject();
//dc->BitBlt( px,py,bmpw*2,bmph,&mem_dc,0,0,SRCCOPY );
dc->StretchBlt( px,py,bmpw/2,bmph,&mem_dc,0,0,bmpw,bmph,SRCCOPY );
px += bmpw/2;
}
}
if( line_idx != curProcess ){
res.LoadBitmap( IDB_ADD );
mem_dc.SelectObject( &res );
res.DeleteObject();
//dc->BitBlt( px,py,bmpw*2,bmph,&mem_dc,0,0,SRCCOPY );
dc->StretchBlt( px,py,bmpw/2,bmph,&mem_dc,0,0,bmpw,bmph,SRCCOPY );
px += bmpw/2;
}
//显示手工化简是否合理
if( !auto_red && (tabSelfReducing_t.intCurIndex-1 == curProcess) ){
bool right = CheckReduceOK();
if( right ){
res.LoadBitmap( IDB_RIGHT );
mem_dc.SelectObject( &res );
res.DeleteObject();
dc->BitBlt( px,py,bmpw*2,bmph,&mem_dc,0,0,SRCCOPY );
//dc->StretchBlt( px,py,bmpw/2,bmph,&mem_dc,0,0,bmpw,bmph,SRCCOPY );
}
else{
res.LoadBitmap( IDB_WRONG );
mem_dc.SelectObject( &res );
res.DeleteObject();
dc->BitBlt( px,py,bmpw*2,bmph,&mem_dc,0,0,SRCCOPY );
//dc->StretchBlt( px,py,bmpw/2,bmph,&mem_dc,0,0,bmpw,bmph,SRCCOPY );
}
}
}
}
void XReduceTestDlg::OnTimer( UINT )
{
curProcess++;
if( (intProcessState == 4) && (curProcess >= tabSelfReducing.intCurIndex) ){
intProcessState = old_state;
KillTimer( m_timer );
timer_on = false;
}
else if( (intProcessState == 10) && (curProcess >= tabAutoReducing[cur_autonum].intCurIndex) ){
intProcessState = old_state;
KillTimer( m_timer );
timer_on = false;
}
else
InvalidateRect(NULL);
}
//分析化简过程
void XReduceTestDlg::OnBnClickedButton8()
{
if( 3 != intProcessState ) return;
intProcessState = 5;
curProcess = -1;
InvalidateRect(NULL);
}
//前一步
void XReduceTestDlg::OnBnClickedButton11()
{
if( 5 != intProcessState ) return;
curProcess--;
if( curProcess < -1 ){
curProcess = -1;
return;
}
InvalidateRect(NULL);
}
//后一步
void XReduceTestDlg::OnBnClickedButton12()
{
if( 5 != intProcessState ) return;
curProcess++;
if( curProcess < tabSelfReducing.intCurIndex )
InvalidateRect( NULL );
else
curProcess--;
}
//根据自动结果,显示自动化简步骤
void XReduceTestDlg::OnBnClickedButton9()
{
// if( 3 != intProcessState ) return;
if( timer_on ) return;//如果正在显示化简过程,
if( intProcessState < 2 ) return;//还没有进行填充
old_state = intProcessState;
intProcessState = 10;
curProcess = 0;
cur_autonum++;
if( cur_autonum > autonum )
cur_autonum = 1;
m_timer = SetTimer( 10,1000,NULL );
timer_on = true;
InvalidateRect(NULL);
}
void XReduceTestDlg::OnBnClickedButton13()
{
if( timer_on ) return;
intProcessState = 1;//正在填充卡诺图
//重新绘制卡诺图框
this->InvalidateRect( NULL );
}
//
bool XReduceTestDlg::CheckReduceOK()
{
for( int i = 1 ; i <= autonum; i++ ){
if( tabAutoReducing[i] == tabSelfReducing ){
cur_autonum = i-1;
return true;
}
}
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -