翻译|使用教程|编辑:黄竹雯|2018-10-29 11:22:45.000|阅读 324 次
概述:本教程整理了VectorDraw 最常见问题,教程整理的很齐全,非常适合新手学习,希望对大家有一定的帮助!
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
相关链接:
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)最新版下载】
一. 窗口选择地面对象的三角形
问:如何通过窗口选择vdGroundSurface对象来选择/获取某些三角形?
答:在新的C#项目中添加一个vdFramedControl并添加如下代码:
private void Form1_Load(object sender, EventArgs e) { vdFramedControl.CommandLine.CommandExecute += new VectorDraw.Professional.vdCommandLine.CommandExecuteEventHandler(CommandLine_CommandExecute); } void CommandLine_CommandExecute(string commandname, bool isDefaultImplemented, ref bool success) { if (isDefaultImplemented) return; if (string.Compare(commandname, "test", true) == 0) { success = true; vdDocument document = vdFramedControl.BaseControl.ActiveDocument; Box rectInViewCS = null; document.Prompt("Pick a window select"); StatusCode sc = document.ActionUtility.getUserRectViewCS(null, out rectInViewCS); document.Prompt(null); if (sc != StatusCode.Success) return; gPoints pts = new gPoints(); pts.Add(rectInViewCS.Min); pts.Add(rectInViewCS.Max); vdSelection set = new vdSelection(); set.SetUnRegisterDocument(document); vdFilterObject filterselect = new vdFilterObject(); filterselect.Types.AddItem("vdGroundSurface"); set.Select(RenderSelect.SelectingMode.CrossingWindowRectangle,pts); set.ApplyFilter(filterselect); if (set.Count == 0) return; vdGroundSurface gsf = set[0] as vdGroundSurface; gTriangles triangles = gsf.Triangles; VectorDraw.Render.Region rgn = new VectorDraw.Render.Region(rectInViewCS); int trigid = 0; VectorDraw.Generics.vdArray trgiIds = new vdArray(); gPoint p1, p2, p3; foreach (gTriangle trig in triangles) { p1 = document.World2ViewMatrix.Transform(trig.P1); p2 = document.World2ViewMatrix.Transform(trig.P2); p3 = document.World2ViewMatrix.Transform(trig.P3); if (rgn.IsLineInside(p1, p2) || rgn.IsLineIntersect(p1, p2)) trgiIds.AddItem(trigid); trigid++; if (rgn.IsLineInside(p2, p3) || rgn.IsLineIntersect(p2, p3)) trgiIds.AddItem(trigid); trigid++; if (rgn.IsLineInside(p3, p1) || rgn.IsLineIntersect(p3, p1)) trgiIds.AddItem(trigid); trigid++; } //test geting triangles from trgiIds foreach (int var in trgiIds) { gTriangle trig = triangles[(var + 1) / 3]; int trigline = var % 3;//0 is p1,p2 - 1 is p1,p2 - 2 = p3,p1 } } }
您可以加载具有复杂Groundsurface对象的图形,然后在命令提示符中写入“test”以运行代码。
二. 检查点是否在折线内
问:如何检查点是否在折线内?
答:可以创建具有这些功能的Region(对象)。请检查以下示例代码。
//Create A Polyline vdPolyline poly = new vdPolyline(); poly.SetUnRegisterDocument(vdFramedControl1.BaseControl.ActiveDocument); poly.setDocumentDefaults(); poly.VertexList.Add(new gPoint()); poly.VertexList.Add(new gPoint(1,1)); poly.VertexList.Add(new gPoint(2,2)); poly.VertexList.Add(new gPoint(3,2)); poly.VertexList.Add(new gPoint(5,2)); poly.VertexList.Add(new gPoint(6,1)); poly.VertexList.Add(new gPoint(3,0)); poly.VertexList.Add(new gPoint(0,0)); vdFramedControl1.BaseControl.ActiveDocument.Model.Entities.AddItem(poly); //Create A Region From the Polyline's points VectorDraw.Render.Region reg = new VectorDraw.Render.Region(poly.GetSamplePoints(0, 0)); //Check if a point is inside the polyline or not. bool a = reg.IsPointInside (new gPoint (0,1)); bool b = reg.IsPointInside (new gPoint (2,1));
三. 将实体从一个文档复制到另一个文档
问:如何将一些实体从一个控件复制到另一个控件?
答:使用VDF Prof. 6.x Wrapper或VDProControl(vdraw.ocx / vdprocontrol.dll),您可以尝试以下代码:
Private Sub copy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles copy.Click Dim coloritem As VectorDraw.Professional.vdObjects.vdColor Dim cadfig As vdFigure Dim selset As vdSelection Dim docfrom As VectorDraw.Professional.vdObjects.vdDocument Dim docto As VectorDraw.Professional.vdObjects.vdDocument vdto.ActiveDocument.New() vdfrom.ActiveDocument.Open(Application.StartupPath() + "\PD-23-from.vdi", 0, 0) vdfrom.CommandAction.Zoom("e", 0, 0) ''create a temporary selection to add the entities you want to copy in destination document selset = vdfrom.ActiveDocument.Selections.Add("tmpCopy") selset.RemoveAll() For Each cadfig In vdfrom.ActiveDocument.Entities If cadfig.Visible = False Then Continue For selset.AddItem(cadfig) Next ''get the the VectorDraw FrameWork document objects. docfrom = vdfrom.ActiveDocument.WrapperObject docto = vdto.ActiveDocument.WrapperObject ''disable the undo write in destination document docto.UndoHistory.PushEnable(False) ''Use the MergeSelection to copy the entites and table dependecies from source to destination document docto.MergeSelection(selset.WrapperObject) ''Set the pallete and backround colors of destination same as the source document docto.Palette.Background = docfrom.Palette.Background docto.Palette.Forground = docfrom.Palette.Forground docto.Palette.RemoveAll() For Each coloritem In docfrom.Palette docto.Palette.AddItem(coloritem.Clone()) Next docto.Model.BkColorEx = docfrom.ActiveLayOut.BkColorEx ''pop back the undo mode of the destination to its original value. docto.UndoHistory.PopEnable() vdto.CommandAction.Zoom("e", 0, 0) vdto.ActiveDocument.SaveAs(Application.StartupPath() + "\PD-23-to.vdi", VdConstFileVer.DefaultVersion) End Sub
两个VD控件是名称vdfrom和vdto。
四. 使用ToStream方法将图形作为存储在数据库中的块插入
问:如何使用ToStream方法将图形作为存储在数据库中的块插入?
答:您可以使用vdDocument的ToStream方法在数据库中保存/读取图形(文档),以将绘图保存在System.IO.MemoryStream和LoadFromMemory中以读取它,如:
object ByteArray = null; System.IO.MemoryStream memorystream = Doc.ToStream(); //doc can be the BaseControl.ActiveDocument or vdDoc1.Document or vdFrame.BaseControl.ActiveDocument if (memorystream == null) return 0; ByteArray = memorystream.ToArray(); int size = (int)memorystream.Length; memorystream.Close(); // then SAVE the ByteArray to your database and // Read the Bytes from database and store it in the ByteArray and then : System.IO.MemoryStream memorystream = new System.IO.MemoryStream((byte[])ByteArray); memorystream.Position = 0; Doc.LoadFromMemory(memorystream); memorystream.Close();
您可以在新项目中尝试上述代码,看看它是否正常工作。您也可以使用压缩,请参阅文章: http://www.vdraw.com/Export6/60000177.htm使用ToStream(true)和LoadFromMemory(stream,true)。
如果您希望以块的形式插入已存储在数据库中的文档,请尝试以下操作:
创建一个新的C#2005项目,并在新表单中添加一个vdScrollable控件(名为vdSC_From),一个名为vdDocComp_Temp的vdDocument控件,一个名为vdFramedControl的控件vdFC_To和2个按钮(button1和button2)。
该示例内部没有DATABASE代码,为此,vdScrollable控件(vdSC_from控件)用于在ByteArray中创建和保存文档,因此它将用于模拟数据库记录/字段中ByteArray的填充。然后使用临时vdDocument控件(vdDocComp_Temp)将此ByteArray“转换”回Document,然后使用vdBlocks对象的AddFromDocument方法生成插入vdFramed控件的图形(作为vdInsert)的vdBlock对象。另见下文,代码应该是:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } //Instead of a database, a VectorDraw Scrollable control (named vdSC_From) is used to create a drawing to a bytearray //Also a vdDocument component (named vdDocComp_Temp) is used so it can be filled with the drawing that is stored in the database (named DocumentToBlock) //after that in the Target's Document (the vdFC_To control) a block is created with AddFromDocument and inserted private void button1_Click(object sender, EventArgs e) { //instead of a database, a VectorDraw Scrollable control (vdSC_From) is used to create a drawing to a bytearray vdSC_From.BaseControl.ActiveDocument.New(); vdSC_From.BaseControl.ActiveDocument.CommandAction.CmdCircle(new VectorDraw.Geometry.gPoint(0, 0, 0), (double)2.0); vdSC_From.BaseControl.ActiveDocument.ActivePenColor.ColorIndex = 1; vdSC_From.BaseControl.ActiveDocument.CommandAction.CmdEllipse(new VectorDraw.Geometry.gPoint(0, 0, 0), new VectorDraw.Geometry.gPoint(1, 1, 0), (double)3.0); object ByteArray = null; System.IO.MemoryStream memorystream = vdSC_From.BaseControl.ActiveDocument.ToStream(true); //save to memory compressed if (memorystream == null) return ; ByteArray = memorystream.ToArray(); int size = (int)memorystream.Length; memorystream.Close(); // the drawing/document is created and saved to a public ByteArray // now we will read this to the temporary document VectorDraw.Professional.vdObjects.vdDocument DocumentToBlock = vdDocComp_Temp.Document; DocumentToBlock.New(); memorystream = new System.IO.MemoryStream((byte[])ByteArray); memorystream.Position = 0; DocumentToBlock.LoadFromMemory(memorystream, true);//Read from memory compressed memorystream.Close(); //and add the entities of this document to a block //We create a block object and initialize it's default properties. VectorDraw.Professional.vdCollections.vdBlocks blks = vdFC_To.BaseControl.ActiveDocument.Blocks; VectorDraw.Professional.vdPrimaries.vdBlock blk = blks.AddFromDocument("CustomBlock1",DocumentToBlock,true); blk.Update(); //add the block to the blocks collection vdFC_To.BaseControl.ActiveDocument.Blocks.AddItem(blk); //and now insert it; vdFC_To.BaseControl.ActiveDocument.CommandAction.CmdInsert("CustomBlock1", new VectorDraw.Geometry.gPoint(0.0d, 3.0d, 0.0d), 1d, 2d, 2d); } private void button2_Click(object sender, EventArgs e) { //instead of a database, a VectorDraw Scrollable control (vdSC_From) is used to create a drawing to a bytearray vdSC_From.BaseControl.ActiveDocument.New(); vdSC_From.BaseControl.ActiveDocument.CommandAction.CmdRect(new VectorDraw.Geometry.gPoint(2.0d, 1d, 0d), new VectorDraw.Geometry.gPoint(3.0d, 4d, 0d)); vdSC_From.BaseControl.ActiveDocument.ActivePenColor.ColorIndex = 3; vdSC_From.BaseControl.ActiveDocument.CommandAction.CmdArc(new VectorDraw.Geometry.gPoint(4.0d, 0d, 0d),2d, 1.0d,2.0d); object ByteArray = null; System.IO.MemoryStream memorystream = vdSC_From.BaseControl.ActiveDocument.ToStream(true); if (memorystream == null) return; ByteArray = memorystream.ToArray(); int size = (int)memorystream.Length; memorystream.Close(); // the drawing/document is created and saved to a public ByteArray // now we will read this to the temporary document VectorDraw.Professional.vdObjects.vdDocument DocumentToBlock = vdDocComp_Temp.Document; DocumentToBlock.New(); memorystream = new System.IO.MemoryStream((byte[])ByteArray); memorystream.Position = 0; DocumentToBlock.LoadFromMemory(memorystream,true); memorystream.Close(); //and add the entities of this document to a block //We create a block object and initialize it's default properties. VectorDraw.Professional.vdCollections.vdBlocks blks = vdFC_To.BaseControl.ActiveDocument.Blocks; VectorDraw.Professional.vdPrimaries.vdBlock blk = blks.AddFromDocument("CustomBlock2", DocumentToBlock, true); blk.Update(); //add the block to the blocks collection vdFC_To.BaseControl.ActiveDocument.Blocks.AddItem(blk); //and now insert it; vdFC_To.BaseControl.ActiveDocument.CommandAction.CmdInsert("CustomBlock2", new VectorDraw.Geometry.gPoint(0.0d, 3.0d, 0.0d), 1d, 2d, 2d); } }
未完待续......
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@cahobeh.cn