コード例 #1
0
ファイル: Reader.cs プロジェクト: echicerman/cncmatic
        //private Circle ReadEsfera(ref ParCodigoValor code)
        //{
        //    var circle = new Circle();
        //    Vector3f center = Vector3f.Zero;
        //    Vector3f normal = Vector3f.UnitZ;
        //    Dictionary<ApplicationRegistry, XData> xData = new Dictionary<ApplicationRegistry, XData>();
        //    code = this.ReadCodePair();
        //    while (code.Code != 0)
        //    {
        //        switch (code.Code)
        //        {
        //            case 5:
        //                circle.Handle = code.Value;
        //                code = this.ReadCodePair();
        //                break;
        //            case 8: //layer code
        //                circle.Layer = this.GetLayer(code.Value);
        //                code = this.ReadCodePair();
        //                break;
        //            case 62: //aci color code
        //                circle.Color = new AciColor(short.Parse(code.Value));
        //                code = this.ReadCodePair();
        //                break;
        //            case 6: //type line code
        //                circle.LineType = this.GetLineType(code.Value);
        //                code = this.ReadCodePair();
        //                break;
        //            case 10:
        //                center.X = float.Parse(code.Value);
        //                code = this.ReadCodePair();
        //                break;
        //            case 20:
        //                center.Y = float.Parse(code.Value);
        //                code = this.ReadCodePair();
        //                break;
        //            case 30:
        //                center.Z = float.Parse(code.Value);
        //                code = this.ReadCodePair();
        //                break;
        //            case 40:
        //                circle.Radius = float.Parse(code.Value);
        //                code = this.ReadCodePair();
        //                break;
        //            case 39:
        //                circle.Thickness = float.Parse(code.Value);
        //                code = this.ReadCodePair();
        //                break;
        //            case 210:
        //                normal.X = float.Parse(code.Value);
        //                code = this.ReadCodePair();
        //                break;
        //            case 220:
        //                normal.Y = float.Parse(code.Value);
        //                code = this.ReadCodePair();
        //                break;
        //            case 230:
        //                normal.Z = float.Parse(code.Value);
        //                code = this.ReadCodePair();
        //                break;
        //            case 1001:
        //                XData xDataItem = this.ReadXDataRecord(code.Value, ref code);
        //                xData.Add(xDataItem.ApplicationRegistry, xDataItem);
        //                break;
        //            default:
        //                if (code.Code >= 1000 && code.Code <= 1071)
        //                    throw new DxfInvalidCodeValueEntityException(code.Code, code.Value, this.file,
        //                                                                 "The extended data of an entity must start with the application registry code " + this.fileLine);
        //                code = this.ReadCodePair();
        //                break;
        //        }
        //    }
        //    circle.XData = xData;
        //    circle.Center = center;
        //    circle.Normal = normal;
        //    return circle;
        //}
        private Elipse ReadElipse(ref ParCodigoValor code)
        {
            var ellipse = new Elipse();
            Vector3f center = Vector3f.Nulo;
            Vector3f axisPoint = Vector3f.Nulo;
            Vector3f normal = Vector3f.UnitarioZ;
            float ratio = 0;
            //Dictionary<ApplicationRegistry, XData> xData = new Dictionary<ApplicationRegistry, XData>();

            code = this.ReadCodePair();
            while (code.Cod != 0)
            {
                switch (code.Cod)
                {
                    case 5:
                        ellipse.Handle = code.Val;
                        code = this.ReadCodePair();
                        break;
                    //case 8: //layer code
                    //    ellipse.Layer = this.GetLayer(code.Val);
                    //    code = this.ReadCodePair();
                    //    break;
                    //case 62: //aci color code
                    //    ellipse.Color = new AciColor(short.Parse(code.Val));
                    //    code = this.ReadCodePair();
                    //    break;
                    //case 6: //type line code
                    //    ellipse.LineType = this.GetLineType(code.Val);
                    //    code = this.ReadCodePair();
                    //    break;
                    case 10:
                        center.X = float.Parse(code.Val);
                        code = this.ReadCodePair();
                        break;
                    case 20:
                        center.Y = float.Parse(code.Val);
                        code = this.ReadCodePair();
                        break;
                    case 30:
                        center.Z = float.Parse(code.Val);
                        code = this.ReadCodePair();
                        break;
                    case 11:
                        axisPoint.X = float.Parse(code.Val);
                        code = this.ReadCodePair();
                        break;
                    case 21:
                        axisPoint.Y = float.Parse(code.Val);
                        code = this.ReadCodePair();
                        break;
                    case 31:
                        axisPoint.Z = float.Parse(code.Val);
                        code = this.ReadCodePair();
                        break;
                    case 40:
                        ratio = float.Parse(code.Val);
                        code = this.ReadCodePair();
                        break;
                    case 41:
                        ellipse.AnguloInicio = (float)(double.Parse(code.Val) * MathHelper.RadToDeg);
                        code = this.ReadCodePair();
                        break;
                    case 42:
                        ellipse.AnguloFin = (float)(double.Parse(code.Val) * MathHelper.RadToDeg);
                        code = this.ReadCodePair();
                        break;
                    case 210:
                        normal.X = float.Parse(code.Val);
                        code = this.ReadCodePair();
                        break;
                    case 220:
                        normal.Y = float.Parse(code.Val);
                        code = this.ReadCodePair();
                        break;
                    case 230:
                        normal.Z = float.Parse(code.Val);
                        code = this.ReadCodePair();
                        break;
                    //case 1001:
                    //    XData xDataItem = this.ReadXDataRecord(code.Value, ref code);
                    //    xData.Add(xDataItem.ApplicationRegistry, xDataItem);
                    //    break;
                    default:
                        if (code.Cod >= 1000 && code.Cod <= 1071)
                            throw new DxfInvalidCodeValueEntityException(code.Cod, code.Val, this.archivo,
                                                                         "The extended data of an entity must start with the application registry code " + this.fileLine);
                        code = this.ReadCodePair();
                        break;
                }
            }

            Vector3d ocsAxisPoint = MathHelper.Transform((Vector3d)axisPoint,
                                                         (Vector3d)normal,
                                                         MathHelper.CoordinateSystem.World,
                                                         MathHelper.CoordinateSystem.Object);
            double rotacion = (float)Vector2d.AngleBetween(Vector2d.UnitarioX, new Vector2d(ocsAxisPoint.X, ocsAxisPoint.Y));

            ellipse.EjeMayor = 2 * axisPoint.Modulus();
            ellipse.EjeMenor = ellipse.EjeMayor * ratio;
            ellipse.Rotacion = (float)(rotacion * MathHelper.RadToDeg);
            ellipse.Centro = center;
            ellipse.Normal = normal;
            //ellipse.XData = xData;
            return ellipse;
        }
コード例 #2
0
ファイル: Traduce.cs プロジェクト: echicerman/cncmatic
        public static void calculaElipse(Elipse elip, int precision)
        {
            float angulo = elip.AnguloInicio;
            Vector2d pi = ElipsePunto(elip.Centro.X, elip.Centro.Y, elip.EjeMayor / 2, elip.EjeMenor / 2, angulo, elip.Rotacion);
            double phi = ElipseTang(elip.EjeMayor / 2, elip.EjeMenor / 2, angulo, elip.Rotacion);

            List<Vector2d> puntos = new List<Vector2d>();
            List<double> tans = new List<double>();

            puntos.Insert(0, pi);
            tans.Insert(0, phi);

            int i = 1;
            float theta = elip.AnguloFin - elip.AnguloInicio;

            while (i <= precision)
            {
                //theta = 360 * i / precision;

                angulo += theta / precision;

                puntos.Insert(i, ElipsePunto(elip.Centro.X, elip.Centro.Y, elip.EjeMayor / 2, elip.EjeMenor / 2, angulo, elip.Rotacion));
                tans.Insert(i, ElipseTang(elip.EjeMayor / 2, elip.EjeMenor / 2, angulo, elip.Rotacion));
                i++;
            }
            return;
        }