VectorDraw Developer Framework(VDF)是一个用于应用程序可视化的图形引擎库。有了VDF提供的功能,您可以轻松地创建、编辑、管理、输出、输入和打印2D和3D图形文件。该库还支持许多矢量和栅格输入和输出格式,包括本地PDF和SVG导出。
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等等)中。

一. 导出背景色的SVG文件
问:是否可以导出背景颜色不同于白色的SVG文件?
答:可以通过一些代码行来指示VDF(VectorDraw Developer Framework)组件在OnDrawBackground事件中使用Palette的背景颜色,例如:

// the form conatins a vdFramedControl and a Buttonbool isOnSVGSave = false; // use this global boolean in the form and make it true just before saving the SVG and then again to false after save is finishedprivate void button1_Click(object sender, EventArgs e)
{vdDocument doc = vdFramedControl.BaseControl.ActiveDocument;doc.Open(@"C:\test\simple1.vdml"); // open a test filedoc.Palette.Background = Color.LightYellow; // change the background colordoc.Palette.Forground = Color.DarkSlateGray; // and the foreground color.....
.....isOnSVGSave = true; //set this flag to true before saving SVGdoc.OnDrawBackground += new vdDocument.DrawBackgroundEventHandler(doc_OnDrawBackground); // enable the eventdoc.SaveAs(@"c:\test\svg1.svg"); // save the SVGdoc.OnDrawBackground -= new vdDocument.DrawBackgroundEventHandler(doc_OnDrawBackground); // disable the eventisOnSVGSave = false;//set this flag back to false after saving SVG
}void doc_OnDrawBackground(object sender, vdRender render, ref bool cancel)
{if (isOnSVGSave && render!=null && render is RenderFormats.SvgRender) // check that is on "save" and render is SvgRender{cancel = true; // you need to pass this as trurender.Clear(vdFramedControl.BaseControl.ActiveDocument.Palette.Background); // clear the render and use the Palette’s Background color!}
}

二. 在非XY平面中创建polyhatch
问:如何在非X / Y平面中创建polyhatch?
答:在创建剖面线时,多边形曲线和剖面线应位于X / Y平面中,因此如果在相同但不是X / Y平面中有折线,则需要将它们“带”到X / Y平面,创建聚阴影线,然后让他们回到他们的平面。请看以下代码:

