新手入门必看:VectorDraw 常见问题整理大全(十五)

本系列教程整理了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)最新版下载

一. 更改鼠标光标或将其隐藏

问:如何更改鼠标光标或隐藏它/p>

答:你可以使用SetCustomMousePointer方法将光标更改为Cursor(在下面的代码中更改为Cursors.PanNW)。要隐藏光标,你需要使用属性ShowCursor和vdMouseEnter事件。请看以下代码:

private void Form1_Load(object sender, EventArgs e){    vdFramedControl1.BaseControl.vdMouseEnter += new VectorDraw.Professional.Control.MouseEnterEventHandler(BaseControl_vdMouseEnter);}private bool show_pointer = true; // a flag in the form that controls if the cursor will be visible or not.void BaseControl_vdMouseEnter(EventArgs e, ref bool cancel){    if (show_pointer) return; // show the cursor        //else hide the cursor with the code below    cancel = true;    vdFramedControl1.BaseControl.ActiveDocument.GlobalRenderProperties.ShowCursor = false; //Hide cursor    vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.MouseEnter(this, e); // this is needed}private void button7_Click(object sender, EventArgs e) // Button to set the cursor to another cursor{    vdFramedControl1.BaseControl.SetCustomMousePointer(Cursors.PanNW); // set the cursor to another cursor    //using GetCustomeMousePointer you can get the cursor.}private void button8_Click(object sender, EventArgs e) //Button to set the cursor to default VDF cross{    vdFramedControl1.BaseControl.SetCustomMousePointer(null); // set the cursor to VDF cross}private void button9_Click(object sender, EventArgs e)//Button to Hide the cursor{show_pointer = false;vdFramedControl1.BaseControl.ActiveDocument.GlobalRenderProperties.ShowCursor=false; //Hide cursor}private void button10_Click(object sender, EventArgs e) //Button to show the cursor{    show_pointer = true;    vdFramedControl1.BaseControl.ActiveDocument.GlobalRenderProperties.ShowCursor=true; //Show cursor}Another way to hide the cursor, is to change it to an "empty"/"transparent" cursor that you will add to your project resources. In this case you will not need the vdMouseEnter event and the global flag and your code should be :private void button9_Click(object sender, EventArgs e){    vdFramedControl1.BaseControl.SetCustomMousePointer(new Cursor(WindowsApplication1.Properties.Resources.Icon1.Handle)); // set the cursor to an "empty/transparent" cursor Icon1.}private void button10_Click(object sender, EventArgs e){    vdFramedControl1.BaseControl.SetCustomMousePointer(null); // set it to the default (visible)}

二. 在所有图纸上绘制图纸的示例

问:我想实现一些功能,在屏幕上的所有实体的顶部呈现覆盖。在开始时,我只想在当前的vdraw视图的左下角绘制一个日期字符串。该文本将是视图独立的,因此无论用户选择何种3D视图,都将面向用户绘制。我也希望文本周围有点阴影,以便很容易看到。你认为最佳方法是什么否给出代码示例呢,谢谢!

