示例#1
0
 public Arc(netDxf.Entities.Arc dxfArc)
     : this
     ((Point)dxfArc.Center
      , dxfArc.StartAngle
      , dxfArc.EndAngle
      , dxfArc.Radius)
 {
 }
        Entity ReadArc(netDxf.Entities.Arc arc, double x, double y)
        {
            Arc c = new Arc();

            c.center     = new CADPoint(arc.Center.X + x, arc.Center.Y + y);
            c.radius     = arc.Radius;
            c.startAngle = arc.StartAngle;
            c.endAngle   = arc.EndAngle;

            return(c);
        }
示例#3
0
        public netDxf.Entities.EntityObject ToDXFEntity()
        {
            netDxf.Entities.Arc dxfArc = new netDxf.Entities.Arc()
            {
                Center = this.Center.ToDXFVertex3(),
                Radius = this.Radius,
                Color = this._color.A != 0? new netDxf.AciColor(this.Color) : netDxf.AciColor.ByLayer,
                LineType = DXFLineTypeConverter.Convert(this.LineType)
            };

            if (this.StartAng < this.EndAng)
            {
                dxfArc.StartAngle = RadToDeg(this.StartAng);
                dxfArc.EndAngle = RadToDeg(this.EndAng);
            }
            else
            {
                dxfArc.StartAngle = RadToDeg(this.EndAng);
                dxfArc.EndAngle = RadToDeg(this.StartAng);
            }
            return dxfArc;
        }
