• <menu id="w2i4a"></menu>
  • logo VectorDraw教程
    文檔首頁>>VectorDraw教程>>新手入門必看:VectorDraw 常見問題整理大全(十二)

    新手入門必看:VectorDraw 常見問題整理大全(十二)


    VectorDraw Developer Framework(VDF)是一個用于應(yīng)用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。該庫還支持許多矢量和柵格輸入和輸出格式,包括本地PDF和SVG導(dǎo)出。

    VectorDraw Developer Framework最新版下載

    VectorDraw web library (javascript)是一個矢量圖形庫。VectorDraw web library (javascript)不僅能打開CAD圖紙,而且能顯示任何支持HTML5標(biāo)準(zhǔn)平臺上的通用矢量對象,如Windows,安卓,iOS和Linux。無需任何安裝,VectorDraw web library (javascript)就可以運行在任何支持canvas標(biāo)簽和Javascript的主流瀏覽器(Chrome, Firefox, Safari, Opera, Dolphin, Boat等等)中。

    VectorDraw web library (javascript)最新版下載

    一. 為user-SaveAs提出路徑,文件名和版本

    問:如何向用戶-SaveAs提出路徑,文件名(文件類型)和版本?

    答:創(chuàng)建一個新的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處于活動狀態(tài)時在工具提示中顯示圓的半徑

    問:當(dāng)CmdCircle處于活動狀態(tài)時,如何在工具提示中顯示圓的半徑?

    答:在表單中放置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);
    }

    三. 計算視口中顯示的對象的位置

    問:如何計算視口內(nèi)顯示的對象布局中的位置?

    答:在新的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();
    
    }

    敬請期待接下來的教程連載~

    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();