⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pinouts.cpp

📁 Source code for cnc controlling three dimentioal machine
💻 CPP
字号:
// pinouts.cpp : implementation file
//

#include "stdafx.h"
#include "mastercontrol.h"
#include "pinouts.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// pinouts property page

IMPLEMENT_DYNCREATE(pinouts, CPropertyPage)

pinouts::pinouts() : CPropertyPage(pinouts::IDD)
{
	//{{AFX_DATA_INIT(pinouts)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	Function = 0;
	 
	//CString buffer;
	// load registry defaults here;
	//buffer = AfxGetApp( )->GetProfileString("Preferences", "Pins2Functions" , "1,2,3,4,5,6,7,8" );
 	 
	LPT1 = AfxGetApp( )->GetProfileInt("Preferences", "LPT1" , 1 ) != 0; 
	LPT2 = AfxGetApp( )->GetProfileInt("Preferences", "LPT2" , 0 ) != 0;
	LPT3 = AfxGetApp( )->GetProfileInt("Preferences", "LPT3" , 0 ) != 0;
	LPT4 = AfxGetApp( )->GetProfileInt("Preferences", "LPT4" , 0 ) != 0;
	IO48 = AfxGetApp( )->GetProfileInt("Preferences", "IO48" , 0 ) != 0;
	Pins[0] = AfxGetApp( )->GetProfileInt("Preferences", "Pin2" , 1 );
	Pins[1] = AfxGetApp( )->GetProfileInt("Preferences", "Pin3" , 2 );
	Pins[2] = AfxGetApp( )->GetProfileInt("Preferences", "Pin4" , 3 );
    Pins[3] = AfxGetApp( )->GetProfileInt("Preferences", "Pin5" , 4 );
    Pins[4] = AfxGetApp( )->GetProfileInt("Preferences", "Pin6" , 5 );
    Pins[5] = AfxGetApp( )->GetProfileInt("Preferences", "Pin7" , 6 );
    Pins[6] = AfxGetApp( )->GetProfileInt("Preferences", "Pin8" , 7 );
    Pins[7] = AfxGetApp( )->GetProfileInt("Preferences", "Pin9" , 8 );

}

pinouts::~pinouts()
{
}

void pinouts::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(pinouts)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(pinouts, CPropertyPage)
	//{{AFX_MSG_MAP(pinouts)
	ON_BN_CLICKED(IDC_EIGHT, OnEight)
	ON_BN_CLICKED(IDC_EMERG, OnEmerg)
	ON_BN_CLICKED(IDC_FIVE, OnFive)
	ON_BN_CLICKED(IDC_FOUR, OnFour)
	ON_BN_CLICKED(IDC_IOBOARD, OnIoboard)
	ON_BN_CLICKED(IDC_LPT1, OnLpt1)
	ON_BN_CLICKED(IDC_LPT2, OnLpt2)
	ON_BN_CLICKED(IDC_LPT3, OnLpt3)
	ON_BN_CLICKED(IDC_LPT4, OnLpt4)
	ON_BN_CLICKED(IDC_NINE, OnNine)
	ON_BN_CLICKED(IDC_PLUGFIELD, OnPlugfield)
	ON_BN_CLICKED(IDC_SEVEN, OnSeven)
	ON_BN_CLICKED(IDC_SIX, OnSix)
	ON_BN_CLICKED(IDC_SPINDLE, OnSpindle)
	ON_BN_CLICKED(IDC_THREE, OnThree)
	ON_BN_CLICKED(IDC_TWO, OnTwo)
	ON_BN_CLICKED(IDC_XDIR, OnXdir)
	ON_BN_CLICKED(IDC_XSTEP, OnXstep)
	ON_BN_CLICKED(IDC_YDIR, OnYdir)
	ON_BN_CLICKED(IDC_YSTEP, OnYstep)
	ON_BN_CLICKED(IDC_ZDIR, OnZdir)
	ON_BN_CLICKED(IDC_ZSTEP, OnZstep)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// pinouts message handlers

void pinouts::OnEight() 
{
	if( !Function ) 
	{ CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
      stat->SetWindowText( "Select Function to Map ");
      stat->Invalidate(TRUE);
      return;
	}
	int temp = Pins[6];
	for(int y=0; y<8; y++) if( Pins[y] == Function) Pins[y] = temp;
	Pins[6] = Function;
	DrawPin();
	Function = 0;
	SetModified(TRUE);
	
}


void pinouts::OnThree() 
{
	if( !Function ) 
	{ CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
      stat->SetWindowText( "Select Function to Map ");
      stat->Invalidate(TRUE);
      return;
	}
	int temp = Pins[1];
	for(int y=0; y<8; y++) if( Pins[y] == Function) Pins[y] = temp;
 
	Pins[1] = Function;
	DrawPin();
    Function = 0;
	SetModified(TRUE);
}

