翻译|使用教程|编辑:黄竹雯|2018-11-22 10:16:46.000|阅读 235 次
概述:本教程整理了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)最新版下载】
一. 为user-SaveAs提出路径,文件名和版本
问:如何向用户-SaveAs提出路径,文件名(文件类型)和版本?
答:创建一个新的C#项目,并在表单中添加一个vdFramed控件和一个按钮。然后使用如下代码:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private string GetSaveDlgFilterFormats() { string filetypes = ""; filetypes += "VDML (*.vdml)|*.vdml|"; filetypes += "vdcl (*.vdcl)|*.vdcl|"; filetypes += "DXF 2004 (*.dxf)|*.dxf|"; filetypes += "DXF 2000 (*.dxf)|*.dxf|"; filetypes += "DXF 12 (*.dxf)|*.dxf|"; filetypes += "|"; return filetypes; } public string GetSaveFileNameDlg(ref string version) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = GetSaveDlgFilterFormats(); if (version == "") version = vdFramedControl1.BaseControl.ActiveDocument.Version.ToUpper(); string defaultFileName = vdFramedControl1.BaseControl.ActiveDocument.FileName; if (defaultFileName == "") defaultFileName = "VectorDraw"; // use your default name here if (defaultFileName != null && defaultFileName != "") { saveFileDialog1.FileName = VectorDraw.Professional.Utilities.vdGlobals.GetFileNameWithoutExtension(defaultFileName); saveFileDialog1.InitialDirectory = VectorDraw.Professional.Utilities.vdGlobals.GetDirectoryName(defaultFileName); int FilterIndex = 1; if (defaultFileName.EndsWith(".dxf", StringComparison.InvariantCultureIgnoreCase)) { switch (version) { case "DXF2004": FilterIndex = 3; break; case "DXF2000": FilterIndex = 4; break; case "DXF12": FilterIndex = 5; break; default: break; } } saveFileDialog1.FilterIndex = FilterIndex; } saveFileDialog1.RestoreDirectory = true; DialogResult res = saveFileDialog1.ShowDialog(this); Application.DoEvents(); if (res != DialogResult.OK) return null; switch (saveFileDialog1.FilterIndex) { case 3: version = "DXF2004"; break; case 4: version = "DXF2000"; break; case 5: version = "DXF12"; break; default: break; } return saveFileDialog1.FileName; } private void saveas_Click(object sender, EventArgs e) {//VDF,VDI,VDCL,VDML does not have versions. string version = "DXF12";//propose this version or "DXF2000" or "DXF2004". Change to an empty string so the version of existing document will be selected. vdFramedControl1.BaseControl.ActiveDocument.Filename= @"c:\temp\mydrawing.dxf"; // use the proposed path and the proposed name here string fname = GetSaveFileNameDlg(ref version); // the filename (including path) that user chose if (fname == null) return; // user canceled save. vdFramedControl1.BaseControl.ActiveDocument.SaveAs(fname, null, version); } }
二. 在CmdCircle处于活动状态时在工具提示中显示圆的半径
问:当CmdCircle处于活动状态时,如何在工具提示中显示圆的半径?
答:在表单中放置vdFramedControl和一个简单的按钮。然后检查以下代码:
private void Form1_Load(object sender, EventArgs e) { vdFramedControl1.BaseControl.ActiveDocument.OnActionJobLoop += new VectorDraw.Professional.vdObjects.vdDocument.ActionJobLoopEventHandler(ActiveDocument_OnActionJobLoop); } private bool CmdCircleStarted = false; private void button1_Click(object sender, EventArgs e) { CmdCircleStarted = true; vdFramedControl1.BaseControl.ActiveDocument.CommandAction.CmdCircle("USER", "USER"); vdFramedControl1.BaseControl.ActiveDocument.ToolTipText = ""; CmdCircleStarted = false; } void ActiveDocument_OnActionJobLoop(object sender, object action, ref bool cancel) { if (!CmdCircleStarted) return; VectorDraw.Professional.CommandActions.ActionCircle act = action as VectorDraw.Professional.CommandActions.ActionCircle; if (act == null) return; VectorDraw.Professional.vdFigures.vdCircle circle = act.Entity as VectorDraw.Professional.vdFigures.vdCircle; if (circle == null) return; vdFramedControl1.BaseControl.ActiveDocument.ToolTipText = "Radius: " + vdFramedControl1.BaseControl.ActiveDocument.lunits.FormatLength (circle.Radius); }
三. 计算视口中显示的对象的位置
问:如何计算视口内显示的对象布局中的位置?
答:在新的C#(Windows窗体)项目中添加vdFramed控件和2个按钮。然后添加以下代码:
public Form1() { InitializeComponent(); } ulong textHandle = 0; ulong circHandle = 0; ulong viewpHandle = 0; short ColorInd = 40; private void Form1_Load(object sender, EventArgs e) {//create a circle, a text (these points will be calculated) a Layout and a Viewport. vdFramedControl1.BaseControl.ActiveDocument.New(); //create a circle VectorDraw.Professional.vdFigures.vdCircle circ = new VectorDraw.Professional.vdFigures.vdCircle(); circ.SetUnRegisterDocument(vdFramedControl1.BaseControl.ActiveDocument); circ.setDocumentDefaults(); circ.Center = new VectorDraw.Geometry.gPoint(-3, -2, .5); circ.Radius = (double)3.3; vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.Entities.AddItem(circ); circHandle = circ.Handle.Value; //create a text VectorDraw.Professional.vdFigures.vdText txt = new VectorDraw.Professional.vdFigures.vdText(); txt.SetUnRegisterDocument(vdFramedControl1.BaseControl.ActiveDocument); txt.setDocumentDefaults(); txt.InsertionPoint = new VectorDraw.Geometry.gPoint(3, 1, 3.5); txt.TextString = "Find WCoords in Layout"; vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.Entities.AddItem(txt); textHandle = txt.Handle.Value; //create a Layout VectorDraw.Professional.vdPrimaries.vdLayout lay = new VectorDraw.Professional.vdPrimaries.vdLayout(); lay.SetUnRegisterDocument(vdFramedControl1.BaseControl.ActiveDocument); lay.setDocumentDefaults(); lay.Name = "MyLayout1"; lay.ShowUCSAxis = false; vdFramedControl1.BaseControl.ActiveDocument.LayOuts.AddItem(lay); //create a Viewport VectorDraw.Professional.vdFigures.vdViewport view = new VectorDraw.Professional.vdFigures.vdViewport(); view.SetUnRegisterDocument(vdFramedControl1.BaseControl.ActiveDocument); view.setDocumentDefaults(); view.ShowUCSAxis = false; view.Height = 100; view.Width = 150; view.Center = new VectorDraw.Geometry.gPoint(100.0, 230.0); view.ViewCenter = new VectorDraw.Geometry.gPoint(4.4008, 1.8233); view.ViewSize = 17.0; view.PenColor.SystemColor = Color.Red; view.PenWidth = 1.0d; //And add this viewport to the entities of the first layout. lay = vdFramedControl1.BaseControl.ActiveDocument.LayOuts.FindName("MyLayout1"); if (lay != null) lay.Entities.AddItem(view); viewpHandle = view.Handle.Value; vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut = lay;//change the view to the MyLayout1 vdFramedControl1.BaseControl.ActiveDocument.Redraw(false); } private void buttonCalculatePoints_Click(object sender, EventArgs e) {// this code will calculate (in WorldCS) the points of the two entities that are shown inside the viewport //get the entities from their handles VectorDraw.Professional.vdFigures.vdCircle onecircle = vdFramedControl1.BaseControl.ActiveDocument.FindFromHandle(new VectorDraw.Professional.vdObjects.vdHandle(circHandle), typeof(VectorDraw.Professional.vdPrimaries.vdFigure)) as VectorDraw.Professional.vdFigures.vdCircle; VectorDraw.Professional.vdFigures.vdText onetext = vdFramedControl1.BaseControl.ActiveDocument.FindFromHandle(new VectorDraw.Professional.vdObjects.vdHandle(textHandle), typeof(VectorDraw.Professional.vdPrimaries.vdFigure)) as VectorDraw.Professional.vdFigures.vdText; //get the points to calculate (center point of the circle and insertion point of the text) VectorDraw.Geometry.gPoint CircPt = new VectorDraw.Geometry.gPoint(onecircle.Center); // circle's center point in WCS VectorDraw.Geometry.gPoint TextPt = new VectorDraw.Geometry.gPoint(onetext.InsertionPoint);// text's insertion point in WCS vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut = vdFramedControl1.BaseControl.ActiveDocument.LayOuts[0]; VectorDraw.Professional.vdFigures.vdViewport viewport = new VectorDraw.Professional.vdFigures.vdViewport(); //get the viewport and set it to active in order to get the transformation matrix viewport = vdFramedControl1.BaseControl.ActiveDocument.FindFromHandle(new VectorDraw.Professional.vdObjects.vdHandle(viewpHandle), typeof(VectorDraw.Professional.vdPrimaries.vdFigure)) as VectorDraw.Professional.vdFigures.vdViewport; vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveViewPort = viewport; vdFramedControl1.BaseControl.ActiveDocument.Redraw(true); //do the transformations and calculate the points VectorDraw.Geometry.gPoint ptC = vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveViewPort.Render.WorldToView(CircPt); // circle's center in Viewport's view coordinates VectorDraw.Geometry.gPoint ptT = vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveViewPort.Render.WorldToView(TextPt);// text's insertion point in Viewport's view coordinates VectorDraw.Geometry.gPoint ptT1 = new VectorDraw.Geometry.gPoint(); // in world coordinates VectorDraw.Geometry.gPoint ptC1 = new VectorDraw.Geometry.gPoint();//in world coordinates vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveViewPort = null; VectorDraw.Geometry.Matrix mat = new VectorDraw.Geometry.Matrix(); mat.ScaleMatrix(1 / viewport.ViewportScale, 1 / viewport.ViewportScale, 1 / viewport.ViewportScale); mat.TranslateMatrix(viewport.Center); mat.TransformPt(ptT - viewport.ViewCenter, ptT1); mat.TransformPt(ptC - viewport.ViewCenter, ptC1); // Create a line to connect the two calculated points VectorDraw.Professional.vdFigures.vdLine lin = new VectorDraw.Professional.vdFigures.vdLine(); lin.SetUnRegisterDocument(vdFramedControl1.BaseControl.ActiveDocument); lin.setDocumentDefaults(); lin.StartPoint = new VectorDraw.Geometry.gPoint(ptT1.x,ptT1.y,(double)0.0); // the insertion point of the text in World coordinates in the Layout lin.EndPoint = new VectorDraw.Geometry.gPoint(ptC1.x, ptC1.y, (double)0.0); // the center point of the circle in World coordinates in the Layout // z is set to zero as it is not needed in Paper spaces lin.PenColor.ColorIndex = ColorInd; ColorInd += 1; lin.Invalidate(); vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.Entities.AddItem(lin); } private void buttonChangeViewport_Click(object sender, EventArgs e) { // Change the viewport so the circle and text are shown in different position, then press the calculate button. VectorDraw.Professional.vdFigures.vdViewport viewport = new VectorDraw.Professional.vdFigures.vdViewport(); viewport = vdFramedControl1.BaseControl.ActiveDocument.FindFromHandle(new VectorDraw.Professional.vdObjects.vdHandle(viewpHandle), typeof(VectorDraw.Professional.vdPrimaries.vdFigure)) as VectorDraw.Professional.vdFigures.vdViewport; vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveViewPort = viewport; vdFramedControl1.BaseControl.ActiveDocument.CommandAction.View3D("vise"); viewport.ViewCenter = new VectorDraw.Geometry.gPoint(5, -4); viewport.ViewSize = 30; vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveViewPort = null; viewport.Update(); viewport.Invalidate(); }
敬请期待接下来的教程连载~
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@capbkgr.cn