在頁面空白處放置一個注釋,注釋可以在界面中定義。
//建立注釋
int UserNoteCreate(ProDrawing drawing,ProLine notestr,ProVector pos,ProModelitem modelitem,ProSelection* view_sel)
{
ProError err;
ProDtlnotetext text;
ProDtlnoteline line;
ProDtlnotedata ndata;
ProView view;
ProDtlattach attach;
ProDtlnote note;
ProSelection csys_sel;
int pid;
err=ProWindowCurrentGet(&pid);
//為注釋文本資料配置設定記憶體
err=ProDtlnotetextAlloc(&text);
if (err!=PRO_TK_NO_ERROR)
return err;
//将注釋文本存入text中
err=ProDtlnotetextStringSet(text,notestr);
if (err!=PRO_TK_NO_ERROR)
return err;
//Allocate memory for the note text line data. User must free memory by ProDtlnotelineFree()
err=ProDtlnotelineAlloc(&line);
if (err!=PRO_TK_NO_ERROR)
return err;
//Add text to the note text line data.
err=ProDtlnotelineTextAdd(line,text);
if (err!=PRO_TK_NO_ERROR)
return err;
//Allocate and initialize memory for note data. User must release memory by ProDtlnotedataFree.
err=ProDtlnotedataAlloc(drawing,&ndata);
if (err!=PRO_TK_NO_ERROR)
return err;
//将一行文本加入到ndata中
err=ProDtlnotedataLineAdd(ndata,line);
if (err!=PRO_TK_NO_ERROR)
return err;
//配置設定和選擇性的填充一個選擇對象
err=ProSelectionAlloc(NULL,&modelitem,&csys_sel);
if (err!=PRO_TK_NO_ERROR)
return err;
//獲得所選對象的視圖句柄
err=ProSelectionViewGet(view_sel[0],&view);
if (err!=PRO_TK_NO_ERROR)
return err;
err=ProSelectionViewSet(view,&csys_sel);
if (err!=PRO_TK_NO_ERROR)
return err;
//Allocate and initialize the memory for a detail attachment. User must release the memory by ProDtlattachFree.
err=ProDtlattachAlloc(PRO_DTLATTACHTYPE_FREE,view,pos,NULL,&attach);
if (err!=PRO_TK_NO_ERROR)
return err;
//将特定的注釋依附到我們所選擇的對象上
err=ProDtlnotedataAttachmentSet(ndata,attach);
if (err!=PRO_TK_NO_ERROR)
return err;
//建立一個注釋
err=ProDtlnoteCreate(drawing,NULL,ndata,¬e);
if (err!=PRO_TK_NO_ERROR)
return err;
//顯示建立的注釋
err=ProDtlnoteShow(¬e);
if (err!=PRO_TK_NO_ERROR)
return err;
err=ProDtlnotedataFree(ndata);
err=ProDtlattachFree(attach);
err=ProSelectionFree(&csys_sel);
err=ProDtlnotelineFree(line);
err=ProDtlnotetextFree(text);
//激活目前視窗
ProWindowActivate(pid);
return 0;
}
void CPart2DDlg::OnBnClickedBtnNoteAdd()
{
// TODO: 在此添加控件通知處理程式代碼
UpdateData(TRUE);
ProError err;
ProDrawing drawing=NULL;
ProLine notestr;
ProMouseButton button_pressed;
ProVector position;
ProModelitem modelitem;
ProSelection* sel;
int n_sel;
//擷取目前模型
err=ProMdlCurrentGet((ProMdl*)&drawing);
if (err!=PRO_TK_NO_ERROR)
return;
//所需添加的注釋内容
wcscpy_s(notestr, m_strNoteText);
//擷取使用者單擊滑鼠後獲得的坐标位置(即注釋将要放置的位置)
if (ProMousePickGet(PRO_ANY_BUTTON,&button_pressed,position)!=PRO_TK_NO_ERROR)
return;
//選擇一個對象(注釋所依附的對象)
err=ProSelect((char*)"feature",1,NULL,NULL,NULL,NULL,&sel,&n_sel);
if (err!=PRO_TK_NO_ERROR||n_sel<1)
return;
//從所選對象中擷取模型項
err=ProSelectionModelitemGet(sel[0],&modelitem);
if (err!=PRO_TK_NO_ERROR)
return;
UserNoteCreate(drawing,notestr,position,modelitem,sel);
}
運作結果: