VDF常見(jiàn)問(wèn)題整理(三十八):如何插入折線的預(yù)定義形狀?
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫(kù)。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
問(wèn):
用戶(hù)如何在不使用預(yù)定義塊的情況下將預(yù)定義的折線形狀放置在布局中的某處?
答:
示例:
我們首先使用scriptCommand.rect制作一個(gè)矩形(或一條線,一條折線等),然后在rect的回調(diào)中調(diào)用actionentityadded,它調(diào)用了scriptCommand.select,所以現(xiàn)在矩形已經(jīng)被選中,在select的回調(diào)中我們調(diào)用moveCallback,所以現(xiàn)在我們可以移動(dòng)矩形并將其放置在所需位置。
在scriptCommand.move的回調(diào)中,我們調(diào)用sclaleCallback,該腳本運(yùn)行scriptCommand.scale()或scriptCommand.rotate()??s放或旋轉(zhuǎn)逗號(hào)的回調(diào),調(diào)用函數(shù)actionfinish,在其中更新布局,重新繪制畫(huà)布,然后將SetActionLineColor(null)恢復(fù)為默認(rèn)值。
function redo() { vdcanvas.scriptCommand.redo(); setTimeout(vdcanvas.redraw); } function undo() { vdcanvas.scriptCommand.undo(); setTimeout(vdcanvas.redraw); } function polyline() { //we start the undogroup vdcanvas.scriptCommand.undogroup('begin'); //create a rect for example with InsertionPoint too far in order not to be draw on screen vdcanvas.scriptCommand.rect([[2000, 2000, 0], 3.0, 4.0,0], actionentityadded); } function actionentityadded(vdrawobj, entity) { vdrawobj.SetActionLineColor([0, 0, 0, 0]);//set the action line color invisible vdrawobj.scriptCommand.select([entity], movecallback);//update script select with user entity and call the move command } function movecallback(vdrawobj) { var rect = vdcanvas.scriptCommand.ActiveSelection()[0]; vdcanvas.scriptCommand.move(rect.InsertionPoint, null, sclaleCallback);//call move action with reference the InsertionPoint of rect } function sclaleCallback(vdrawobj) { var rect = vdcanvas.scriptCommand.ActiveSelection()[0]; if (!vdrawobj.ActiveAction().IsCanceled()) { //vdrawobj.scriptCommand.scale(rect.InsertionPoint, null, actionfinish); //call scale or rotate action with reference the InsertionPoint of rect vdcanvas.scriptCommand.rotate(rect.InsertionPoint,null,actionfinish); } else {//user press esc or right-click so the command is canceled actionfinish(vdrawobj); } } function actionfinish(vdrawobj) { var rect = vdrawobj.scriptCommand.ActiveSelection()[0]; if (vdrawobj.ActiveAction().IsCanceled()) {//in case action is canceled by the user esc or right click rect.Deleted = true;//mark the create figure as deleted vdrawobj.UpdateLayout(); //mark the layout bounds to be updated setTimeout(vdrawobj.redraw);//post a redraw in order to clear existing entity draw by the active action } vdrawobj.SetActionLineColor(null);//restore action line color to default value. vdcanvas.scriptCommand.undogroup('close');//Close the undogroup }
對(duì)于以上問(wèn)答,如果您有任何的疑惑都可以在評(píng)論區(qū)留言,我們會(huì)及時(shí)回復(fù)。此系列的問(wèn)答教程我們會(huì)持續(xù)更新,如果您感興趣,可以多多關(guān)注本教程。
熱門(mén)文章推薦:
如果您對(duì)想要購(gòu)買(mǎi)正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢(xún)相關(guān)問(wèn)題。
關(guān)注慧聚IT微信公眾號(hào) ???,了解產(chǎn)品的最新動(dòng)態(tài)及最新資訊。