?? mastercontroldlg.cpp
字號:
void CMasterControlDlg::BuildStringArray()
{
LPSTR lpNext = TextBuffer;
LPSTR lpEnd = TextBuffer + FileLength - 2;
*lpEnd = '\n';
for( cGLines = 0; lpNext < lpEnd; cGLines++, lpNext++)
{
lpNext = strchr(lpNext, '\n');
if( lpNext == NULL) break;
if( *lpNext == '\n' || *lpNext == '\r') lpNext+= sizeof(char);
}
GLines.SetSize(cGLines);
STRING string;
lpNext = TextBuffer;
for( int iLine = 0; iLine < cGLines; iLine++)
{
string.ccLen = 0;
string.pText = lpNext;
while(( *lpNext != '\n') && ( *lpNext != '\r'))
{
lpNext++; string.ccLen++;
}
GLines[iLine] = string;
*lpNext = 0;
lpNext +=( 2* sizeof(char));
while( *lpNext == '\n' || *lpNext == '\r') lpNext+= sizeof(char);
}
curline = 0; lastline = cGLines;
}
void CMasterControlDlg::QuantifyVectors()
{
double OldX=0,OldY=0,OldZ=0;
double diffX, diffY, diffZ;
static double oldangle = 0;
static double oldradius;
double newangle;
double newradius;
Line data;
maxX = 0; maxY = 0; maxZ = 0; //set mins and max's
minX = 0; minY = 0; minZ = 0;
data = DecodeLine( 0 );
if(data.xloc < 9999) maxX = data.xloc; else maxX = 0;
if(data.yloc < 9999) maxY = data.yloc; else maxY = 0; // for maximums
if(data.zloc < 9999) maxZ = data.zloc; else maxZ = 0;
if( data.xloc < 9999) OldX = data.xloc;
if( data.yloc < 9999) OldY = data.yloc;
if( data.zloc < 9999) OldZ = data.zloc;
int cCount = 0;
double distance = 0;
for( int x = 1; x < cGLines; x++)
{
cCount++;
data = DecodeLine( x );
if( data.xloc < 9999 )
{ diffX = OldX - data.xloc;
OldX = data.xloc;
if( OldX < minX ) minX = OldX;
if( OldX > maxX ) maxX = OldX;
}
else diffX = 0;
if( data.yloc < 9999 )
{ diffY = OldY - data.yloc;
OldY = data.yloc;
if( OldY < minY ) minY = OldY;
if( OldY > maxY ) maxY = OldY;
}
else diffY = 0;
if( data.zloc < 9999 )
{ diffZ = OldZ - data.zloc;
OldZ = data.zloc;
if( OldZ < minZ ) minZ = OldZ;
if( OldZ > maxZ ) maxZ = OldZ;
}
else diffZ = 0;
CalcAngle( newradius, newangle, diffX, diffY); // calculate angle and radius
m_LinearMM += (int)newradius; // linear mm's of cut tabulation
distance += newradius;
double change = fabs( newangle - oldangle); // calculate change of direction ( x/y only )
if( newradius == 0) { vector[x] = 1; steps[x] = 0; }
else
if( ((change < 1) || (change > 5.28)) && distance < MinDist) vector[x] = 1;
else
{
vector[x] = 0;
steps[x] = (int) (distance / XRes);
distance = 0;
}
oldangle = newangle;
oldradius = newradius;
}
m_Linear = m_LinearMM;
m_LinearEd.UpdateData(false);
m_XMax = maxX;
m_YMax = maxY;
m_ZMax = maxZ;
m_XMin = minX;
m_YMin = minY;
m_ZMin = minZ;
curline = 0;
m_CurLineInt = curline;
double maxX1 = maxX; double maxY1 = maxY;
if( maxX1 < 100 ) maxX1 = 100;
if( maxY1 < 100 ) maxY1 = 100;
UpdateData(FALSE);
bitmapX = 180/((maxX - minX)+1);
bitmapY = 180/((maxY - minY)+1);
bitmapZ = 128/((0 - minZ)+.001);
if( bitmapZ < 0) bitmapZ = -bitmapZ;
GMode = 0;
Axis = 1;
}
Line CMasterControlDlg::DecodeLine(int current)
{
Line data;
char *lp;
data.xloc = 9999;
data.yloc = 9999;
data.zloc = 9999;
data.rval = 9999;
data.ival = 9999;
data.jval = 9999;
data.kval = 9999;
data.gmode = 9999;
data.tool = 9999;
data.mval = 9999;
lp = GLines[current].pText;
int cc = 0;
while( lp[cc] != 0 )
{
switch ( lp[cc] )
{
case 'X' : data.xloc = atof( &lp[cc+1] );
break;
case 'Y' : data.yloc = atof( &lp[cc+1] );
break;
case 'Z' : data.zloc = atof( &lp[cc+1] );
break;
case 'R' : data.rval = atof( &lp[cc+1] );
break;
case 'K' : data.kval = atof( &lp[cc+1] );
break;
case 'I' : data.ival = atof( &lp[cc+1] );
break;
case 'J' : data.jval = atof( &lp[cc+1] );
break;
case 'G' : data.gmode = atoi( &lp[cc+1] );
if( data.gmode <= 3) GMode = data.gmode;
if( data.gmode == 20) Inches = true;
if( data.gmode == 21) Inches = false;
if( data.gmode == 4) Sleep( Dwell );
if( data.gmode == 17) Axis = 1;
if( data.gmode == 18) Axis = 2;
if( data.gmode == 19) Axis = 3;
if( Inches ) XRes = XResIn; else XRes = XResmm;
if( Inches ) YRes = YResIn; else YRes = YResmm;
if( Inches ) ZRes = ZResIn; else ZRes = ZResmm;
MaxRes = __min( XRes, YRes);
MaxRes = __min( MaxRes , ZRes );
break;
case 'T' : data.tool = atoi( &lp[cc+1]);
break;
case 'M' : if( !RUN ) break;
data.mval = atoi( &lp[cc+1]);
if ( data.mval == 6 && !Simulate) data.tool = 0; // or should there be a bit?
if ( data.mval == 3 && !Simulate) RouterOn();
if ( data.mval == 4 && !Simulate) RouterOn();
if ( data.mval == 5) RouterOff();
}
cc++;
}
return data;
}
void CMasterControlDlg::CalcAngle(double &radius, double &theta, double x, double y)
{
if( x == 0 && y == 0) { radius = 0; theta = 0; return; }
radius = sqrt(x * x + y * y);
if (radius == 0)
{
theta = 0;
return;
}
if (y > 0)
{
theta = acos(x / radius);
}
else
{
// acos(0) == pi / 2 // I'm using the trig functions instead of a constant
// to ensure that the conversion functions use the
// same values when going in both directions.
theta = 4.0 * acos((float)0) - acos(x / radius); }
}
void CMasterControlDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMasterControlDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMasterControlDlg::OnPrefs()
{
CPropertySheet *Prefs = new CPropertySheet( "Configuration");
CPropertyPage *pinsheet = new pinouts( );
CPropertyPage *propaux = new PropAux( );
CPropertyPage *pulsesheet = new pulses( );
CPropertyPage *speedsheet = new speeds( );
CPropertyPage *homesheet = new homeconf( );
CPropertyPage *translations = new Translation( );
CPropertyPage *feeds = new Feeds();
Prefs->AddPage(pinsheet);
Prefs->AddPage(propaux);
Prefs->AddPage(pulsesheet);
Prefs->AddPage(speedsheet);
Prefs->AddPage(homesheet);
Prefs->AddPage(translations );
Prefs->AddPage(feeds);
Prefs->DoModal();
SetupVars();
delete Prefs;
delete pinsheet;
delete propaux;
delete pulsesheet;
delete homesheet;
delete translations;
}
void CMasterControlDlg::OnAbout()
{
CAboutDlg *about = new CAboutDlg();
about->DoModal();
delete about;
}
bool CMasterControlDlg::SetupVars()
{
bool Success = FALSE;
int x = 2;
CString pin;
int pos;
CString buffer;
while( x < 10)
{
pin.Format( "Pin%d",x );
pos = AfxGetApp( )->GetProfileInt("Preferences", (LPCTSTR)pin , -99 );
if( pos == -99 )
{
CallPage( 1 ); // call property page #1 to replenish vars
return false; // then repeat
}
switch (pos)
{
case 1: XDirMask = 1 << ( x-2 );
break;
case 2: XStepMask = 1 << ( x-2 );
break;
case 3: YDirMask = 1 << ( x-2 );
break;
case 4: YStepMask = 1 << ( x-2 );
break;
case 5: ZDirMask = 1 << ( x-2 );
break;
case 6: ZStepMask = 1 << ( x-2 );
break;
case 7: SpindleMask = 1 << ( x-2 );
break;
case 8: EmergMask = 0;
break;
}
x++;
}
while( x < 14)
{
pin.Format( "Pin%d",x );
pos = AfxGetApp( )->GetProfileInt("Preferences", (LPCTSTR)pin , -99 );
if( pos == -99 )
{
CallPage( 5 ); // call property page #1 to replenish vars
return false; // then repeat
}
switch (pos)
{
case 1: EStopMask = 1 << ( x-10 );
break;
case 2: LimitXMask= 1 << ( x-10 );
break;
case 3: LimitYMask = 1 << ( x-10 );
break;
case 4: LimitZMask = 1 << ( x-10 );
break;
}
x++;
}
x = 1;
pin.Format( "Pin%d",x );
pos = AfxGetApp( )->GetProfileInt("Preferences", (LPCTSTR)pin , -99 );
if( pos == -99 )
{
CallPage( 5 ); // call property page #1 to replenish vars
return false; // then repeat
}
switch (pos)
{
case 1: Aux1Mask = 1 ;
break;
case 2: Aux2Mask = 1 ;
break;
case 3: Aux3Mask = 1 ;
break;
case 4: EnableMask = 1;
break;
}
x = 15;
pin.Format( "Pin%d",x );
pos = AfxGetApp( )->GetProfileInt("Preferences", (LPCTSTR)pin , -99 );
if( pos == -99 )
{
CallPage( 5 ); // call property page #1 to replenish vars
return false; // then repeat
}
switch (pos)
{
case 1: EStopMask = 1 << 4;
break;
case 2: LimitXMask= 1 << 4;
break;
case 3: LimitYMask = 1 << 4;
break;
case 4: LimitZMask = 1 << 4;
break;
}
x = 14;
pin.Format( "Pin%d",x );
pos = AfxGetApp( )->GetProfileInt("Preferences", (LPCTSTR)pin , -99 );
if( pos == -99 )
{
CallPage( 5 ); // call property page #1 to replenish vars
return false; // then repeat
}
switch (pos)
{
case 1: Aux1Mask = 2;
break;
case 2: Aux2Mask= 2;
break;
case 3: Aux3Mask = 2;
break;
case 4: EnableMask = 2;
break;
}
x = 16;
pin.Format( "Pin%d",x );
pos = AfxGetApp( )->GetProfileInt("Preferences", (LPCTSTR)pin , -99 );
if( pos == -99 )
{
CallPage( 5 ); // call property page #1 to replenish vars
return false; // then repeat
}
switch (pos)
{
case 1: Aux1Mask = 4;
break;
case 2: Aux2Mask= 4;
break;
case 3: Aux3Mask = 4;
break;
case 4: EnableMask = 4;
break;
}
x = 17;
pin.Format( "Pin%d",x );
pos = AfxGetApp( )->GetProfileInt("Preferences", (LPCTSTR)pin , -99 );
if( pos == -99 )
{
CallPage( 5 ); // call property page #5 to replenish vars
return false; // then repeat
}
switch (pos)
{
case 1: Aux1Mask = 8;
break;
case 2: Aux2Mask= 8;
break;
case 3: Aux3Mask = 8;
break;
case 4: EnableMask = 8;
break;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -