Exemplo n.º 1
0
 protected bool Equals(OverlayConfig other)
 {
     return(MinOverlayArea.Equals(other.MinOverlayArea) && MinSourceArea.Equals(other.MinSourceArea) &&
            AspectRatio1.Equals(other.AspectRatio1) && AspectRatio2.Equals(other.AspectRatio2) &&
            Angle1.Equals(other.Angle1) && Angle2.Equals(other.Angle2) && MinSampleArea == other.MinSampleArea &&
            RequiredSampleArea == other.RequiredSampleArea && MaxSampleDiff.Equals(other.MaxSampleDiff) &&
            Subpixel == other.Subpixel && ScaleBase.Equals(other.ScaleBase) && Branches == other.Branches &&
            AcceptableDiff.Equals(other.AcceptableDiff) && Correction == other.Correction);
 }
Exemplo n.º 2
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = MinOverlayArea.GetHashCode();
         hashCode = (hashCode * 397) ^ MinSourceArea.GetHashCode();
         hashCode = (hashCode * 397) ^ AspectRatio1.GetHashCode();
         hashCode = (hashCode * 397) ^ AspectRatio2.GetHashCode();
         hashCode = (hashCode * 397) ^ Angle1.GetHashCode();
         hashCode = (hashCode * 397) ^ Angle2.GetHashCode();
         hashCode = (hashCode * 397) ^ MinSampleArea;
         hashCode = (hashCode * 397) ^ RequiredSampleArea;
         hashCode = (hashCode * 397) ^ MaxSampleDiff.GetHashCode();
         hashCode = (hashCode * 397) ^ Subpixel.GetHashCode();
         hashCode = (hashCode * 397) ^ ScaleBase.GetHashCode();
         hashCode = (hashCode * 397) ^ Branches;
         hashCode = (hashCode * 397) ^ AcceptableDiff.GetHashCode();
         hashCode = (hashCode * 397) ^ Correction;
         return(hashCode);
     }
 }
Exemplo n.º 3
0
        protected override void BuildProcessing(MillingCommandGenerator generator)
        {
            generator.ZSafety = ZSafety;
            if (MachineType.Value == CAM.MachineType.Donatoni)
            {
                generator.SetTool(2, Frequency, angleA: 90, hasTool: false);
            }
            else
            {
                generator.SetTool(1, Frequency, angleA: 0, hasTool: false);
            }

            var curves    = ProcessingArea.Select(p => p.ObjectId).QOpenForRead <Curve>().ToList();
            var bounds    = ProcessingArea.Select(p => p.ObjectId).GetExtents();
            var random    = new Random();
            var mainDir   = Vector3d.XAxis.RotateBy(Angle1.ToRad(), Vector3d.ZAxis);
            var side      = 1;
            var sign      = -1;
            var basePoint = bounds.MinPoint + (bounds.GetCenter() - bounds.MinPoint).GetNormal() * 100;

            using (var ray = new Ray())
                while (true)
                {
                    ray.BasePoint = basePoint;
                    ray.UnitDir   = mainDir.RotateBy(Angle2.ToRad() * side, Vector3d.ZAxis);
                    var points = ray.Intersect(curves).FindAll(p => p.DistanceTo(ray.BasePoint) > 10);
                    if (!points.Any())
                    {
                        break;
                    }

                    basePoint = points.First() + ray.UnitDir.Negate();
                    Cutting(ray.BasePoint, basePoint, ray.UnitDir, ray.UnitDir.GetPerpendicularVector() * side * sign);
                    side *= -1;
                }

            void Cutting(Point3d point1, Point3d point2, Vector3d dir, Vector3d pv)
            {
                var z = 0;

                if (generator.IsUpperTool)
                {
                    generator.Move(point1.X, point1.Y);
                    generator.GCommand(CommandNames.Cutting, 1, x: point1.X, y: point1.Y, z: ZEntry, feed: Feed / 5);
                    z = ZEntry;
                }
                var point0  = point1;
                var line    = new Line();
                var length  = point1.DistanceTo(point2);
                var l       = 0D;
                var a       = 0D;
                var count   = 10D;
                var stepA   = Math.PI / count;
                var stepL   = 0D;
                var amp     = 0;
                var isInner = true;

                while (l < length)
                {
                    if (Math.Abs(Math.Sin(a)) < Consts.Epsilon)
                    {
                        stepL = random.Next(StepMin, StepMax) / count;
                        amp   = random.Next(AmplitudeMin, AmplitudeMax);
                    }
                    l += stepL;
                    a += stepA;
                    var point = point1 + dir * l + pv * Math.Sin(a) * amp;
                    line.StartPoint = point0;
                    line.EndPoint   = point;
                    if (line.Intersect(curves).Any())
                    {
                        isInner = !isInner;
                    }
                    if (isInner)
                    {
                        if (z > 0)
                        {
                            z--;
                        }
                        generator.GCommand(CommandNames.Cutting, 1, x: point.X, y: point.Y, z: z, feed: Feed);
                    }
                    point0 = point;
                }
                line.Dispose();
                if (Math.Sin(a - stepA) > 0)
                {
                    sign = -sign;
                }
            }

            //var ray = new Ray
            //{
            //    BasePoint = new Point3d(bounds.MinPoint.X, 0, 0),
            //    UnitDir = Vector3d.YAxis
            //};
            //var uppDir = true;
            //var random = new Random();

            //while (true)
            //{
            //    var points = ray.Intersect(ProcessingArea.Select(p => p.ObjectId).QOpenForRead<Curve>().ToList(), Intersect.ExtendThis);
            //    if (points.Count == 0)
            //        break;
            //    if (points.Count > 1)
            //    {
            //        points = (uppDir ? points.OrderBy(p => p.Y) : points.OrderByDescending(p => p.Y)).ToList();
            //        Cutting(points.First(), points.Last());
            //    }
            //    ray.BasePoint += Vector3d.XAxis * Step1;
            //}

            //void Cutting(Point3d point1, Point3d point2)
            //{
            //    if (generator.IsUpperTool)
            //        generator.Move(point1.X, point1.Y);
            //    generator.GCommand(CommandNames.Cutting, 1, point: point1);

            //    var length = point1.DistanceTo(point2);
            //    var rnd = IsRandomStepCount ? (random.NextDouble() / 2 + 0.75) : 1;
            //    var countCycles = (int)Math.Round(length * rnd / Step2 / 2) * 2;
            //    var coodrs = Enumerable.Range(1, countCycles).Select(p => (double)p);
            //    if (IsRandomStepParams)
            //        coodrs = coodrs.Select(p => p + (p != countCycles ? (random.NextDouble() / 2 - 0.25) : 0));
            //    var coordArray = coodrs.ToArray();
            //    double l = 0;
            //    double a = 0;
            //    var count = 10;
            //    var stepA = Math.PI / count;
            //    for (int i = 0; i < coordArray.Length; i++)
            //    {
            //        var coord0 = i > 0 ? coordArray[i - 1] : 0;
            //        var dl = coordArray[i] - coord0;
            //        var stepL = dl * length / countCycles / count;

            //        foreach (var j in Enumerable.Range(1, count))
            //        {
            //            l += stepL;
            //            a += stepA;
            //            var point = point1 + new Vector3d(Math.Sin(a) * Amplitude * dl, uppDir ? l : -l, 0);
            //            generator.GCommand(CommandNames.Cutting, 1, point: point, feed: Feed);
            //        }
            //    }

            //while(true)
            //{
            //    cnt++;
            //    if (length - l < 2 * Step2)
            //    {

            //    }
            //    var rnd = random.Next(5, 10) / 10D;
            //    foreach (var i in Enumerable.Range(0, 10))
            //    {
            //        var point = point1 + new Vector3d(Math.Sin(a) * Amplitude * rnd, uppDir ? l : -l, 0);
            //        generator.GCommand(CommandNames.Cutting, 1, point: point, feed: Feed);
            //        l += stepL / 10 * rnd;
            //        a += stepA / 10;
            //    }
            //}


            //foreach (var i in Enumerable.Range(0, count))
            //{
            //    var point = point1 + new Vector3d(Math.Sin(a) * Amplitude, uppDir ? l : -l, 0);
            //    generator.GCommand(CommandNames.Cutting, 1, point: point, feed: Feed);
            //    l += stepL;
            //    a += stepA;
            //}
            //    uppDir = !uppDir;
            //}
        }
Exemplo n.º 4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            double OffsetX, OffsetY;
            double LeftTopMX = Convert.ToDouble(txtLeftTopMX.Text.Trim()) * PublicVar.CHXCaliCorr;
            double LeftTopMY = Convert.ToDouble(txtLeftTopMX.Text.Trim()) * PublicVar.CHYCaliCorr;
            double LeftTopCX = Convert.ToDouble(txtLeftTopCX.Text.Trim());
            double LeftTopCY = Convert.ToDouble(txtLeftTopCX.Text.Trim());
            double LeftTopSX = Convert.ToDouble(txtLeftTopSX.Text.Trim());
            double LeftTopSY = Convert.ToDouble(txtLeftTopSX.Text.Trim());

            OffsetX    = -(LeftTopCX - nWidth / 2) * PublicVar.CameraX_Unit;
            OffsetY    = -(LeftTopCY - nHeight / 2) * PublicVar.CameraY_Unit;
            LeftTopMX += OffsetX;
            LeftTopMY += OffsetY;
            double LeftBottomMX = Convert.ToDouble(txtLeftBottomMX.Text.Trim()) * PublicVar.CHXCaliCorr;
            double LeftBottomMY = Convert.ToDouble(txtLeftBottomMX.Text.Trim()) * PublicVar.CHYCaliCorr;
            double LeftBottomCX = Convert.ToDouble(txtLeftBottomCX.Text.Trim());
            double LeftBottomCY = Convert.ToDouble(txtLeftBottomCX.Text.Trim());
            double LeftBottomSX = Convert.ToDouble(txtLeftBottomSX.Text.Trim());
            double LeftBottomSY = Convert.ToDouble(txtLeftBottomSX.Text.Trim());

            OffsetX       = -(LeftBottomCX - nWidth / 2) * PublicVar.CameraX_Unit;
            OffsetY       = -(LeftBottomCY - nHeight / 2) * PublicVar.CameraY_Unit;
            LeftBottomMX += OffsetX;
            LeftBottomMY += OffsetY;
            double RightTopMX = Convert.ToDouble(txtLeftTopMX.Text.Trim()) * PublicVar.CHXCaliCorr;
            double RightTopMY = Convert.ToDouble(txtLeftTopMX.Text.Trim()) * PublicVar.CHYCaliCorr;
            double RightTopCX = Convert.ToDouble(txtLeftTopCX.Text.Trim());
            double RightTopCY = Convert.ToDouble(txtLeftTopCX.Text.Trim());
            double RightTopSX = Convert.ToDouble(txtLeftTopSX.Text.Trim());
            double RightTopSY = Convert.ToDouble(txtLeftTopSX.Text.Trim());

            OffsetX     = -(RightTopCX - nWidth / 2) * PublicVar.CameraX_Unit;
            OffsetY     = -(RightTopCY - nHeight / 2) * PublicVar.CameraY_Unit;
            RightTopMX += OffsetX;
            RightTopMY += OffsetY;
            double RightBottomMX = Convert.ToDouble(txtLeftBottomMX.Text.Trim()) * PublicVar.CHXCaliCorr;
            double RightBottomMY = Convert.ToDouble(txtLeftBottomMX.Text.Trim()) * PublicVar.CHYCaliCorr;
            double RightBottomCX = Convert.ToDouble(txtLeftBottomCX.Text.Trim());
            double RightBottomCY = Convert.ToDouble(txtLeftBottomCX.Text.Trim());
            double RightBottomSX = Convert.ToDouble(txtLeftBottomSX.Text.Trim());
            double RightBottomSY = Convert.ToDouble(txtLeftBottomSX.Text.Trim());

            OffsetX        = -(RightBottomCX - nWidth / 2) * PublicVar.CameraX_Unit;
            OffsetY        = -(RightBottomCY - nHeight / 2) * PublicVar.CameraY_Unit;
            RightBottomMX += OffsetX;
            RightBottomMY += OffsetY;

            double x1, y1, x2, y2, a1, b1, a2, b2, Angle1, Angle2;

            x1     = LeftTopSX - LeftBottomSX;
            y1     = LeftTopSY - LeftBottomSY;
            x2     = RightBottomSX - LeftBottomSX;
            y2     = RightBottomSY - LeftBottomSY;
            a1     = LeftTopMX - LeftBottomMX;
            b1     = LeftTopMY - LeftBottomMY;
            a2     = RightBottomMX - LeftBottomMX;
            b2     = RightBottomMY - LeftBottomMY;
            Angle1 = (y1 * b2 - y2 * b1) / (a1 * b2 - a2 * b1);
            Angle1 = Math.Asin(Angle1) * 180 / 3.14159;
            Angle2 = (x1 * a2 - x2 * a1) / (b1 * a2 - b2 * a1);
            Angle2 = Math.Asin(Angle2);
            double x3, y3;
            double angleX, angleY;

            angleX      = Angle1 * 3.14159 / 180;
            angleY      = Angle2 * 3.14159 / 180;
            x3          = RightTopMX * Math.Cos(angleX) + RightTopMY * Math.Sin(angleY);
            y3          = RightTopMY * Math.Cos(angleY) + RightTopMX * Math.Sin(angleX);
            labelX.Text = x3.ToString("f6");
            labelY.Text = y3.ToString("f6");
            if (MessageBox.Show("确认保存吗?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                string strPath;
                strPath = Application.StartupPath + "\\DOC";
                if (!Directory.Exists(strPath))
                {
                    Directory.CreateDirectory(strPath);
                }
                strPath += "\\Setting.ini";
                CIni IniSetting = new CIni(strPath);
                IniSetting.IniWriteValue("CHX", "RepairAngle", Angle1.ToString("f6"));
                IniSetting.IniWriteValue("CHY", "RepairAngle", Angle1.ToString("f6"));
                PublicVar.CHXRepairAngle = Angle1;
                PublicVar.CHYRepairAngle = Angle2;
            }
        }