예제 #1
0
 public static Vector3D ToVector3D(this netDxf.Vector2 v)
 {
     return(new Vector3D(v.X, v.Y));
 }
예제 #2
0
        //extract mark vectors from DXF
        public static void Extract_Vectors(string filename, string layer_name, float mark_speed)
        {
            List<MarkVector> list_of_vectors = new List<MarkVector>();
            DxfDocument dxf = LoadDXF(filename);

            if (dxf==null)
            {
                MessageBox.Show("netDXF extraction from DXF failed, trying line by line.");
                dxf = LineByLineLoader(filename);

                //need a text only loader for this.  Python or not?
            }
            if (dxf==null)
            {
                MessageBox.Show("Line by line processing failed");
                list_of_vectors = null;
                //return list_of_vectors;
            }

            int number = 0;
            netDxf.Vector2 previous_point = new netDxf.Vector2(0.0d, 0.0d);
            netDxf.Entities.LwPolylineVertex avertex = new netDxf.Entities.LwPolylineVertex();
            netDxf.Entities.PolylineVertex bvertex = new netDxf.Entities.PolylineVertex();
            //convert LWPolylines to Mark Vectors
            foreach(netDxf.Entities.LwPolyline apolyline in dxf.LwPolylines)
            {
                if(apolyline.Layer.Name ==layer_name || layer_name =="All")
                {
                    for(int i=0; i<apolyline.Vertexes.Count; i++)
                    {
                        avertex = apolyline.Vertexes[i];
                        if(i==0)
                        {
                            previous_point.X=avertex.Location.X;
                            previous_point.Y=avertex.Location.Y;
                        }
                        if (i!=0)
                        {
                            MarkVector aMarkVector = new MarkVector((float)previous_point.X, (float)previous_point.Y, (float)avertex.Location.X, (float)avertex.Location.Y);
                            list_of_vectors.Add(aMarkVector);
                            number++;
                            previous_point.X=avertex.Location.X;
                            previous_point.Y=avertex.Location.Y;
                        }

                    }
                    if(apolyline.IsClosed==true)
                    {
                        MarkVector aMarkVector = new MarkVector((float)previous_point.X, (float)previous_point.Y, (float)apolyline.Vertexes[0].Location.X, (float)apolyline.Vertexes[0].Location.X);
                        list_of_vectors.Add(aMarkVector);
                    }
                }
            }

            //convert polylines to Mark Vectors
            foreach(netDxf.Entities.Polyline apolyline in dxf.Polylines)
            {
                for(int i=0; i<apolyline.Vertexes.Count; i++)
                {
                    bvertex = apolyline.Vertexes[i];
                    if(i==0)
                    {
                        previous_point.X=bvertex.Location.X;
                        previous_point.Y=bvertex.Location.Y;
                    }
                    if (i!=0)
                    {
                        MarkVector aMarkVector = new MarkVector((float)previous_point.X, (float)previous_point.Y, (float)bvertex.Location.X, (float)bvertex.Location.Y);
                        list_of_vectors.Add(aMarkVector);
                        number++;
                        previous_point.X=avertex.Location.X;
                        previous_point.Y=avertex.Location.Y;
                    }

                }
                if(apolyline.IsClosed==true)
                {
                    MarkVector aMarkVector = new MarkVector((float)previous_point.X, (float)previous_point.Y, (float)apolyline.Vertexes[0].Location.X, (float)apolyline.Vertexes[0].Location.X);
                    list_of_vectors.Add(aMarkVector);
                }
            }

            //convert Lines to Mark Vectors
            foreach(netDxf.Entities.Line aline in dxf.Lines)
            {
                if(aline.Layer.Name ==layer_name || layer_name =="All")
                {
                    number++;
                    MarkVector aMarkVector = new MarkVector((float)aline.StartPoint.X, (float)aline.StartPoint.Y, (float)aline.EndPoint.X, (float)aline.EndPoint.Y);
                    list_of_vectors.Add(aMarkVector);
                }
            }

            //convert arcs
            foreach(netDxf.Entities.Arc an_arc in dxf.Arcs)
            {
                if(an_arc.Layer.Name ==layer_name || layer_name =="All")
                {
                    number++;
                    //////TO DO/////////////
                }
            }

            //convert circles
            foreach(netDxf.Entities.Circle aCircle in dxf.Circles)
            {
                if(aCircle.Layer.Name ==layer_name || layer_name =="All")
                {
                    number++;
                    //////TO DO/////////////
                }
            }

            //MessageBox.Show(number.ToString());
            //
            //return list_of_vectors;
            vector_list = list_of_vectors;
        }