• <menu id="w2i4a"></menu>
  • logo VectorDraw教程

    文檔首頁(yè)>>VectorDraw教程>>新手入門必看:VectorDraw 常見(jiàn)問(wèn)題整理大全(十八)

    新手入門必看:VectorDraw 常見(jiàn)問(wèn)題整理大全(十八)


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

    VectorDraw Developer Framework最新版下載

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

    VectorDraw web library (javascript)最新版下載

    一. 按圖層更改實(shí)體的順序

    問(wèn):我想更改某些實(shí)體的順序,以便在2D中繪制其他實(shí)體。例如,層“TEXT”和“DIMS”中的vdTexts和vdDimensions對(duì)象我想將它們?cè)O(shè)置為實(shí)體列表的后面,以便它們?cè)谄渌麑?shí)體之上繪制。我嘗試在for ...循環(huán)中使用ChangeOrder方法,但速度非常慢。我怎么才能更快地做到這一點(diǎn)?

    答:繪制對(duì)象的順序定義如下:

    - 在2D中:添加的最后一個(gè)對(duì)象(在實(shí)體列表中,而不是在圖層列表中)繪制在上一個(gè)對(duì)象的頂部

    - 在3D中:對(duì)象的坐標(biāo)指定哪個(gè)將在頂部。

    因此,在2D中,你必須要更改這些實(shí)體的順序才行。你可以使用InsertAt / RemoveAt和ChangeOrder方法或交換方法來(lái)交換集合中兩個(gè)對(duì)象的位置。在Wrapper中,你可以使用ChangeOrder / MoveBefore / MoveAfter Subs。

    如果你要檢查很多圖層和實(shí)體,而不是使用ChangeOrder或Swap,那么你可以嘗試以下代碼:

                    vdArray<vdLayer> layers = new vdArray<vdLayer>();
                    layers.AddItem(doc.Layers.FindName("1")); // here you add the layers with the order you want
                    layers.AddItem(doc.Layers.FindName("DIMS"));  // the order of the layers here is significant
                    layers.AddItem(doc.Layers.FindName("TEXTS"));  // and defines the order that the entities will have and drawn in 2D
    
                    // if the drawing has the layers 0, 1, 2, 3, TEXTS, 4, DIMS, 5 then then entities draw order in 2D after 
                    // this code will be [entities in any layers 0,2,3,4,5][entities in Layer 1][entities in layer DIMS][entities in Layer TEXTS]
    
                    layers.MakeIndexDictionary(); // speeds up swaping and search 
                    doc.Model.Entities.MakeIndexDictionary(); // speeds up swaping and search
                    int pos1 = 0;
                    int pos2 = 0;
                    for (int i = 0; i < doc.Model.Entities.Count; i++)
                    {
                        vdFigure fig1 = doc.Model.Entities[i];
                        pos1 = layers.GetObjectRealPosition(fig1.Layer);
                        for (int k = i + 1; k < doc.Model.Entities.Count; k++)
                        {
                            vdFigure fig2 = doc.Model.Entities[k];
                            pos2 = layers.GetObjectRealPosition(fig2.Layer);
                            
                            if (pos1 > pos2) 
                            {
                                doc.Model.Entities.swap(fig1, fig2);
                            }
                        }
                    }
                    doc.Model.Entities.ClearIndexDictionary(); // must follow a doc.Model.Entities.MakeIndexDictionary
                    layers.ClearIndexDictionary(); // must follow a layers.MakeIndexDictionary

    或者,你可以使用排序類并對(duì)數(shù)組中的所有實(shí)體(System.Collections.ArrayList)進(jìn)行排序,并將這些實(shí)體(已排序)重新添加回繪圖,如:

            internal class ItemSort : System.Collections.IComparer
            {
                vdFigure mfig;
                int mpos;
                ulong handle;
                public ulong Handle { get { return handle; } }
                public vdFigure Fig { get { return mfig; } }
                public ItemSort() { }
                public ItemSort(vdFigure fig, int pos)
                {
                    mfig = fig;
                    mpos = pos;
                    handle = mfig.Handle.Value; // Keep the handle because the RemoveAll sets the handle to 0 !!
                }
                public int Compare(object x, object y)
                {
                    return (((ItemShort)x).mpos - ((ItemShort)y).mpos);
                }
            }
    .....
                    vdArray<vdLayer> layers = new vdArray<vdLayer>();
                    layers.AddItem(doc.Layers.FindName("0")); // here you add the layers with the order you want
                    layers.AddItem(doc.Layers.FindName("2")); // here you add the layers with the order you want
                    layers.AddItem(doc.Layers.FindName("1")); // here you add the layers with the order you want
                    layers.AddItem(doc.Layers.FindName("DIMS"));  // the order of the layers here is significant
                    layers.AddItem(doc.Layers.FindName("TEXTS"));  // and defines the order that the entities will have and drawn in 2D
    
                    // if the drawing has the layers 0, 1, TEXTS, 2 and DIMS then then entities draw order in 2D after 
                    // this code will be [entities in any layer 0][entities in any layer 2][entities in Layer 1][entities in layer DIMS][entities in Layer TEXTS]
    
    
                    layers.MakeIndexDictionary(); // speeds up swaping and search 
                    System.Collections.ArrayList lst = new System.Collections.ArrayList();
                    foreach (vdFigure fig in doc.Model.Entities)
                    {
                        lst.Add(new ItemShort(fig, layers.GetObjectRealPosition(fig.Layer)));
                    }
                    layers.ClearIndexDictionary();
                    lst.Sort(new ItemSort()); // sort items
                    doc.Model.Entities.RemoveAll(); //remove all entities from the model that have the "bad order"
                    foreach (ItemShort item in lst)
                    {
                        item.Fig.Handle.InternalSetValue(item.Handle); // set the handle back cause it is lost with RemoveAll
                        doc.Model.Entities.AddItem(item.Fig); //and re-add the entities with the order 
                    }

    在版本6019Beta7及更高版本中,有一種新方法Sort()可用于代替上述代碼段。詳情如下:

    在版本6019中,在vdArray對(duì)象和vdEntities集合中添加了新的排序方法。代碼如下:

    VectorDraw.Generics.vdArray<T> sort methods
            /// <summary>
            /// Sorts the elements in an entire collection using the <see cref="System.IComparable<T>"/>
            ///     generic interface implementation of each element of the System.Array.
            /// </summary>
            /// <exception cref="System.InvalidOperationException">One or more elements in array do not implement the <see cref="System.IComparable<T>"/>  generic interface.</exception>
            public void Sort()
    
            example:
            sort items in a collection of doubles
                    vdArray<double> collectionOfDoubles = new vdArray<double>();
                    collectionOfDoubles.AddItem(5);
                    collectionOfDoubles.AddItem(15);
                    collectionOfDoubles.AddItem(2);
                    collectionOfDoubles.AddItem(8);
                    collectionOfDoubles.AddItem(3);
    
                    //sort the items from smaller value to bigger
                    collectionOfDoubles.Sort();
                    //the values will be take the following order
                    //2 ,3, 5, 8, 15
    
     
    
    
            /// <summary>
            ///  Sorts the elements in a range of elements in entire collection using the specified
            ///     <see cref="System.Collections.Generic.IComparer<T>"/> generic interface.
            /// </summary>
            /// <param name="comparer">
            /// The <see cref="System.Collections.Generic.IComparer<T>"/> generic interface implementation
            ///     to use when comparing elements, or null to use the <see cref="System.IComparable<T>"/>
            ///     generic interface implementation of each element.
            /// </param>
            /// <exception cref="System.ArgumentException">
            /// The implementation of comparer caused an error during the sort. 
            /// For example, comparer might not return 0 when comparing an item with itself.
            /// </exception>
            /// <exception cref="System.InvalidOperationException">
            /// comparer is null, and one or more elements in array do not implement the <see cref="System.IComparable<T>"/>  generic interface
            /// </exception>
            public void Sort(IComparer<T> comparer)
            example:
            sort items in a collection of gPoints depend of their distance from an origin point.
    
    
                     private class OriginComparer : System.Collections.Generic.IComparer<gPoint>
                     {
                        gPoint mOrigin;
                        public OriginComparer(gPoint Origin)
                        {
                            mOrigin = Origin;
                        }
                        public int Compare(gPoint x, gPoint y)
                        {
                            double dif = x.Distance3D(mOrigin) - y.Distance3D(mOrigin);
                            if (dif == 0.0d) return 0;
                            if (dif > 0.0d) return 1;
                            else return -1;
                        }
                     }
             
                    vdArray<gPoint> collectionOfPoints = new vdArray<gPoint>();
                    collectionOfPoints.AddItem(new gPoint(5,0,0));
                    collectionOfPoints.AddItem(new gPoint(15, 0, 0));
                    collectionOfPoints.AddItem(new gPoint(2, 0, 0));
                    collectionOfPoints.AddItem(new gPoint(8, 0, 0));
                    collectionOfPoints.AddItem(new gPoint(3, 0, 0));
    
                    //sort the items from smaller to bigger depend of their distance from point(0,0,0)
                    collectionOfPoints.Sort(new OriginComparer(new gPoint(0, 0, 0)));
                    //the values will be take the following order
                    //(2,0,0) ,(3,0,0), (5,0,0), (8,0,0), (15,0,0)
    
    
    VectorDraw.Professional.vdCollections.vdEntities sort methods
            /// <summary>
            ///  Sorts the elements in a range of elements in entire collection using the specified
            ///     <see cref="System.Collections.Generic.IComparer<vdFigure>"/> generic interface.
            /// </summary>
            /// <param name="comparer">
            /// The <see cref="System.Collections.Generic.IComparer<vdFigure>"/> generic interface implementation
            ///     to use when comparing elements, or null to use the <see cref="System.IComparable<vdFigure>"/>
            ///     generic interface implementation of each element.
            /// </param>
            /// <exception cref="System.ArgumentException">
            /// The implementation of comparer caused an error during the sort. 
            /// For example, comparer might not return 0 when comparing an item with itself.
            /// </exception>
            /// <exception cref="System.InvalidOperationException">
            /// comparer is null, and one or more elements in array do not implement the <see cref="System.IComparable<vdFigure>"/>  generic interface
            /// </exception>
            public void Sort(IComparer<vdFigure> comparer)
            example:
            sort items in vdEntities collection depend of their Layer name.
                      //a class object that used to compare to vdFigure depend of the Layer Name
                      private class FigureLayerComparer : System.Collections.Generic.IComparer<vdFigure>
                      {
                        public FigureLayerComparer()
                        {
                        }
                        public int Compare(vdFigure fig1, vdFigure fig2)
                        {
                            return System.StringComparer.InvariantCultureIgnoreCase.Compare(fig1.Layer.ToString(), fig2.Layer.ToString());
                        }
                      }
                    //Create 4 layers and add them into the Layers collection of a vdDocument object
                    vdLayer lay1 = doc.Layers.Add("1");
                    vdLayer lay2 = doc.Layers.Add("2");
                    vdLayer lay3 = doc.Layers.Add("3");
                    vdLayer lay4 = doc.Layers.Add("4");
    
                    //create a new vdLine object that belong to Layer with name "3"
                    vdLine l1 = new vdLine();
                    l1.SetUnRegisterDocument(doc);
                    l1.setDocumentDefaults();
                    l1.Layer = lay3;
    
                   //create a new vdLine object that belong to Layer with name "1"
                    vdLine l2 = new vdLine();
                    l2.SetUnRegisterDocument(doc);
                    l2.setDocumentDefaults();
                    l2.Layer = lay1;
    
                    //create a new vdLine object that belong to Layer with name "4"
                    vdLine l3 = new vdLine();
                    l3.SetUnRegisterDocument(doc);
                    l3.setDocumentDefaults();
                    l3.Layer = lay4;
    
                    //create a new vdLine object that belong to Layer with name "2"
                    vdLine l4 = new vdLine();
                    l4.SetUnRegisterDocument(doc);
                    l4.setDocumentDefaults();
                    l4.Layer = lay2;
    
                    //add the new vdlines to vdDocument Model Entities collection
                    doc.Model.Entities.AddItem(l1);
                    doc.Model.Entities.AddItem(l2);
                    doc.Model.Entities.AddItem(l3);
                    doc.Model.Entities.AddItem(l4);
    
                    //change the order of items in the collection so the items of layer "1" to be first in the collection folow by items in layer "2" , "3" and "4" at the end of the collection
                    doc.Model.Entities.Sort(new FigureLayerComparer());
    

    二. 制作復(fù)制命令以執(zhí)行所選項(xiàng)目的多個(gè)副本

    問(wèn):如何制作復(fù)制命令以執(zhí)行所選項(xiàng)目的多個(gè)副本。例如,復(fù)制完選擇后,復(fù)制命令不會(huì)結(jié)束,并且保持活動(dòng)狀態(tài)以繼續(xù)復(fù)制相同的選擇活動(dòng)?

    答:你可以通過(guò)創(chuàng)建自己的命令來(lái)完成此操作。在這種情況下,請(qǐng)嘗試以下代碼:

            private void button2_Click(object sender, EventArgs e)
            {
                bool flag = MultipleCopy(vdFramedControl1.BaseControl.ActiveDocument);
                this.Text = flag.ToString();
            }
    
            private Boolean MultipleCopy(vdDocument doc)
            {
                bool isCopy = true;
                doc.Prompt("Select Entities to copy: ");
                if (!doc.CommandAction.CmdSelect("USER"))
                {
                    doc.Prompt("");
                    return false;
                }
                vdSelection sel = doc.Selections.FindName("VDRAW_PREVIOUS_SELSET");
                if ((sel == null) | (sel.Count < 1)) return false;
                doc.Prompt("Copy from Point: ");
                gPoint ptFrom = doc.ActionUtility.getUserPoint() as gPoint;
                if ((ptFrom == null))
                {
                    doc.Prompt("");
                    return false;
                }
                int i = 0;
                while (isCopy)
                {
                    isCopy = doc.CommandAction.CmdCopy(sel, ptFrom, "USER");
                    if ((i==0) & (isCopy==false))
                    {
                     doc.Prompt("");
                     return false;
                    }
                    i++;
                }
                doc.Prompt("");
                return true;
            }

    未完待續(xù)~

    熱門活動(dòng)

    *點(diǎn)擊圖片查看活動(dòng)詳情*

    ABViewer免費(fèi)送

    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

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