- UID
- 306377
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-8-10
- 最后登录
- 1970-1-1
|
发表于 2005-9-19 18:56:56
|
显示全部楼层
//功能:在当前绘图上pick点,将获得的点坐标存在SQL Server数据库的同时,将pick的点顺序连线
//editor:fxm
//date:2005年9月16日
//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "MyDlg.h"
CString xpt[100];
CString ypt[100];
float xco[100];
float yco[100];
//-----------------------------------------------------------------------------
#define szRDS _RXST("lemon")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CPickPointApp : public AcRxArxApp {
public:
CPickPointApp () : AcRxArxApp () {}
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
// TODO: Add your initialization code here
return (retCode) ;
}
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
// TODO: Add your code here
return (retCode) ;
}
virtual void RegisterServerComponents () {
}
// ----- lemonPickPoint.pp command (do not rename)
static void lemonPickPointpp(void)
{
// Add your code for command lemonPickPoint.pp here
ads_point pt;
int NodeNumCount; //定义节点数,即最大的节点编号数值
acedGetInt("Please input the node number:",&NodeNumCount);
for(int i=0;i<NodeNumCount;i++)
{
if(acedGetPoint(NULL,"\nPick a point:",pt)==RTNORM)
{
xpt.Format("%g",pt[X]);
ypt.Format("%g",pt[Y]);
acutPrintf("\nThe coordinates of the point is:%s,%s",xpt,ypt);
}
}
_ConnectionPtr m_pConnection;
AfxOleInit();
HRESULT hr;
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open("Provider=SQLOLEDB;Data Source=CZQDAY;User ID=sa;Password=820306;Initial Catalog=TOSHIBA1","","",adModeUnknown);///连接数据库
}
try
{
_variant_t varProjectID,varID,varx,vary;
for(int i=0;i<NodeNumCount;i++)
{
atof(xpt);
atof(ypt);
varProjectID = "as001";
varID = i+1;
varx = xpt;
vary = ypt;
_RecordsetPtr t_pRecordset;
t_pRecordset.CreateInstance("ADODB.Recordset");
t_pRecordset->Open("SELECT * FROM xy",_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
t_pRecordset->MoveFirst();
t_pRecordset->AddNew();
t_pRecordset->PutCollect("ProjectID",varProjectID);
t_pRecordset->PutCollect("id",varID);
t_pRecordset->PutCollect("x",varx);
t_pRecordset->PutCollect("y",vary);
t_pRecordset->Update();//只有写了这句才能刷新数据库!!
//Refresh();//只有运行这个函数,才能保存成功
t_pRecordset->Close();
}
}
catch(_com_error e)///捕捉异常
{
AfxMessageBox("保存不成功!");///显示错误信息
}
//更改数据类型,CString->float
for (int j=0;j<NodeNumCount;j++)
{
xco[j]=atof(xpt[j]);
yco[j]=atof(ypt[j]);
}
//pick点,连续画直线
AcDbBlockTableRecord *pBlkTableRcd
=new AcDbBlockTableRecord();//创建块表记录
//以写方式得到当前块表的指针
AcDbBlockTable *pBlkTable=NULL;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlkTable, AcDb::kForWrite);
//将新的块表记录加入块表中,并获得块表记录的ID
AcDbObjectId Id;
pBlkTable->add(Id, pBlkTableRcd);
pBlkTable->close();
for(int k=0;k<NodeNumCount;k++)
{
//生成直线
AcGePoint3d startPt(xco[k],yco[k],0.0);//定义直线起点
AcGePoint3d endPt(xco[k+1],yco[k+1],0.0);//定义直线终点
AcDbLine *pLine=new AcDbLine(startPt,endPt);
AcDbBlockTable *pBlkTable2=NULL;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlkTable2, AcDb::kForRead);
pBlkTable2->getAt(ACDB_MODEL_SPACE, pBlkTableRcd,
AcDb::kForWrite);
pBlkTable2->close();
AcDbObjectId lineId;
pBlkTableRcd->appendAcDbEntity(lineId, pLine);
pLine->setLayer("Layer_Frame");//设置创建轮廓线的层为"Layer_Frame"
pLine->close();
}
pBlkTableRcd->close();
}
// ----- lemonPickPoint.verify command (do not rename)
static void lemonPickPointverify(void)
{
// Add your code for command lemonPickPoint.verify here
CMyDlg dlg;
dlg.DoModal();
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CPickPointApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CPickPointApp, lemonPickPoint, pp, pp, ACRX_CMD_TRANSPARENT, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CPickPointApp, lemonPickPoint, verify, verify, ACRX_CMD_TRANSPARENT, NULL) |
|