• <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)就可以運(yùn)行在任何支持canvas標(biāo)簽和Javascript的主流瀏覽器(Chrome, Firefox, Safari, Opera, Dolphin, Boat等等)中。

    VectorDraw web library (javascript)最新版下載

    一. 導(dǎo)出背景色的SVG文件

    問:是否可以導(dǎo)出背景顏色不同于白色的SVG文件?

    答:可以通過一些代碼行來指示VDF(VectorDraw Developer Framework)組件在OnDrawBackground事件中使用Palette的背景顏色,例如:

    // the form conatins a vdFramedControl and a Button
    
    bool 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 finished
    
    private void button1_Click(object sender, EventArgs e)
    {
        vdDocument doc = vdFramedControl.BaseControl.ActiveDocument;
    
        doc.Open(@"C:\test\simple1.vdml"); // open a test file
        doc.Palette.Background = Color.LightYellow; // change the background color
        doc.Palette.Forground = Color.DarkSlateGray; // and the foreground color
    
    .....
    .....
    
        isOnSVGSave = true; //set this flag to true before saving SVG
        doc.OnDrawBackground += new vdDocument.DrawBackgroundEventHandler(doc_OnDrawBackground); // enable the event
        doc.SaveAs(@"c:\test\svg1.svg"); // save the SVG
        doc.OnDrawBackground -= new vdDocument.DrawBackgroundEventHandler(doc_OnDrawBackground); // disable the event
        isOnSVGSave = 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 tru
            render.Clear(vdFramedControl.BaseControl.ActiveDocument.Palette.Background); // clear the render and use the Palette’s Background color!
        }
    }   

    二. 在非XY平面中創(chuàng)建polyhatch

    問:如何在非X / Y平面中創(chuàng)建polyhatch?

    答:在創(chuàng)建剖面線時,多邊形曲線和剖面線應(yīng)位于X / Y平面中,因此如果在相同但不是X / Y平面中有折線,則需要將它們“帶”到X / Y平面,創(chuàng)建聚陰影線,然后讓他們回到他們的平面。請看以下代碼:

     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 polylines
                gPoints pts1 = cir1.geomMeasure(7); // points of 1st polyline
                gPoints pts2 = cir2.geomMeasure(4); // points of 2nd polyline
                #endregion
    
                Matrix mat = new Matrix(); // this is the matrix of the plane that the circles belong to
                mat.SetToViewDirection(vec, 0.0d);
                Matrix invmat = new Matrix(mat.GetInvertion());
    
                // create the curves for the polyhatch
                vdPolyline 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 plane
                pl.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 plane
                
                VectorDraw.Professional.vdCollections.vdCurves curves_Inside = new VectorDraw.Professional.vdCollections.vdCurves();
                curves_Inside.AddItem(pl);
    
                //'create polyhatch
                vdPolyhatch 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 them
                cir1.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);
            }   

    三. 導(dǎo)出txt文件中的xyz坐標(biāo)

    問:如何將圖形中的折線和折線的x,y,z數(shù)據(jù)導(dǎo)出到txt文件中?

    答:VDF沒有自動化此功能,但很容易從加載到VDF組件的任意圖形中導(dǎo)出此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(" ");
                }
            }
        }
    }

    您所需要的只是循環(huán)遍歷文檔中的所有對象(線,折線等)并獲取其x,y,z值并使用StreamWriter將它們寫入txt文件。

    四. 如何覆蓋折線的夾點(diǎn)

    問:我想以不同的方式繪制折線的第一個夾點(diǎn)。我如何才能做到這一點(diǎn)?

    答:以下是使用FigureDrawGrips事件執(zhí)行此操作的示例:

    ..... // 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 color
            void 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 CS
     
                int i = 0;
                foreach (gPoint pt in pts)
                {
                    if (!render.IsSectionVisible(pt)) continue;//check the 3d section clip visibility
                    gPoint 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 CS
                    morigin.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-out
                    if (render.StatusDraw == vdRender.DrawStatus.Break) break;
                    i++;
                }
                render.IsMessageQueEmpty();//update the render StatusDraw by checking if a mouse action was placed by the user
                cancel = true;//do not call the default VectorDraw grip draw.
            }

    五. VDF滾動的鼠標(biāo)滾輪控制

    問:我想禁用鼠標(biāo)平移和鼠標(biāo)滾輪縮放,而不是使用滾輪,我想控制繪圖的滾動,水平和垂直。我如何才能做到這一點(diǎn)?

    答:您可以按照以下操作來禁用鼠標(biāo)中鍵平移和鼠標(biāo)滾輪放大/縮小。

    //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 used
                doc.MouseWheelZoomScale = 1.0d; // disable mouse wheel zoom
                
                doc.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 horizontally
                        doc.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
            }

     

    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    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); })();