答:可使用vdFramed控件的C#Windows应用程序中的示例:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using VectorDraw.Professional.vdObjects;using VectorDraw.Professional.vdFigures;using VectorDraw.Professional.vdPrimaries;using VectorDraw.Generics;using VectorDraw.Geometry;using VectorDraw.Professional.vdCollections;using VectorDraw.Actions;namespace WindowsApplication2{   public partial class Form2 : Form   {      public Form2()      {         InitializeComponent();      }      private vdDocument doc { get { return vdFramedControl1.BaseControl.ActiveDocument; } }      VectorDraw.Render.grTextStyle textstyle = null;      protected override void OnLoad(EventArgs e)      {         base.OnLoad(e);         doc.OnDrawAfter += new vdDocument.DrawAfterEventHandler(doc_OnDrawAfter);         doc.OnDrawOverAll += new vdDocument.DrawOverAllEventHandler(doc_OnDrawOverAll);         //create a global TextStyle used to draw the overall text         textstyle = new VectorDraw.Render.grTextStyle("Arial");      }    void drawoverall(VectorDraw.Render.vdRender render)    {        double DPIScale=1.0d; //ratio render DPI/ScreenDPI        if (render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW_PAPER || render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW)        {            DPIScale = (double)render.Height / (double)(doc.ActiveLayOut.Printer.LandScape doc.ActiveLayOut.Printer.paperSize.Width : doc.ActiveLayOut.Printer.paperSize.Height);        }        //make the active render unlock so it will always draw using GDIPlus API        bool islock = render.IsLock;        if (islock) render.UnLock();        //Get the display string        string str = System.DateTime.Now.ToShortDateString();        //Calculate the text box with the selecting text style Size.        Box textbox = textstyle.GetBaseTextBox(str, null);        //create a box that will be drawn in the text background and will be 25% biger tham the text box.        Box box = new Box(textbox);        box.AddWidth(textbox.Height * 0.25);        //calculate a Matrix that will scale and offset the drawing primitives.        Matrix m = new Matrix();        double OneMM_DUSize = render.PixelSize * DPIScale * render.DpiY * 1.0d / 25.4;        //select the text height to be 10 mm of height.        double scale = OneMM_DUSize * 10.0d / textbox.Height;        Box rendersize = render.ClipBounds.ToBox();        //select the left offset of the box to be 15 mm of width, and the the bottom offset of the box to be 15 mm.        gPoint offset = new gPoint((render.ClipBounds.Xmin + OneMM_DUSize * 15.0d), (render.ClipBounds.Ymin + box.Height * scale + OneMM_DUSize * 15.0d));        if (render.IsPrinting) //taking into consideration the printer hardware margins        {            offset.x += (OneMM_DUSize * Globals.INCH_MM * doc.ActiveLayOut.Printer.Hardmargins.Left / 100);            offset.y += (OneMM_DUSize * Globals.INCH_MM * doc.ActiveLayOut.Printer.Hardmargins.Bottom / 100);        }        m.ScaleMatrix(scale, scale, scale);        m.TranslateMatrix(offset);        //select the matrix and draw the primitives        render.PushToViewMatrix();        render.PushMatrix(m);        render.PushPenstyle(new VectorDraw.Render.vdGdiPenStyle(Color.Brown, 150));        render.DrawSolidBoundBox(this, box);        render.PopPenstyle();        render.PushPenstyle(new VectorDraw.Render.vdGdiPenStyle(Color.Blue, 255));        render.DrawString(this, textstyle, null, str, textbox);        render.PopPenstyle();        render.PopMatrix();        render.PopMatrix();        if (islock) render.Lock();    }//we use the OnDrawAfter event only when priniting because the OnDrawOverAll is not fired when printing      void doc_OnDrawAfter(object sender, VectorDraw.Render.vdRender render)      {         if (render.IsPrinting && (render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW_PAPER || render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PRINTER_PAPER)) drawoverall(render);      }      void doc_OnDrawOverAll(object sender, VectorDraw.Render.vdRender render, ref bool cancel)      {         drawoverall(render);      }   }}

三. 在HIDE模式下具有更细的线条

问:是否可以在HIDE模式下使用更细的线条/p>

答:当RenderMode为Hidden或ShadeOn时,可以使用FixedShadeOnPenWidth全局属性来控制线宽,如:

    VectorDraw.Render.vdRenderGlobalProperties.FixedShadeOnPenWidth = 0.0f;

默认值为0.016。此值表示以英寸为单位的线宽,通过将其设置为0,然后在HIDE模式下将1个像素用于“线”。

四. 根据GridMode = True的缩放动态更新限制

问:我打开了网格,并将vdDocument.Limits框设置为视图的当前可见范围。当用户使用鼠标滚轮缩小时,我目前没有将Limits值更改为当前视图范围,但希望这样做。如何捕捉鼠标滚轮的事件,以便我可以将网格的限制更改为新的范围何获得缩放更改事件,这是保持网格覆盖整个屏幕的最佳方法吗/p>

答:执行此操作的最佳方法是覆盖vddocument的draw和drawoverall事件,代码如下所示:

private void Form1_Load(object sender, EventArgs e){   vdFramedControl.BaseControl.ActiveDocument.OnDraw += new vdDocument.DrawEventHandler(doc_OnDraw);   vdFramedControl.BaseControl.ActiveDocument.OnDrawOverAll += new vdDocument.DrawOverAllEventHandler(doc_OnDrawOverAll);}void doc_OnDrawOverAll(object sender, VectorDraw.Render.vdRender render, ref bool cancel){   vdDocument document = sender as vdDocument;   UpdateLimits(document.ActiveLayOut);}void doc_OnDraw(object sender, VectorDraw.Render.vdRender render, ref bool cancel){   vdDocument document = sender as vdDocument;   UpdateLimits(document.ActiveLayOut);}private void UpdateLimits(vdLayout layout){   if (layout != null && layout.World2ViewMatrix.Zdir.Equals(layout.World2UserMatrix.Zdir))   {      Box limitBox = layout.Render.ClipBounds.ToBox();      limitBox.AddWidth(limitBox.Width / 2.0);      limitBox.TransformBy((layout.View2WorldMatrix * layout.World2UserMatrix));      layout.Limits.Empty(); layout.Limits.AddBox(limitBox);   }}

未完待续~

好消息!为了感谢大家的支持和关注,现免费送30套正版ABViewer软件~走过路过的同学千万不要错过~

ABViewer免费送

标签:CAD工业4.0

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年11月2日
下一篇 2018年11月2日

相关推荐

发表回复

登录后才能评论