示例#4
0
        //Method to parse DXF line by line when LoadDXF fails
        public static DxfDocument LineByLineLoader(string filename)
        {
            vector_list.Clear();

            DxfDocument dxfdata = new DxfDocument();
            List<string> list_of_strings = new List<string>();
            //reset logic function
            reset_logic();

            entity_count =0;
            double intermediate =0.0d;  //used for nullable exchange
            int int_intermediate =0;

            bool in_block = false;
            bool in_entities =false;
            int LineCount  =0;
            string coder_string ="";
            string a_string ="";
            string layer_string ="";

            Vector2 start_point = new Vector2(0,0);
            Vector2 end_point = new Vector2(0,0);

            try
            {
                string line = null;
                bool found_file_end =false;
                System.IO.TextReader readFile = new StreamReader(filename);
                while (found_file_end==false)
                {
                    line = readFile.ReadLine();
                    if (line != null)
                    {
                        list_of_strings.Add(line);
                    }
                    else
                    {
                        found_file_end=true;
                    }
                }
                readFile.Close();
                readFile = null;
            }
               	    catch(Exception e)
            {
                error_string=e.ToString();
                return dxfdata;
            }

               	    for(int i=0;i<list_of_strings.Count; i+=2)   //read strings in pairs - first is code - second is value
               	    {
                LineCount = LineCount+1;
                coder_string = list_of_strings[i].Trim();
                try
                {
                    a_string = list_of_strings[i+1].Trim();
                }
                catch
                {
                    a_string="";
                }

                //check location in structure - only read from entities section
                if (coder_string =="0" && a_string=="BLOCK")
                {
                    in_block=true;
                }
                if(coder_string =="2" && a_string=="ENTITIES")
                {
                    in_entities=true;
                }
                if(coder_string =="0" && a_string=="ENDBLK")
                {
                    in_block=false;
                }
                if(coder_string =="0" && a_string=="ENDSEC")
                {
                    in_entities=false;
                }

                //read in layer info
                if(coder_string=="8" && in_block==false &&  in_entities==true && (ReadingLine==true || ReadingPolyline == true ||ReadingArc==true || ReadingCircle == true))
                {
                   layer_string = a_string;
                   FoundNewLayer=true;
                    //could populate a layer list here if needed

                }
                //read data
                if(coder_string=="10")
                {
                    double.TryParse(a_string, out intermediate);
                    X1=(double?)intermediate;
                }

                if (coder_string=="11")
                {
                    double.TryParse(a_string, out intermediate);
                    X2=(double?)intermediate;
                }

                if(coder_string=="20")
                {
                    double.TryParse(a_string, out intermediate);
                    Y1=(double?)intermediate;
                }

                if(coder_string=="21")
                {
                    double.TryParse(a_string, out intermediate);
                    Y2=(double?)intermediate;
                }

                if(coder_string=="40")
                {
                    double.TryParse(a_string, out intermediate);
                    radius=(double?)intermediate;
                }

                if(coder_string=="50")
                {
                    double.TryParse(a_string, out intermediate);
                    start_angle=(double?)intermediate;
                }

                if(coder_string=="51")
                {
                    double.TryParse(a_string, out intermediate);
                    end_angle=(double?)intermediate;
                }

                if(coder_string=="70")
                {
                    if(ReadingPolyline==true)
                    {
                        if(a_string=="1")
                        {
                            polyline_closed=true;
                        }
                        else
                        {
                            polyline_closed=false;
                        }
                    }
                }
                if(coder_string=="90")
                {
                    if(ReadingPolyline==true)
                    {
                        int.TryParse(a_string, out int_intermediate);
                        PointCount = (int?)int_intermediate;
                    }

                }

               	//flag start of a line
               	if(coder_string =="0" && a_string=="LINE" && in_block==false && in_entities==true)
               	{
               		if(ReadingLine==false)
               		{
                        reset_logic();
                        ReadingLine = true;
               		}
                    else
                    {
                        reset_logic();
                    }
               	}
                //add line if data complete
                if(ReadingLine==true && X1!=null && Y1 !=null && X2 !=null && Y2 != null)
                {
                    start_point = new Vector2((double)X1,(double)Y1);
                    end_point = new Vector2((double)X2,(double)Y2);

                    netDxf.Entities.Line aLine = new netDxf.Entities.Line(start_point,end_point);

                    aLine.Layer = new netDxf.Tables.Layer(layer_string);

                    dxfdata.AddEntity(aLine);
                    reset_logic();

                    entity_count++;
                }

                //flag start of a LWPOLYLINE
                if(coder_string =="0" && a_string=="LWPOLYLINE" && in_block==false && in_entities==true)
                {
                    if(ReadingPolyline == false)
                    {
                        reset_logic();
                        ReadingPolyline = true;
                    }
                    else
                    {
                        reset_logic();
                    }
                }

                //add point to polyline
                if(ReadingPolyline==true && X1 !=null && Y1!=null)
                {
                    netDxf.Entities.LwPolylineVertex aVertex = new netDxf.Entities.LwPolylineVertex(new Vector2((double)X1,(double)Y1),0.0d);

                    points.Add(aVertex);
                    X1 = null;
                    Y1 = null;
                }

                //add polyline if have enough points

                if(ReadingPolyline==true && points.Count==PointCount && PointCount !=null)
                {
                    netDxf.Entities.LwPolyline aPolyline = new netDxf.Entities.LwPolyline(points,polyline_closed);
                    aPolyline.Layer= new netDxf.Tables.Layer(layer_string);
                    dxfdata.AddEntity(aPolyline);
                    reset_logic();
                    entity_count++;

                }

                //flag star of a ARC
                if(coder_string =="0" && a_string=="ARC" && in_block == false)
                {
                    if(ReadingArc==false)
                    {
                        reset_logic();
                        ReadingArc = true;
                    }
                    else
                    {
                        reset_logic();
                    }
                }

                //add arc if data complete
                if(ReadingArc==true && X1 != null && Y1 !=null && radius !=null && start_angle != null && end_angle !=null)
                {
                    Vector2 center = new Vector2((double)X1,(double)Y1);
                    netDxf.Entities.Arc aArc = new netDxf.Entities.Arc(center,(double)radius,(double)start_angle,(double)end_angle);
                    aArc.Layer= new netDxf.Tables.Layer(layer_string);
                    dxfdata.AddEntity(aArc);
                    reset_logic();
                    entity_count++;
                }

                //flag star of a CIRCLE
                if (coder_string =="0" && a_string=="CIRCLE" && in_block ==false)
                {
                    if (ReadingArc==false)
                    {
                        reset_logic();
                        ReadingCircle =true;
                    }
                    else
                    {
                        reset_logic();
                    }
                }

                //add circle if data complete
                if(ReadingCircle==true && X1 !=null && Y1 !=null && radius != null)
                {
               			Vector2 center = new Vector2((double)X1,(double)Y1);
               			netDxf.Entities.Circle aCircle = new netDxf.Entities.Circle(center,(double)radius);
                    aCircle.Layer= new netDxf.Tables.Layer(layer_string);
                    dxfdata.AddEntity(aCircle);
                    reset_logic();
                    entity_count++;
                }

               	    }

            return dxfdata;
        }