?? genpadslibdlg.cpp
字號:
// GenPadsLibDlg.cpp : implementation file
//
#include "stdafx.h"
#include "string.h"
#include "afxtempl.h"
#include "GenPadsLib.h"
#include "GenPadsLibDlg.h"
//#include "math.h"
#include "common.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGenPadsLibDlg dialog
CGenPadsLibDlg::CGenPadsLibDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGenPadsLibDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGenPadsLibDlg)
m_partName = _T("");
m_pcbDecal = _T("");
m_numPins = 0;
m_alphaNumeric = _T("");
m_gateName = _T("");
m_numSignals = 0;
m_unit = _T("");
m_fileName = _T("");
m_log = _T("");
m_numGatePins = 0;
m_flag = -1;
m_logicType = _T("");
m_chkAlpha = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CGenPadsLibDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGenPadsLibDlg)
DDX_Control(pDX, ID_REMOVE, m_C_remove);
DDX_Control(pDX, ID_INSERT, m_C_insert);
DDX_Control(pDX, ID_EDIT, m_C_EDIT);
DDX_Control(pDX, IDC_LIST_GATE, m_C_listGate);
DDX_Control(pDX, IDC_E_ALPHANUM, m_C_alphaNumeric);
DDX_Text(pDX, IDC_E_PARTNAME, m_partName);
DDX_Text(pDX, IDC_E_PCBDECAL, m_pcbDecal);
DDX_Text(pDX, IDC_E_NUMPINS, m_numPins);
DDV_MinMaxUInt(pDX, m_numPins, 1, 32767);
DDX_Text(pDX, IDC_E_ALPHANUM, m_alphaNumeric);
DDX_Text(pDX, IDC_E_GATENAME, m_gateName);
DDX_Text(pDX, IDC_E_NUMSIGNALS, m_numSignals);
DDV_MinMaxUInt(pDX, m_numSignals, 0, 1024);
DDX_Text(pDX, IDC_E_UNIT, m_unit);
DDV_MaxChars(pDX, m_unit, 1);
DDX_Text(pDX, IDC_E_FILENAME, m_fileName);
DDX_Text(pDX, IDC_E_STATE, m_log);
DDX_Text(pDX, IDC_E_GATEPINS, m_numGatePins);
DDV_MinMaxUInt(pDX, m_numGatePins, 0, 32767);
DDX_CBIndex(pDX, IDC_CB_FLAG, m_flag);
DDX_CBString(pDX, IDC_CB_LOGCITYPE, m_logicType);
DDV_MaxChars(pDX, m_logicType, 3);
DDX_Check(pDX, IDC_CHECK_ALPH, m_chkAlpha);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGenPadsLibDlg, CDialog)
//{{AFX_MSG_MAP(CGenPadsLibDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDGen, OnGen)
ON_BN_CLICKED(IDC_OPENFILE, OnOpenfile)
ON_BN_CLICKED(IDC_CHECK_ALPH, OnCheckAlph)
ON_BN_CLICKED(ID_ADD, OnAdd)
ON_LBN_SELCHANGE(IDC_LIST_GATE, OnSelchangeListGate)
ON_BN_CLICKED(ID_REMOVE, OnRemove)
ON_BN_CLICKED(ID_INSERT, OnInsert)
ON_BN_CLICKED(ID_EDIT, OnEdit)
ON_EN_CHANGE(IDC_E_NUMPINS, OnChangeENumpins)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGenPadsLibDlg message handlers
BOOL CGenPadsLibDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// ****user initiation***
//************************
m_partName="NEW_PART";
m_pcbDecal="NEW_PCB";
m_numPins=2;
m_logicType="UND";
m_flag=0;
m_unit='I';
m_chkAlpha=0;
m_gateName="GATEA";
m_numGatePins=2;
m_log="Input base information of part !";
UpdateData(false);
// ***********************
return TRUE; // return TRUE unless you set the focus to a control
}
void CGenPadsLibDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CGenPadsLibDlg::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);
// m_numGatePins=m_numPins;
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CGenPadsLibDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CGenPadsLibDlg::OnGen()
{
// TODO: Add your control notification handler code here
CString tmpStr,fileBuffer,srcDefStr;
CString fileName;
CFile srcFile;
char* buffer;
//****Get inforamtion from the Dialog
UpdateData(true);
part.partName=m_partName;
part.pcbDecal=m_pcbDecal;
part.numPins=m_numPins;
part.flag=m_flag;
part.type=m_logicType;
part.UNIT=m_unit;
part.numCpins=0;
part.numGates=part.gateCA.GetSize();
part.alphaNumeric=m_alphaNumeric;
if(part.numGates==0)
{
AfxMessageBox("The number of GATES is wrong",0);
return;
}
if(m_fileName=="")
OnOpenfile();
srcFile.Open(m_fileName,CFile::modeRead);
buffer=tmpStr.GetBuffer(srcFile.GetLength());
srcFile.Read(buffer,srcFile.GetLength());
srcDefStr=buffer;
tmpStr.ReleaseBuffer();
if(srcDefStr=="")
{
m_log="File is empty";
UpdateData(false);
return;
}
// Get alphaNumeric pinNumer
if(part.isalpha && m_alphaNumeric.GetLength()!=0)
{
if(part.GetAlphaNumeric(&part)==false)
{
AfxMessageBox("The number of alphaNumeric is not equal with the number of pins",0);
//UpdateData(false);
return;
}
}
else if(m_alphaNumeric.GetLength()==0)
{
AfxMessageBox("The lenghte of alphaNumeric string is 0",0);
return;
}
//generate imformation of pin from source file
if(part.GetPinDef(&part,srcDefStr))
{ // print
if(WriteFile(&part,fileName))
{
m_log="Successful on generating PADS Library!\13\10 Please check file ";
m_log+=fileName;
}
}
else
{
m_log="Unsuccessful at generating pads library !";
return;
}
UpdateData(false);
part.alphaNumericCA.RemoveAll();
UpdateData(false);
}
LRESULT CGenPadsLibDlg::WriteFile(struct _PARTDEF* pPart,CString fileName)
{
CString fileBuffer,tmpStr;
CFile outputFile;
UINT pinSequence=0;
//Head of part file
fileBuffer="*PADS-LIBRARY-PART-TYPES-V4*";
tmpStr.Format("%c%c",13,10);
fileBuffer+=tmpStr+tmpStr;
fileBuffer+=part.partName+' '+part.pcbDecal+' ';
fileBuffer+=part.UNIT+' '+part.type+" 0 ";
tmpStr.Format("%d",part.gateCA.GetSize());
fileBuffer+=tmpStr+" 0 ";
tmpStr.Format("%d",part.alphaNumericCA.GetSize());
fileBuffer+=tmpStr+" 0 0";
tmpStr.Format("%c%c",13,10);
fileBuffer+=tmpStr;
//Head of Gate_x
for(int gateIndex=0;gateIndex<pPart->gateCA.GetSize();gateIndex++)
{
fileBuffer+="G:"+pPart->gateCA.GetAt(gateIndex)->gateDecals+" 0 ";
tmpStr.Format("%d%c%c",pPart->gateCA.GetAt(gateIndex)->pins,13,10);
fileBuffer+=tmpStr;
for(UINT pinIndex=0;pinIndex<part.gateCA.GetAt(gateIndex)->pins;pinIndex++)
{
if((int)pinSequence<pPart->pinStrCA.GetSize())
fileBuffer+=pPart->pinStrCA.GetAt(pinSequence);
else
{
AfxMessageBox("Number of pin in SrcFile Erro!",0);
return false;
}
tmpStr.Format("%c%c",13,10);
fileBuffer+=tmpStr;
pinSequence++;
}
}
fileBuffer+=part.alphaNumeric;
tmpStr.Format("%c%c%C%C",13,10,13,10);
fileBuffer+=tmpStr;
fileBuffer+="*END*";
fileName=m_fileName.Left(m_fileName.ReverseFind('.')+1);
fileName+="p";
outputFile.Open(fileName,CFile::modeCreate|CFile::modeWrite);
outputFile.WriteHuge(fileBuffer,fileBuffer.GetLength());
outputFile.Close();
return true;
}
// int numPins=partDefCA.GetSize();
// for(UINT sequence=0;sequence<m_numPins;sequence++)
// {
// pinAttr=pinAttr+part.GetAt(sequence);
// tmpStr.Format("%c%c",13,10);
// pinAttr+=tmpStr;
// }
// }
void CGenPadsLibDlg::OnOpenfile()
{
// TODO: Add your control notification handler code here
CString fileName,tmpStr;
CFile sourceFile;
char *filebuffer;
int fileLen;
static char szFilter[] = "Ascii file(*.txt)|*.txt|DxDesigner library List file(*.csv)|*.csv|All Files (*.*)|*.*||";
static char DefExt[]="csv";
UpdateData(true);
//static char DefExt[]="csv";
CFileDialog OpenDlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT ,szFilter,AfxGetMainWnd());
OpenDlg.DoModal(); //打開文件對話框
fileName=OpenDlg.GetPathName();
m_fileName=fileName;
if(sourceFile.Open(fileName,CFile::modeRead)==0)
return;
fileLen=sourceFile.GetLength();
filebuffer=tmpStr.GetBuffer(fileLen+1);
//m_log.Format("%d",sourceFile.Read(filebuffer,fileLen));
sourceFile.Read(filebuffer,fileLen);
//filebuffer[fileLen]='\0';
m_log=filebuffer;
//m_log=tmpStr;
tmpStr.ReleaseBuffer();
sourceFile.Close();
UpdateData(false);
}
void CGenPadsLibDlg::OnCheckAlph()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_chkAlpha==false)
{
part.alphaNumeric="";
part.alphaNumericCA.RemoveAll();
part.numAlphaN=0;
part.isalpha=false;
}
else
{
part.isalpha=true;
m_C_alphaNumeric.EnableWindow(m_chkAlpha);
}
}
void CGenPadsLibDlg::OnSelchangeListGate()
{
// TODO: Add your control notification handler code here
int listIndex=m_C_listGate.GetCaretIndex();
if(listIndex!=-1)
{
if(part.gateCA.GetSize()!=0)
{
m_gateName=part.gateCA.GetAt(listIndex)->gateDecals;
m_numGatePins=part.gateCA.GetAt(listIndex)->pins;
UpdateData(false);
m_C_EDIT.EnableWindow(true);
m_C_insert.EnableWindow(true);
m_C_remove.EnableWindow(true);
}
}
}
void CGenPadsLibDlg::OnAdd()
{
// TODO: Add your control notification handler code here
GateOperation('a');
}
void CGenPadsLibDlg::OnRemove()
{
// TODO: Add your control notification handler code here
UINT validPins=m_numPins;
int listIndex=m_C_listGate.GetCaretIndex();
if(listIndex!=-1)
{
part.gateCA.RemoveAt(listIndex);
m_C_listGate.DeleteString(listIndex);
//OnSelchangeListGate();
}
if(m_C_listGate.GetSelCount()==-1)
{
m_C_remove.EnableWindow(false);
m_C_EDIT.EnableWindow(false);
m_C_insert.EnableWindow(false);
}
for(int gateIndex=0;gateIndex<part.gateCA.GetSize();gateIndex++)
{
validPins-=part.gateCA.GetAt(gateIndex)->pins;
}
m_numGatePins=validPins;
UpdateData(false);
}
void CGenPadsLibDlg::OnInsert()
{
// TODO: Add your control notification handler code here
GateOperation('i');
}
void CGenPadsLibDlg::OnEdit()
{
// TODO: Add your control notification handler code here
GateOperation('e');
}
void CGenPadsLibDlg::GateOperation(char flag)
{
int listIndex=m_C_listGate.GetCaretIndex();
int validPins;
LPGATEDEF pGate=new GATEDEF;
CString tmpStr,formatStr;
UpdateData(true);
validPins=m_numPins;
for(int i=0;i<part.gateCA.GetSize();i++)
{
validPins-=part.gateCA.GetAt(i)->pins;
}
//m_numGatePins=validPins;
//UpdateData(false);
if(int(m_numGatePins)>validPins)
{
m_numGatePins=validPins;
UpdateData(false);
return;
}
if(validPins!=0 && m_numGatePins!=0)
{
tmpStr.Format("GATE_%c NAME= ",m_C_listGate.GetCount()+65);
tmpStr+=m_gateName;
formatStr.Format(" PINS= %d",m_numGatePins);
tmpStr+=formatStr;
}
else
{
AfxMessageBox("Invalid PinNumber");
return;
}
switch(flag) {
case 'a': //Add
case 'A':
m_C_listGate.AddString(tmpStr);
pGate->gateDecals=m_gateName;
pGate->pins=m_numGatePins;
pGate->gateswap=0;
part.gateCA.Add(pGate);
break;
case 'e':
case 'E':
pGate->gateDecals=m_gateName;
pGate->gateswap=0;
pGate->pins=m_numGatePins;
part.gateCA.SetAt(listIndex,pGate);
m_C_listGate.DeleteString(listIndex);
m_C_listGate.InsertString(listIndex,tmpStr);
m_C_EDIT.EnableWindow(false);
break;
case 'i':
case 'I':
if(listIndex!=-1)
{
pGate->gateDecals=m_gateName;
pGate->pins=m_numGatePins;
pGate->gateswap=0;
part.gateCA.InsertAt(listIndex+1,pGate,1);
m_C_listGate.InsertString(listIndex+1,tmpStr);
//OnSelchangeListGate();
}
break;
default: //Remove
break;
}
validPins=m_numPins;
for(int gateIndex=0;gateIndex<part.gateCA.GetSize();gateIndex++)
{
validPins-=part.gateCA.GetAt(gateIndex)->pins;
}
m_numGatePins=validPins;
UpdateData(false);
}
void CGenPadsLibDlg::OnChangeENumpins()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(true);
UINT validPins;
validPins=m_numPins;
for(int gateIndex=0;gateIndex<part.gateCA.GetSize();gateIndex++)
validPins-=part.gateCA.GetAt(gateIndex)->pins;
m_numGatePins=validPins;
UpdateData(false);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -