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

📄 backannt.cpp

📁 该软件为EDA行业所用
💻 CPP
字号:
// BackAnnt.cpp : implementation file
//

#include "stdafx.h"
#include "LIB2DXD.h"
#include "BackAnnt.h"

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


CString path;
CString txtFileName,logFileName;

/////////////////////////////////////////////////////////////////////////////
// CBackAnnt dialog


CBackAnnt::CBackAnnt(CWnd* pParent /*=NULL*/)
	: CDialog(CBackAnnt::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBackAnnt)
	m_fileContent = _T("");
	m_lmcFileName = _T("");
	//}}AFX_DATA_INIT
}


void CBackAnnt::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBackAnnt)
	DDX_Control(pDX, IDC_ADDLIST, m_AddFileList);
	DDX_Text(pDX, IDC_TXT, m_fileContent);
	DDX_Text(pDX, IDC_LMC, m_lmcFileName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBackAnnt, CDialog)
	//{{AFX_MSG_MAP(CBackAnnt)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_OPENLMC, OnOpenlmc)
	ON_BN_CLICKED(IDC_REMOVE, OnRemove)
	ON_LBN_SELCHANGE(IDC_ADDLIST, OnSelchangeAddlist)
	ON_BN_CLICKED(ID_BackAnn, OnBackAnn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBackAnnt message handlers

void CBackAnnt::OnAdd() 
{
	// TODO: Add your control notification handler code here
	// TODO: Add your control notification handler code here
	char *checkStr;
	static char szFilter[] = "Expedition PCB ASCII FILE(*.txt)|*.txt|All Files (*.*)|*.*||";
	CFileDialog OpenTxtDlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT ,szFilter,AfxGetMainWnd());
	CString addString;
	CFile OPENfp;
	POSITION FilePosition;	
	CFileStatus status;
	char AddFileBuf[10000];
	AddFileBuf[0]='\0';
	OpenTxtDlg.m_ofn.lpstrFile=AddFileBuf;
	OpenTxtDlg.m_ofn.nMaxFile=10000;			//缓冲区长度
	OpenTxtDlg.DoModal();						//打开文件对话框
	FilePosition=OpenTxtDlg.GetStartPosition();
	//AddString=OpenDlg.GetPathName();
	while (FilePosition!=NULL) 
	{
		addString=OpenTxtDlg.GetNextPathName(FilePosition);
		CFile::GetStatus( addString, status );
		if (addString!="")
			m_AddFileList.AddString(addString);
	}	
	// Open first file
	if(OPENfp.Open(addString,CFile::modeRead))//打开文件
	{
		checkStr=m_fileContent.GetBuffer(301);
		OPENfp.Read(checkStr,300);  //读取文件到文件缓冲区
		//if(addString.Left(18)!="")  //判断文件格式是否正确
		if(strncmp(checkStr,".Filetype ASCII_PDB",19)!=0)
		{
				AfxMessageBox("Error!! LIB2DXD 无法读取该文件——无效的库文件或不支持的文件格式!");
		}
		UpdateData(false);
		m_fileContent.ReleaseBuffer();
		OPENfp.Close();
	}
}

void CBackAnnt::OnOpenlmc() 
{
	// TODO: Add your control notification handler code here
	CString lmcFileName;
	int symLength,lmcLength;
	static char szFilter[] = "Central libraries(*.lmc)|*.lmc|All Files (*.*)|*.*||";
	CFileDialog openLmcDlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,AfxGetMainWnd());
	openLmcDlg.DoModal();
	m_lmcFileName=openLmcDlg.GetPathName();
	// Get ViewDraw schematic lib file name
	path=m_lmcFileName;
	lmcFileName=openLmcDlg.GetFileName();
	lmcLength=lmcFileName.GetLength();
	symLength=path.GetLength()-lmcLength;
	path=path.Left(symLength);
	UpdateData(false);

}

void CBackAnnt::OnRemove() 
{
	// TODO: Add your control notification handler code here
	int number,sequence,listIndex[15];
	while(m_AddFileList.GetSelCount())
	{
		m_AddFileList.GetSelItems(15,listIndex);
		number=m_AddFileList.GetSelCount();
		sequence=listIndex[number-1];
		m_AddFileList.DeleteString(sequence);
	}
}

void CBackAnnt::OnSelchangeAddlist() 
{
	// TODO: Add your control notification handler code here
	int selchangeIndex;
	int fileLength;
	char *checkStr;
	CFile selchangeFp;
	CString selchangeFileName;
	selchangeIndex=m_AddFileList.GetAnchorIndex();
	m_AddFileList.GetText(selchangeIndex,selchangeFileName);
	if (selchangeFileName)
	{		
		selchangeFp.Open(selchangeFileName,CFile::modeRead);//打开文件
		fileLength=selchangeFp.GetLength();
		checkStr=m_fileContent.GetBuffer(fileLength);		//获得缓冲区
		selchangeFp.Read(checkStr,300);  //读取文件到文件缓冲区						
		if (strncmp(checkStr,".Filetype ASCII_PDB",19)!=0)//判断文件格式是否正确
			AfxMessageBox("Error!! LIB2DXD 无法读取该文件——无效的库文件或不支持的文件格式!");
		UpdateData(false);
		m_fileContent.ReleaseBuffer();
		selchangeFp.Close();
	}


}

void CBackAnnt::OnBackAnn() 
{
	// TODO: Add your control notification handler code here
	int fileListIndex,logLength;
	char *logBuffer;
	CFile logFp;
	CString logMessage;
	if(!m_AddFileList.GetCount())
		OnAdd();
	if(!m_AddFileList.GetCount())
		return;
	if(!m_lmcFileName.GetLength())
		OnOpenlmc();
	if(!m_lmcFileName.GetLength())	
		return;

	// log file
	logFileName=path+"LogFiles\\BackAnnt.log";
	logFp.Open(logFileName,CFile::modeCreate|CFile::modeReadWrite);
	logFp.SeekToEnd();
   	logMessage="	\xd\x0a\xd\x0a	LIB2DXD  -  Transfer Protel lib to Dxdesigner LMC. Version 5.0 \xd\x0a";
	logFp.Write(logMessage,logMessage.GetLength());
	logMessage="	(c) Copyright Bei Institute of Technology. \xd\x0a";
	logFp.Write(logMessage,logMessage.GetLength());
	logMessage="	All Rights Reserved by jihengzhang. \xd\x0a\xd\x0a\xd\x0a";
	logFp.Write(logMessage,logMessage.GetLength());
	logFp.Close();
	// Get Expedition ASCII File Name
	int numLists;
	numLists=m_AddFileList.GetCount();
	for (fileListIndex=0;fileListIndex<numLists;fileListIndex++)
	{
		m_AddFileList.GetText(0,txtFileName);
		m_AddFileList.DeleteString(0);
		m_fileContent="";
		BackAnnotation();
	}
	// read logfile
	logFp.Open(logFileName,CFile::modeRead);
	logLength=logFp.GetLength();
	logBuffer=m_fileContent.GetBuffer(logLength+1);
	logFp.Read(logBuffer,logLength);
	logBuffer[logLength]=0;
	UpdateData(false);
	m_fileContent.ReleaseBuffer();
	logFp.Close();
}

	//BackAnnotation
#define READLENGTH 50000
#define BALANCE	   3000

void CBackAnnt::BackAnnotation()
{
	CFile txtFp;
	CString txtFileStr,deviceName,pkgType;
	CString partParameter[3];
	char txtFileBuf[READLENGTH+BALANCE],readBuffer[READLENGTH+1],*pBuffer;
	int readLength;
	char fileEndFlag=0;
	txtFileBuf[0]=0;
	pBuffer=txtFileBuf;
	if(txtFp.Open(txtFileName,CFile::modeRead))
	{

		while(1)
		{
			if((strlen(pBuffer)<BALANCE)&&fileEndFlag==0)
			{
				readLength=txtFp.Read(readBuffer,READLENGTH);//Not near the end of file
				readBuffer[readLength]=0;
				strcpy(txtFileBuf,pBuffer);
				strcat(txtFileBuf,readBuffer);
				if(readLength!=READLENGTH)//Not near the end of file
				{
					fileEndFlag=1;
				}
				pBuffer=txtFileBuf;
			}
			pBuffer=GetParameter(pBuffer,partParameter);
			if(pBuffer==NULL)
				break;
			WriteSymbolFile(partParameter);
		}
		txtFp.Close();
	}
	txtFileStr.ReleaseBuffer();
}

	//GetParameter
char *CBackAnnt::GetParameter(char *src,CString *des)
{
	char keyWord1[]=".Number";
	char keyWord2[]="..Symbol";
	char keyWord3[]="..TopCell";
	char pkgType[30],tmpBuffer1[50],tmpBuffer2[30];
	char SPACE[]="  ";
	char QUOTATION[]="\x22";//  " --34
	int  paraLength;
	char *colonPosition;

	des[0]="";
	des[1]="";
	des[2]="";
	src=strstr(src,keyWord1);
	if(src!=NULL)								//found a part
	{
		src=strstr(src,keyWord3);
		if(src!=NULL)							//found a pkgType
		{
			src=strchr(src,'"')+1;				//found "
			paraLength=strcspn(src,QUOTATION);
			strncpy(pkgType,src,paraLength);	//get pkgType
			pkgType[paraLength]=0;
			des[0]=pkgType;
			src=strstr(src,keyWord2);			
			if(src!=NULL)							//found a symbol
			{
				src=strchr(src,'"')+1;				//found "
				paraLength=strcspn(src,QUOTATION);	//found next "
				strncpy(tmpBuffer1,src,paraLength);
				tmpBuffer1[paraLength]=0;
				colonPosition=strchr(tmpBuffer1,':');
				if(colonPosition)
				{
					paraLength=colonPosition-tmpBuffer1;
					strncpy(tmpBuffer2,src,paraLength);
					tmpBuffer2[paraLength]=0;
					des[1]=tmpBuffer2;						//partition		
					colonPosition++;
					paraLength=strcspn(colonPosition,QUOTATION);
					strncpy(tmpBuffer2,colonPosition,paraLength);	//get symbol name
					tmpBuffer2[paraLength]=0;
					des[2]=tmpBuffer2;						//symbol				
				}
				else
				{
					des[1]="";
					des[2]=tmpBuffer1;
				}

			}
		}
	}
	return src;
}

	//BackToSymbolFile
void CBackAnnt::WriteSymbolFile(CString *src)
{
	CFile symbolFp,logFp;
	CString symbolStr,logMessage;
	CString symbolFileName;
	char *pOffset,*fileBuffer;
	char PKGTYPE[]="PKG_TYPE=",timeBuffer[9],dateBuffer[10];
	char originPkgType[30];
	int fileLength,writeLength,readLength;
	if(src[1]!="")
		src[1]+="\\";
	symbolFileName=path+"SymbolLibs\\"+src[1]+"sym\\"+src[2]+".1";
	_strtime(timeBuffer);								//get time
	_strdate(dateBuffer);								//get date
	if(symbolFp.Open(symbolFileName,CFile::modeReadWrite))
	{
		fileLength=symbolFp.GetLength();
		fileBuffer=symbolStr.GetBuffer(fileLength+1);
		pOffset=fileBuffer;
		symbolFp.Read(fileBuffer,fileLength);
		fileBuffer[fileLength]=0;
		pOffset=strstr(fileBuffer,PKGTYPE)+9;			//seek PKGTYPE
		writeLength=pOffset-fileBuffer;
		symbolFp.SeekToBegin();							//prepare to write to file
		symbolFp.Write(fileBuffer,writeLength);
		symbolFp.Write(src[0],src[0].GetLength());
		fileBuffer=pOffset;
		pOffset=strchr(pOffset,13);
		readLength=(pOffset-fileBuffer);
		strncpy(originPkgType,fileBuffer,readLength);
		originPkgType[readLength]=0;
		symbolFp.Write(pOffset,strlen(pOffset));		
		symbolFp.Close();
		
		//write log file
		logMessage="Successful	Change	symbol "+src[1]+":"+src[2]+"."+originPkgType +" to " +src[0]+"	"+timeBuffer+" "+dateBuffer+" \xd\x0a";
		logFp.Open(logFileName,CFile::modeReadWrite);
		logFp.SeekToEnd();
		logFp.Write(logMessage,logMessage.GetLength());
		logFp.Close();
	}
	else
	{
		logFp.Open(logFileName,CFile::modeReadWrite);
		logMessage="Failure	Edit	symbol	"+src[1]+":"+src[2]+"	"+timeBuffer+" "+dateBuffer+" \xd\x0a";
		logFp.SeekToEnd();
		logFp.Write(logMessage,logMessage.GetLength());
		logFp.Close();
	}
}

⌨️ 快捷键说明

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