void pinouts::OnTwo() 
{
	if( !Function ) 
	{ CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
      stat->SetWindowText( "Select Function to Map ");
      stat->Invalidate(TRUE);
      return;
	}
	int temp = Pins[0];
	for(int y=0; y<8; y++) if( Pins[y] == Function) Pins[y] = temp;
 
	Pins[0] = Function;
   DrawPin();
   Function = 0;
   SetModified(TRUE);
}

void pinouts::OnFive() 
{
	if( !Function ) 
	{ CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
      stat->SetWindowText( "Select Function to Map ");
      stat->Invalidate(TRUE);
      return;
	}
	int temp = Pins[3];
	for(int y=0; y<8; y++) if( Pins[y] == Function) Pins[y] = temp;
 
	Pins[3] = Function;
	DrawPin();
    Function = 0;
	SetModified(TRUE);
}

void pinouts::OnFour() 
{
	if( !Function ) 
	{ CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
      stat->SetWindowText( "Select Function to Map ");
      stat->Invalidate(TRUE);
      return;
	}
 	int temp = Pins[2];
	for(int y=0; y<8; y++) if( Pins[y] == Function) Pins[y] = temp;

	Pins[2] = Function;
	DrawPin();
    Function = 0;
	SetModified(TRUE);
}


void pinouts::OnNine() 
{
  if( !Function ) 
	{ CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
      stat->SetWindowText( "Select Function to Map ");
      stat->Invalidate(TRUE);
      return;
	}
    int temp = Pins[7];
	for(int y=0; y<8; y++) if( Pins[y] == Function) Pins[y] = temp;
 
    Pins[7] = Function;
	DrawPin();
    Function = 0;
	SetModified(TRUE);
}

void pinouts::OnSeven() 
{
	if( !Function ) 
	{ CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
      stat->SetWindowText( "Select Function to Map ");
      stat->Invalidate(TRUE);
      return;
	}
	int temp = Pins[5];
	for(int y=0; y<8; y++) if( Pins[y] == Function) Pins[y] = temp;
 
	Pins[5] = Function;
	DrawPin();
    Function = 0;
	SetModified(TRUE);
}

void pinouts::OnSix() 
{
	if( !Function ) 
	{ CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
      stat->SetWindowText( "Select Function to Map ");
      stat->Invalidate(TRUE);
      return;
	}
	int temp = Pins[4];
	for(int y=0; y<8; y++) if( Pins[y] == Function) Pins[y] = temp;
 
	Pins[4] = Function;
	DrawPin();
    Function = 0;
	SetModified(TRUE);
}



void pinouts::OnIoboard() 
{
 
   IO48 = !IO48;
   CButton *but = (CButton*) GetDlgItem(IDC_IOBOARD);
	if(IO48) but->SetCheck( 1 ); else but->SetCheck( 0 );
   UpdateData(FALSE);
   SetModified(TRUE);	
}

void pinouts::OnLpt1() 
{
	LPT1 = !LPT1;
	CButton *but = (CButton*) GetDlgItem(IDC_LPT1);
	if(LPT1) but->SetCheck( 1 ); else but->SetCheck( 0 );
	UpdateData(FALSE);
	SetModified(TRUE);
}

void pinouts::OnLpt2() 
{
	LPT2 = !LPT2;
	CButton *but = (CButton*) GetDlgItem(IDC_LPT2);
	if(LPT2) but->SetCheck( 1 ); else but->SetCheck( 0 );
	UpdateData(FALSE);
	SetModified(TRUE);
}

void pinouts::OnLpt3() 
{
	LPT3 = !LPT3;
	CButton *but = (CButton*) GetDlgItem(IDC_LPT3);
	if(LPT3) but->SetCheck( 1 ); else but->SetCheck( 0 );
	UpdateData(FALSE);
	SetModified(TRUE);
}

void pinouts::OnLpt4() 
{
	LPT4 = !LPT4;
	CButton *but = (CButton*) GetDlgItem(IDC_LPT4);
	if(LPT4) but->SetCheck( 1 ); else but->SetCheck( 0 );
	UpdateData(FALSE);
	SetModified(TRUE);
}

void pinouts::OnPlugfield() 
{
	// TODO: Add your control notification handler code here
	
}


void pinouts::OnSpindle() 
{
Function = 7;
CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
stat->SetWindowText( "Spindle Control -- Select Pin");
stat->Invalidate(TRUE);
	
}

void pinouts::OnEmerg() 
{
Function = 8;
CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
stat->SetWindowText( "Unused -- Select Pin");
stat->Invalidate(TRUE);
	
}


void pinouts::OnXdir() 
{

Function = 1;
CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
stat->SetWindowText( "X-Dir -- Select Pin");
stat->Invalidate(TRUE);
	
}

void pinouts::OnXstep() 
{
Function = 2;
CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
stat->SetWindowText( "X-Step -- Select Pin");
stat->Invalidate(TRUE);
	
}

void pinouts::OnYdir() 
{
Function = 3;
CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
stat->SetWindowText( "Y-Dir -- Select Pin");
stat->Invalidate(TRUE);
	
}

void pinouts::OnYstep() 
{
Function = 4;
CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
stat->SetWindowText( "Y-Step -- Select Pin");
stat->Invalidate(TRUE);

}

void pinouts::OnZdir() 
{
Function = 5;
CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
stat->SetWindowText( "Z-Dir -- Select Pin");
stat->Invalidate(TRUE);
	
}

void pinouts::OnZstep() 
{
Function = 6;
CStatic	*stat = (CStatic*) GetDlgItem(IDC_PROMPT);
stat->SetWindowText( "Z-Step -- Select Pin");
stat->Invalidate(TRUE);
	
}

BOOL pinouts::OnKillActive() 
{
	UpdateData(TRUE);
	//CString value;
	//value.Format("%d,%d,%d,%d,%d,%d,%d,%d",Pins[0],Pins[1],Pins[2],Pins[3],Pins[4],Pins[5],Pins[6],Pins[7],Pins[8]);
	//AfxGetApp( )->WriteProfileString("Preferences", "Pins2Functions" , (LPCTSTR) value);
	AfxGetApp( )->WriteProfileInt("Preferences", "Pin2" , (int)Pins[0] );
	AfxGetApp( )->WriteProfileInt("Preferences", "Pin3" , (int)Pins[1] );
    AfxGetApp( )->WriteProfileInt("Preferences", "Pin4" , (int)Pins[2] );
    AfxGetApp( )->WriteProfileInt("Preferences", "Pin5" , (int)Pins[3] );
    AfxGetApp( )->WriteProfileInt("Preferences", "Pin6" , (int)Pins[4] );
    AfxGetApp( )->WriteProfileInt("Preferences", "Pin7" , (int)Pins[5] );
    AfxGetApp( )->WriteProfileInt("Preferences", "Pin8" , (int)Pins[6] );
    AfxGetApp( )->WriteProfileInt("Preferences", "Pin9" , (int)Pins[7] );

	AfxGetApp( )->WriteProfileInt("Preferences", "LPT1" , (int)LPT1 ); // true by default
	AfxGetApp( )->WriteProfileInt("Preferences", "LPT2" , (int)LPT2 );
	AfxGetApp( )->WriteProfileInt("Preferences", "LPT3" , (int)LPT3 );
	AfxGetApp( )->WriteProfileInt("Preferences", "LPT4" , (int)LPT4 );
	AfxGetApp( )->WriteProfileInt("Preferences", "IO48" , (int)IO48 );

	return CPropertyPage::OnKillActive();
}

void pinouts::OnPaint() 
{
	CPaintDC dc(this);  
	CButton *but = (CButton*) GetDlgItem(IDC_IOBOARD);
	if(IO48) but->SetCheck( 1 ); else but->SetCheck( 0 );
	but = (CButton*) GetDlgItem(IDC_LPT1);
	if(LPT1) but->SetCheck( 1 ); else but->SetCheck( 0 );
	but = (CButton*) GetDlgItem(IDC_LPT2);
	if(LPT2) but->SetCheck( 1 ); else but->SetCheck( 0 );
	but = (CButton*) GetDlgItem(IDC_LPT3);
	if(LPT3) but->SetCheck( 1 ); else but->SetCheck( 0 );
	but = (CButton*) GetDlgItem(IDC_LPT3);
	if(LPT4) but->SetCheck( 1 ); else but->SetCheck( 0 );

 	DrawPin(); 	 

	
	 
}

void pinouts::DrawPin()
{

	CStatic *plugs = (CStatic*) GetDlgItem(IDC_PLUGFIELD);
	CDC *dc = plugs->GetDC();
	COLORREF bk = 0x000;
	CSize size = dc->GetWindowExt();
	RECT bounds;
	plugs->GetClientRect(&bounds);
	bounds.bottom -=3;
	bounds.right -= 3;
	bounds.top 	+= 3;
	bounds.left += 3;
	
	dc->FillSolidRect(&bounds, bk);
	dc->SelectStockObject(WHITE_PEN);
 
	for(int x = 1; x<9; x++)
	{
	  dc->MoveTo( (x*23)-9 , 3 );		   // goto each function
	  dc->LineTo( (x*23)-9, (Pins[x-1]*18)-5); // line to under pin
	  dc->LineTo( 3 , (Pins[x-1]*18)-5 );  // line to pin
	 
	}
	
}

 

void pinouts::OnOK() 
{
	// TODO: Add your specialized code here and/or call the base class
	OnKillActive();
	CPropertyPage::OnOK();
}

BOOL pinouts::OnApply() 
{
	 
 
	OnKillActive();
	return CPropertyPage::OnApply();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -