新手入門(mén)必看:VectorDraw 常見(jiàn)問(wèn)題整理大全(十三)
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫(kù)。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。該庫(kù)還支持許多矢量和柵格輸入和輸出格式,包括本地PDF和SVG導(dǎo)出。
【VectorDraw Developer Framework最新版下載】
VectorDraw web library (javascript)是一個(gè)矢量圖形庫(kù)。VectorDraw web library (javascript)不僅能打開(kāi)CAD圖紙,而且能顯示任何支持HTML5標(biāo)準(zhǔn)平臺(tái)上的通用矢量對(duì)象,如Windows,安卓,iOS和Linux。無(wú)需任何安裝,VectorDraw web library (javascript)就可以運(yùn)行在任何支持canvas標(biāo)簽和Javascript的主流瀏覽器(Chrome, Firefox, Safari, Opera, Dolphin, Boat等等)中。
【VectorDraw web library (javascript)最新版下載】
一. 在用戶激活視口時(shí)更改視口的顏色
問(wèn):當(dāng)用戶通過(guò)雙擊激活視口時(shí),如何更改視口的顏色?
答:在“Collections”示例中添加ActionLayoutActivated事件并編寫(xiě)類(lèi)似的代碼:
VectorDraw.Professional.vdObjects.vdColor oldcolor = new VectorDraw.Professional.vdObjects.vdColor(); // there will store the color before the "highlight" VectorDraw.Professional.vdObjects.vdHandle deactivated_Viewport_handle = new VectorDraw.Professional.vdObjects.vdHandle(); // The handle of the Viewport we changed void ActiveDocument_ActionLayoutActivated(object sender, VectorDraw.Professional.vdPrimaries.vdLayout deactivated, VectorDraw.Professional.vdPrimaries.vdLayout activated) {// fires when the Layout or the Viewport changes if (activated.ActiveViewPort == null) // Run when MODEL is activated that happens when the viewport is activated or user returns to Model. { if (deactivated.ActiveViewPort != null) // the deactiveted vieport is the one that the use dbl-clicked { oldcolor.CopyFrom(deactivated.ActiveViewPort.PenColor); // store the color deactivated.ActiveViewPort.PenColor.SystemColor = Color.Red; // change the color deactivated.ActiveViewPort.Update(); deactivated.ActiveViewPort.Invalidate(); deactivated_Viewport_handle = deactivated.ActiveViewPort.Handle; // store the handle } if ((deactivated.ActiveViewPort == null) && (deactivated_Viewport_handle.Value != 0)) // This happens when the Viewport is not "active" {//create a vdViewport and set it to the viewport that was deactivated VectorDraw.Professional.vdFigures.vdViewport deactiViewport = new VectorDraw.Professional.vdFigures.vdViewport(); deactiViewport= vdFramedControl1.BaseControl.ActiveDocument.FindFromHandle(deactivated_Viewport_handle, typeof(VectorDraw.Professional.vdPrimaries.vdFigure)) as VectorDraw.Professional.vdFigures.vdViewport; deactiViewport.PenColor.CopyFrom(oldcolor); // change the color back if (deactiViewport.ClipObj != null) { deactiViewport.ClipObj.PenColor.CopyFrom(oldcolor); // to the ClipObj too deactiViewport.ClipObj.Update(); deactiViewport.ClipObj.Invalidate(); } deactiViewport.Update(); deactiViewport.Invalidate(); deactivated_Viewport_handle= new VectorDraw.Professional.vdObjects.vdHandle(0); // set the handle to 0 } } }
二. 在包裝器中使用AlignToView和AlignToViewSize
問(wèn):如何在包裝器中使用AlignToView和AlignToViewSize?
答:本文適用于6014及以上版本。使用VectorDraw.Professional.tlb,在VB6項(xiàng)目上只需添加一個(gè)vdraw包裝器和2個(gè)按鈕以及如下代碼:
Private Sub Command6_Click() Dim txt As VDrawI5.vdText Dim AlignObject As VectorDraw_Professional.IAlignToView Set txt = VD.ActiveDocument.entities.AddText("aaBB", Array(10, 10), 1) VD.CommandAction.CmdRect Array(9.5, 9.5), Array(14, 11.5) VD.CommandAction.Zoom "E", 0, 0 Set AlignObject = txt.WrapperObject ' set this text to be always parallel to the view. AlignObject.AlignToView = True AlignObject.AlignToViewSize = 20 'text size always the same, size in pixels End Sub Private Sub Command7_Click() VD.CommandAction.View3D "VROT" End Sub
三. 在移動(dòng)鼠標(biāo)的同時(shí)在光標(biāo)周?chē)?huà)一個(gè)圓圈
問(wèn):我想在移動(dòng)鼠標(biāo)時(shí)圍繞光標(biāo)畫(huà)一個(gè)圓圈。我沒(méi)有任何主動(dòng)操作,我嘗試使用MouseMove事件,但結(jié)果不正確。我該怎么做呢 ?
答:你應(yīng)該使用在沒(méi)有任何活動(dòng)操作的情況下觸發(fā)的OnActionDraw事件。試試如下代碼:
void ActiveDocument_OnActionDraw(object sender, object action, bool isHideMode, ref bool cancel) { VectorDraw.Actions.BaseAction act = action as VectorDraw.Actions.BaseAction; VectorDraw.Geometry.gPoint currentpoint = act.OrthoPoint; VectorDraw.Professional.vdFigures.vdCircle circle = new VectorDraw.Professional.vdFigures.vdCircle(); circle.SetUnRegisterDocument(vdSC.BaseControl.ActiveDocument); circle.setDocumentDefaults(); circle.Center = currentpoint; circle.Radius =2.0; circle.Draw(act.Render); }
四. 像cmdCircle那樣創(chuàng)建自己的命令
問(wèn):我想像cmdCircle那樣創(chuàng)建自己的命令,但沒(méi)有cmdCircle顯示的rubber radious。我該怎么做 ?
答:你需要?jiǎng)?chuàng)建自己的cmd-circle而不是使用我們的cmdCircle。例如,在表單中的空C#項(xiàng)目中添加一個(gè)vdScrollable控件(名為vdSC)和一個(gè)按鈕并使用如下代碼:
bool onMycmdCircle = false; VectorDraw.Geometry.gPoint cent = new VectorDraw.Geometry.gPoint(); private void Form1_Load(object sender, EventArgs e) { this.vdSC.BaseControl.ActiveDocument.ShowUCSAxis = false; this.vdSC.BaseControl.ActiveDocument.FreezeEntityDrawEvents.Push(false); this.vdSC.BaseControl.ActiveDocument.OnActionDraw += new VectorDraw.Professional.vdObjects.vdDocument.ActionDrawEventHandler(ActiveDocument_OnActionDraw); } void ActiveDocument_OnActionDraw(object sender, object action, bool isHideMode, ref bool cancel) { //here we draw the rubber circle if (action is VectorDraw.Actions.ActionGetPoint && onMycmdCircle) { VectorDraw.Actions.BaseAction act = action as VectorDraw.Actions.BaseAction; VectorDraw.Geometry.gPoint refpoint = act.ReferencePoint; VectorDraw.Geometry.gPoint currentpoint = act.OrthoPoint; VectorDraw.Professional.vdFigures.vdCircle circle = new VectorDraw.Professional.vdFigures.vdCircle(); circle.SetUnRegisterDocument(vdSC.BaseControl.ActiveDocument); circle.setDocumentDefaults(); circle.Center = cent; circle.Radius = circle.Center.Distance3D(currentpoint); circle.Draw(act.Render); } else { return; } return; } private void button2_Click(object sender, EventArgs e) { VectorDraw.Geometry.gPoint pt_cent = new VectorDraw.Geometry.gPoint(); VectorDraw.Geometry.gPoint pt_ref = new VectorDraw.Geometry.gPoint(); object status_cen = vdSC.BaseControl.ActiveDocument.ActionUtility.getUserPoint(out pt_cent); vdSC.BaseControl.ActiveDocument.ActiveLayOut.User2WorldMatrix.TransformPt(pt_cent, cent); if (status_cen != null && (VectorDraw.Actions.StatusCode)status_cen == VectorDraw.Actions.StatusCode.Success) { onMycmdCircle = true; object status_ref = vdSC.BaseControl.ActiveDocument.ActionUtility.getUserPoint(out pt_ref); onMycmdCircle = false; if (status_ref != null && (VectorDraw.Actions.StatusCode)status_ref == VectorDraw.Actions.StatusCode.Success) { //VectorDraw.Geometry.gPoint cent = new VectorDraw.Geometry.gPoint(); double radious = 0; VectorDraw.Geometry.gPoint refp = new VectorDraw.Geometry.gPoint(); vdSC.BaseControl.ActiveDocument.ActiveLayOut.User2WorldMatrix.TransformPt(pt_ref, refp); radious = refp.Distance3D(cent); vdSC.BaseControl.ActiveDocument.CommandAction.CmdCircle(cent, radious); } } }
未完待續(xù)~