新手入门必看:VectorDraw 常见问题整理大全(十三)
VectorDraw Developer Framework(VDF)是一个用于应用程序可视化的图形引擎库。有了VDF提供的功能,您可以轻松地创建、编辑、管理、输出、输入和打印2D和3D图形文件。该库还支持许多矢量和栅格输入和输出格式,包括本地PDF和SVG导出。
【VectorDraw Developer Framework最新版下载】
VectorDraw web library (javascript)是一个矢量图形库。VectorDraw web library (javascript)不仅能打开CAD图纸,而且能显示任何支持HTML5标准平台上的通用矢量对象,如Windows,安卓,iOS和Linux。无需任何安装,VectorDraw web library (javascript)就可以运行在任何支持canvas标签和Javascript的主流浏览器(Chrome, Firefox, Safari, Opera, Dolphin, Boat等等)中。
【VectorDraw web library (javascript)最新版下载】
一. 在用户激活视口时更改视口的颜色
问:当用户通过双击激活视口时,如何更改视口的颜色?
答:在“Collections”示例中添加ActionLayoutActivated事件并编写类似的代码:
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
问:如何在包装器中使用AlignToView和AlignToViewSize?
答:本文适用于6014及以上版本。使用VectorDraw.Professional.tlb,在VB6项目上只需添加一个vdraw包装器和2个按钮以及如下代码:
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
三. 在移动鼠标的同时在光标周围画一个圆圈
问:我想在移动鼠标时围绕光标画一个圆圈。我没有任何主动操作,我尝试使用MouseMove事件,但结果不正确。我该怎么做呢 ?
答:你应该使用在没有任何活动操作的情况下触发的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那样创建自己的命令
问:我想像cmdCircle那样创建自己的命令,但没有cmdCircle显示的rubber radious。我该怎么做 ?
答:你需要创建自己的cmd-circle而不是使用我们的cmdCircle。例如,在表单中的空C#项目中添加一个vdScrollable控件(名为vdSC)和一个按钮并使用如下代码:
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); } } }
未完待续~