三維CAD與BOM管理系統(tǒng)的接口研究
(1) 得到裝配圖中裝配樹(shù)的根:
HRESULTres=S_OK;
LPCONFIGURATION pConfiguration= NULL;
LPMODELDOC pModelDoc= NULL;
LPCOMPONENT pRootComponent= NULL;
long RecurseLevel= 0;
LPSLDWORKS
pTemp= TheApplication- > GetSWApp () ;
respTemp- > get_IActiveDoc (pModelDoc) ;
if (S_OK! = res? ?pModelDoc== NULL)
return;
if (pModelDoc-> IGetActiveConfiguration
(pConfiguration) = = S_OK )
{pConfiguration- > IGetRootComponent
(pRootComponent) ;}??
(2) 從裝配樹(shù)根開(kāi)始,對(duì)裝配樹(shù)進(jìn)行遍歷,部分代碼如下:
int TraverseChildren ( long RecurseLevel,
LPCOMPONENT pComponent)
{
LPCOMPONENT3 pCh ildren = NULL;
int nChildren= 0;
HRESULT hres= S_ O K;
BSTR Name;
hres = pComponent- > get_Name (Name) ;
g_JianHaoArray1Add (Name) ;
??
if (S_OK = = hres? ?nChildren> 0)
{
pCh ildren =
new L PCOM PON EN T [nCh ildren ];
h res=
pComponent- > IGetCh ildren ( (L PCOM PON EN T3
3 ) pCh ildren) ;
pComponent- > get_Name (parent) ;
if (S_ O K = = h res) {
??Recursively t raverse the ch ildren
fo r ( i= 0;i nCh ildren;i+ + )
{
T raverseCh ildren (RecurseL evel,,pCh ildren[ i]) ;
pCh ildren [ i]- > Release () ;
}}
delete[ ]pCh ildren;}
RecurseL evel- - ;
??
return nChildren;
}
2-1-2 BOM接口對(duì)數(shù)據(jù)庫(kù)的操作
圖3 為BOM接口主界面,本文使用ADO(ActiveX Data Object) 實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)的操作。下面介紹在VC++中使用ADO的方法:
(1) 初始化COM庫(kù),引入ADO庫(kù)定義文件。
(2) 用Connection 對(duì)象連接數(shù)據(jù)庫(kù)。
(3) 利用建立好的連接,通過(guò)Connection、Command 對(duì)象執(zhí)行SQL 命令,或利用Recordset對(duì)象取得結(jié)果記錄集進(jìn)行查詢、處理。
(4) 使用完畢后關(guān)閉連接釋放對(duì)象。
在SolidWorks環(huán)境下對(duì)數(shù)據(jù)庫(kù)操作的部分代碼如下:
StsAfx1h
# impo rt“C:?P rogramF iles?CommonF iles?System?
ado?m sado151dll”no_ namespace rename (“EO F”,
“adoEO F”) ??引入ADO 庫(kù)定義
BOM1cpp
long InitU serDLL 3 (L PSLDWORKS pSldWo rk s)
{??
A fxO le Init () ;??初始化COM 庫(kù)
??
}
ReadWriteClass1cpp
BOOL ReadW riteClass::L inkDatabase (?)
{ ??
h r= m_ Connect ion1Create Instance
(“ADODB1Connect ion”) ;???創(chuàng)建Connect ion 對(duì)象
??
}
評(píng)論