private void Test(){vdDocument doc = vdFramedControl.BaseControl.ActiveDocument;doc.New();#region create 2 random polylines// we will use two circles in order to get some random points from them to create the polylines.vdCircle cir1 = new vdCircle(doc, new gPoint(3, 2), 5);vdCircle cir2 = new vdCircle(doc, new gPoint(3, 2), 2);Vector vec = new Vector(0.3, 0.7, -0.2); vec.Normalize();cir1.ExtrusionVector = vec;cir2.ExtrusionVector = vec;// 2 circles are created in the same "random" plane// get some points from these just to "have" two polylinesgPoints pts1 = cir1.geomMeasure(7); // points of 1st polylinegPoints pts2 = cir2.geomMeasure(4); // points of 2nd polyline#endregionMatrix mat = new Matrix(); // this is the matrix of the plane that the circles belong tomat.SetToViewDirection(vec, 0.0d);Matrix invmat = new Matrix(mat.GetInvertion());// create the curves for the polyhatchvdPolyline pl = new vdPolyline(doc, pts1);// vector should be perpendicular in the plane where the polyline is and can also calculated using CalculateNormal3P, like:Vector vec2 = new Vector();Vector.CalculateNormal3P(pl.VertexList[0] as gPoint, pl.VertexList[1] as gPoint, pl.VertexList[2] as gPoint, out vec2);// in this case we already have it from the circle, as we set it above.pl.ExtrusionVector = vec;pl.Flag = VdConstPlineFlag.PlFlagCLOSE;pl.Transformby(mat); // we need to bring these points to X/Y planepl.Update();VectorDraw.Professional.vdCollections.vdCurves curves_Outer = new VectorDraw.Professional.vdCollections.vdCurves();curves_Outer.AddItem(pl);pl = new vdPolyline(doc, pts2);pl.ExtrusionVector = vec;pl.Flag = VdConstPlineFlag.PlFlagCLOSE;pl.Transformby(mat); pl.Update(); // we need to bring these points to X/Y planeVectorDraw.Professional.vdCollections.vdCurves curves_Inside = new VectorDraw.Professional.vdCollections.vdCurves();curves_Inside.AddItem(pl);//'create polyhatchvdPolyhatch onehatch = new vdPolyhatch(doc);onehatch.PolyCurves.AddItem(curves_Outer);onehatch.PolyCurves.AddItem(curves_Inside);onehatch.HatchProperties = new VectorDraw.Professional.vdObjects.vdHatchProperties(VectorDraw.Professional.Constants.VdConstFill.VdFillModeSolid);onehatch.Transformby(invmat); // bring this to the plane where the circles are.doc.Model.Entities.AddItem(onehatch);//just add the circles for display reasons. There is no need to add themcir1.PenColor.FromSystemColor(Color.Red);cir2.PenColor.FromSystemColor(Color.Red);doc.Model.Entities.AddItem(cir1);doc.Model.Entities.AddItem(cir2);doc.CommandAction.Zoom("E", 0, 0);}

三. 导出txt文件中的xyz坐标
问:如何将图形中的折线和折线的x,y,z数据导出到txt文件中?
答:VDF没有自动化此功能,但很容易从加载到VDF组件的任意图形中导出此txt文件。请参阅以下代码:

private void button1_Click(object sender, EventArgs e)
{vdDocument doc = vdFramedControl.BaseControl.ActiveDocument;doc.New();doc.Open(@"c:\test\MyModel Layout_1.0.dxf");using (StreamWriter writer = new StreamWriter(doc.FileName+".txt")) //export c:\test\MyModel Layout_1.0.dxf.txt file containing the points of lines and polylines only{foreach (vdFigure item in doc.Model.Entities){if (item != null && item is vdLine){writer.WriteLine("vdLine " + (item as vdLine).StartPoint.ToString() + " " + (item as vdLine).EndPoint.ToString());}if (item != null && item is vdPolyline){writer.Write("vdPolyline ");foreach (Vertex item2 in (item as vdPolyline).VertexList){writer.Write(item2.AsgPoint().ToString() + " ");}writer.WriteLine(" ");}}}
}

你所需要的只是循环遍历文档中的所有对象(线,折线等)并获取其x,y,z值并使用StreamWriter将它们写入txt文件。

四. 如何覆盖折线的夹点
问:我想以不同的方式绘制折线的第一个夹点。我如何才能做到这一点?
答:以下是使用FigureDrawGrips事件执行此操作的示例:

..... // need to have these
doc.FreezeEntityDrawEvents.Push(false);
doc.OnFigureDrawGrips += new vdDocument.FigureDrawGripsEventHandler(doc_OnFigureDrawGrips);
....
and//overrides the default draw grip//draw the first grip of all vdFigures as red circle//and the others as rectangle using the default grip colorvoid doc_OnFigureDrawGrips(object sender, vdRender render, ref bool cancel){vdFigure fig = sender as vdFigure;if (fig == null) return;//calculate the circle points and grip box points relative to grip center.double half_viewsize = render.PixelSize * render.GlobalProperties.GripSize * 0.5d;gPoint offsetPoint = new gPoint(half_viewsize, half_viewsize);Box GripBox = new Box(offsetPoint * -1, offsetPoint);gPoints circlepts = Globals.GetArcSamplePoints(16, half_viewsize, 0, Globals.VD_TWOPI);Matrix morigin = new Matrix();gPoints pts = fig.GetGripPoints();//points are in world CSint i = 0;foreach (gPoint pt in pts){if (!render.IsSectionVisible(pt)) continue;//check the 3d section clip visibilitygPoint ptInView = render.CurrentMatrix.Transform(pt);System.Drawing.Point p = render.View2PixelMatrix.Transform2GDIPoint(ptInView);if (!render.Contains(p)) continue;//check if grip is inside the screen//initialize a new offset matrix represents the center of grip in current view CSmorigin.IdentityMatrix();morigin.TranslateMatrix(ptInView);//push to matrix where the grip figure points are reference(see GripBox and circlepts)render.PushToViewMatrix();render.PushMatrix(morigin);if (i == 0)//if it is the first grip{render.PushPenstyle(Color.Red, true);render.DrawPLine(sender, circlepts);render.PopPenstyle();}else render.DrawBoundBox(sender, GripBox);render.PopMatrix();render.PopMatrix();//if a rendering procedure was break usually by a user pan / zoom in-outif (render.StatusDraw == vdRender.DrawStatus.Break) break;i++;}render.IsMessageQueEmpty();//update the render StatusDraw by checking if a mouse action was placed by the usercancel = true;//do not call the default VectorDraw grip draw.}

五. VDF滚动的鼠标滚轮控制
问:我想禁用鼠标平移和鼠标滚轮缩放,而不是使用滚轮,我想控制绘图的滚动,水平和垂直。我如何才能做到这一点?
答:您可以按照以下操作来禁用鼠标中键平移和鼠标滚轮放大/缩小。

//For the wrapper we have to get the vdDocument object like below.
VectorDraw.Professional.vdObjects.vdDocument doc = vd.ActiveDocument.WrapperObject as VectorDraw.Professional.vdObjects.vdDocument;doc.MouseWheelZoomScale = 1.0;              //1.0 means disabled mouse wheel. 0.8(less than 1.0) or 1.2(more than 1.0) values can reverse the mouse wheel functionality.

想要禁用平移,你必须使用如下的JobStart事件。

vd.JobStart += new AxVDrawLib5._DVdrawEvents_JobStartEventHandler(vd_JobStart);void vd_JobStart(object sender, AxVDrawLib5._DVdrawEvents_JobStartEvent e)
{if (e.jobName == "BaseAction_ActionPan") e.cancel = 1;}

要滚动视图,请使用以下代码:

... // these events must be useddoc.MouseWheelZoomScale = 1.0d; // disable mouse wheel zoomdoc.ActionStart += new vdDocument.ActionStartEventHandler(doc_ActionStart);vdFramedControl1.BaseControl.MouseWheel += new MouseEventHandler(BaseControl_MouseWheel);...void BaseControl_MouseWheel(object sender, MouseEventArgs e){if ((e != null) && (e.Delta != 0)){vdDocument doc = vdFramedControl1.BaseControl.ActiveDocument;double height = doc.ActiveRender.Height * doc.ActiveRender.PixelSize;double width = doc.ActiveRender.Width * doc.ActiveRender.PixelSize;double stepY = height * (e.Delta / Math.Abs(e.Delta)) / 10.0d;double stepX = width * (-1.0d * e.Delta / Math.Abs(e.Delta)) / 10.0d;if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift){ // if Shift key is pressed scroll horizontallydoc.ScrollActiveActionRenderView(stepX, 0.0d, true); // scroll only in dX}else //else scroll vertically{doc.ScrollActiveActionRenderView(0.0d, stepY, true); // scroll only in dY}}}void doc_ActionStart(object sender, string actionName, ref bool cancel){if (actionName == "BaseAction_ActionPan") cancel = true; // cancel middle mouse button pan}

接下来我会继续连载该系列教程的~希望自己可以坚持!

新手入门必看教程:矢量绘图控件VectorDraw 常见问题整理大全(一)相关推荐

  1. Leap Motion新手入门必看教程

    : 到leap motion后, 第一件事情是访问官方网站下载对应的电脑驱动 http://leapmotion.com/setup 选择对应的操作系统(windows或MAC)下载相应的驱动并进行安 ...

  2. 【学点Linux】Linux该如何学习(新手入门必看)

    Linux该如何学习(新手入门必看) 文章目录 Linux该如何学习(新手入门必看) 如何去学习 碰到问题怎么办 英文读不懂怎么办 忘记Windows的思维方式 无意间在一处看到的,分享出来. 如何去 ...

  3. powershell 开发入门_详谈Ubuntu PowerShell(小白入门必看教程)

    早在去年八月份PowerShell就开始开源跨平台了,但是一直没有去尝试,叫做PowerShell Core. 这里打算简单介绍一下如何安装和简单使用,为还不知道PowerShell Core on ...

  4. IntelliJ IDEA 最常用配置详细图解,新手入门必看

    转载自   IntelliJ IDEA 最常用配置详细图解,新手入门必看 刚刚使用IntelliJ IDEA 编辑器的时候,会有很多设置,会方便以后的开发,磨刀不误砍柴工. 比如:设置文件字体大小,代 ...

  5. 旅行青蛙前期怎么玩 新手入门必看攻略

    旅行青蛙前期怎么玩?有什么新手攻略吗?相信大家最近都被这款游戏刷屏了,感觉全世界都在玩,很多玩家都不小心入坑了,下面就和小编一起去看看这游戏要怎么玩吧. 旅行青蛙前期怎么玩? 主角是一只可爱的小青蛙, ...

  6. 撼龙图怎么开鸿蒙炁灵,【一人之下】新手入门必看攻略,萌新技巧超详细攻略...

    <一人之下>新手该怎么玩呢?新手需要掌握什么技巧呢?小编为大家整理了<一人之下>新手入门超详细攻略,一起来看看吧. 一.装备 6件防具.1把武器.6个饰品.还有炁灵和铭文. 装 ...

  7. C#控件常用设计整理大全

    1.常用属性  (1)Name属性:用来获取或设置窗体的名称,在应用程序中可通过Name属性来引用窗体. (2)WindowState属性:用来获取或设置窗体的窗口状态. 取值有三种: Normal ...

  8. JavaScript基础教程新手入门必看

    对前端稍微有点了解的初学者都知道,JavaScript是必不可少的工具.毫不夸张的说,大部分网页都使用了JavaScript,想要成为一个优秀的前端工程师,做出漂亮令用户满意的网页,熟练掌握JavaS ...

  9. Linux该如何学习(新手入门必看)

    本节旨在介绍对于初学者如何学习 Linux 的建议.如果你已经确定对 Linux 产生了兴趣,那么接下来我们介绍一下学习 Linux 的方法. 如何去学习 学习大多类似鹿丁解牛,对事物的认识一般都是由 ...

最新文章

  1. reboot 百度网盘资源
  2. 编程之美-寻找发帖“水王”方法整理
  3. 新页面,简单的tree视图写法
  4. 在intellij idea 中怎么不用git 解除关联
  5. 复制加网站信息的javascript代码及对应的javascript阻止命令
  6. 设计模式——19.迭代器模式
  7. Spark 机器学习 —— ALS
  8. AutoCompleteTextView输入汉字拼音首字母实现过滤提示(支持多音字,Filterable的使用)...
  9. element-ui表单验证时需要number类型
  10. python3.7 获取网络时间
  11. 高通QCA61 4A网卡驱动linux,高通创锐QCA61x4蓝牙4.1驱动程序
  12. 疫情期间再读三体(3)——黑暗森林到底怎么个黑法
  13. 微信小程序使用node-xlsx解析excel文件的云函数
  14. GNSS/INS超紧组合、深组合导航数据采集器
  15. 英语作业介绍一项发明计算机,计算机专业英语第1次作业.doc
  16. RestTemplete
  17. 基于JAVA口红专卖网站计算机毕业设计源码+数据库+lw文档+系统+部署
  18. mysql的一些基本常识(约束 、事务,事务隔离级别)
  19. springcloud-netfilx(Eureka)服务注册
  20. [电磁场AnsysMaxell仿真] 从一些简单的操作开始

热门文章

  1. 虚拟现实VR(视景仿真、系统仿真、可视化)工作站配置方案
  2. #python# 成语接龙(三)
  3. 淮阴工学院计算机答辩,淮阴工学院成绩管理规定
  4. 223. 矩形面积(矩形面积并简单版)
  5. “肉空间”是什么意思?
  6. 【基于EDK的嵌入式系统】 关于Xilinx EDK添加自定义IP核到PLB总线后linux无法boot的问题
  7. API 和 SDK 的区别
  8. 单色液晶屏的工作原理是什么? 单色液晶屏该如何分类
  9. Node-red开发软PLC程序?
  10. Linux音频设备驱动[zz]