Пример #1
0
        ///// <summary>
        ///// Raccorda elementi 2D dove primo elemento è linea e secondo è arco.
        ///// </summary>
        ///// <param name="line"></param>
        ///// <param name="arc"></param>
        ///// <param name="radiusValue"></param>
        ///// <param name="radiusSuccess"></param>
        ///// <returns></returns>
        //private static IEnumerable<IEntity2D> CreateChamfer(Line2D line, Arc2D arc, double radiusValue, out bool radiusSuccess)
        //{
        //    Arc2D filletArc = null;

        //    var rsl = GeometryHelper.FilletEntity(arc, line, radiusValue, true, out filletArc);


        //    if (rsl)
        //    {
        //        var lineWithRadius = new List<IEntity2D>();

        //        arc.Start = filletArc.End;
        //        line.End = filletArc.Start;

        //        lineWithRadius.Add(line);
        //        lineWithRadius.Add(filletArc);

        //        foreach (var entity2D in lineWithRadius)
        //            entity2D.PlotStyle = line.PlotStyle;


        //        radiusSuccess = true;
        //        return lineWithRadius;
        //    }

        //    radiusSuccess = false;
        //    return null;

        //}

        /// <summary>
        /// Risolve il profilo, se ci sono problemi ritorna profilo fino al problema.
        /// Poi dice dove è errore, dove metto errore ? nel IRawMove2D ??
        /// </summary>
        /// <returns></returns>
        public Profile2D GetProfileResult(bool closed)
        {
            /*
             * closed indica se il profilo che serve è chiuso o meno..
             *
             * è già settato con costruttore.
             *
             */

            if (Count == 0)
            {
                return(null);
            }

            var rslt = UpdateCycle();

            var profile = new Profile2D();

            foreach (var entity2D in rslt)
            {
                profile.AddEntity(entity2D);
            }

            return(profile);
        }
Пример #2
0
        public Profile2D GetClosedProfile()
        {
            var interasseArc = new Arc2D()
            {
                Center = new Point2D(CentroX, CentroY)
            };

            var clockWise = false;

            var angoloStartRad = GeometryHelper.DegreeToRadian(AngoloStart);
            var angoloEndRad   = GeometryHelper.DegreeToRadian(AngoloStart + AngoloAmpiezza);

            interasseArc.Radius    = RaggioInterasse;
            interasseArc.ClockWise = false;

            interasseArc.Start = GeometryHelper.GetCoordinate(angoloStartRad, RaggioInterasse);
            interasseArc.End   = GeometryHelper.GetCoordinate(angoloEndRad, RaggioInterasse);

            var offset = Larghezza / 2;
            var arc1   = GeometryHelper.GetParallel(interasseArc, offset, true);

            arc1.ClockWise = false;
            var arc2 = GeometryHelper.GetParallel(interasseArc, offset, false);

            arc2.ClockWise = true;

            var temp = arc2.Start;

            arc2.Start = arc2.End;
            arc2.End   = temp;

            var arcEndCaps = new Arc2D()
            {
                Center    = interasseArc.End,
                ClockWise = true,
                Start     = arc1.End,
                End       = arc2.Start,
                Radius    = Larghezza / 2,
            };

            var arcStartCaps = new Arc2D()
            {
                Center    = interasseArc.Start,
                ClockWise = true,
                Start     = arc2.End,
                End       = arc1.Start,
                Radius    = Larghezza / 2,
            };

            var profile2D = new Profile2D();

            profile2D.AddEntity(arc1);
            profile2D.AddEntity(arcEndCaps);
            profile2D.AddEntity(arc2);
            profile2D.AddEntity(arcStartCaps);

            arc1.PlotStyle = arc2.PlotStyle = arcStartCaps.PlotStyle = arcEndCaps.PlotStyle = EnumPlotStyle.Element;
            return(profile2D);
        }
Пример #3
0
        private static double GetRoughIniDiameter(Profile2D profile2D, Tornitura.TipoTornitura tipoTornitura)
        {
            if (tipoTornitura == Tornitura.TipoTornitura.Esterna)
            {
                return(GetUpperDiameter(profile2D));
            }

            return(GetLowestDiameter(profile2D));
        }
Пример #4
0
        public static Profile2D GetSquareProfile(double centerX, double centerY, double width, double height)
        {
            var pp1 = new Point2D(centerX + width / 2, centerY + height / 2);
            var pp2 = new Point2D(centerX + width / 2, centerY - height / 2);
            var pp3 = new Point2D(centerX - width / 2, centerY - height / 2);
            var pp4 = new Point2D(centerX - width / 2, centerY + height / 2);

            var polygon = new Profile2D();

            polygon.AddPnt(pp1);
            polygon.AddPnt(pp2);
            polygon.AddPnt(pp3);
            polygon.AddPnt(pp4);
            polygon.AddPnt(pp1);

            return(polygon);
        }
Пример #5
0
        private static Point2D FindIntersectionPoint(Profile2D profile2D, Line2D segment)
        {
            /*
             * assumo che il profilo non ha insenature o altre pippe ho solo un punto di contatto.
             */
            var s = profile2D.Source;

            foreach (var entity2D in s)
            {
                Point2D o;
                if (Geometry.GeometryHelper.Entity2DIntersection(entity2D, segment, out o))
                {
                    return(o);
                }
            }

            return(null);
        }
Пример #6
0
        private static double GetUpperDiameter(Profile2D profile2D)
        {
            var s   = profile2D.Source;
            var max = double.MinValue;

            foreach (var entity2D in s)
            {
                var p  = entity2D.GetFirstPnt();
                var p1 = entity2D.GetLastPnt();

                if (p.Y > max)
                {
                    max = p.Y;
                }

                if (p1.Y > max)
                {
                    max = p1.Y;
                }
            }
            return(max);
        }
Пример #7
0
        public Profile2D GetClosedProfile()
        {
            var cerchio = new Arc2D
            {
                Center    = new Point2D(CentroX, CentroY),
                Radius    = Raggio,
                ClockWise = false,
                Start     = { X = CentroX + Raggio },
                End       = { X = CentroX + Raggio },
            };


            cerchio.Start.Y = CentroY;
            cerchio.End.Y   = CentroY;


            var profile2D = new Profile2D();

            profile2D.AddEntity(cerchio);

            cerchio.PlotStyle = EnumPlotStyle.Element;
            return(profile2D);
        }
Пример #8
0
        private static double GetMaxZ(Profile2D profile2D)
        {
            var s = profile2D.Source;

            var maxZ = double.MinValue;

            foreach (var entity2D in s)
            {
                var p  = entity2D.GetFirstPnt();
                var p1 = entity2D.GetLastPnt();

                if (p.X > maxZ)
                {
                    maxZ = p.X;
                }

                if (p1.X > maxZ)
                {
                    maxZ = p1.X;
                }
            }

            return(maxZ);
        }
Пример #9
0
        private static double GetMinZ(Profile2D profile2D)
        {
            var s = profile2D.Source;

            var min = double.MaxValue;

            foreach (var entity2D in s)
            {
                var p  = entity2D.GetFirstPnt();
                var p1 = entity2D.GetLastPnt();

                if (p.X < min)
                {
                    min = p.X;
                }

                if (p1.X < min)
                {
                    min = p1.X;
                }
            }

            return(min);
        }
Пример #10
0
        internal static void GetSgrossaturaInterna(PathGenerator.MoveActionCollection moveCollection, Profile2D profile2D, double profPassata, double avvicinamento, double stacco, bool useMacro)
        {
            /*
             * assumo anche che nel profilo non ci siano tasche..
             */
            var diaIniziale = GetRoughIniDiameter(profile2D, Tornitura.TipoTornitura.Interna);

            var diaFinale = GetRoughFinDiameter(profile2D, Tornitura.TipoTornitura.Interna);

            var zMin = GetMinZ(profile2D);

            var zIniziale = GetMaxZ(profile2D) + avvicinamento;

            var r = stacco;

            var currentDia = diaIniziale;

            moveCollection.AddLinearMove(MoveType.Work, AxisAbilited.Xyz, zIniziale, currentDia, 0);
            while (currentDia < diaFinale)
            {
                currentDia += profPassata;
                if (currentDia >= diaFinale)
                {
                    currentDia = diaFinale;
                }

                var scanIniPoint = new Point2D(zIniziale, currentDia);
                var scanEndPoint = new Point2D(zMin, currentDia);

                var scanLine = new Line2D()
                {
                    Start = scanIniPoint, End = scanEndPoint
                };

                var intersectPoint = FindIntersectionPoint(profile2D, scanLine);

                if (intersectPoint == null)
                {
                    break;
                }

                moveCollection.AddLinearMove(MoveType.Work, AxisAbilited.Xyz, zIniziale, currentDia, 0);


                moveCollection.AddLinearMove(MoveType.Work, AxisAbilited.Xyz, intersectPoint.X, null, 0);

                moveCollection.AddLinearMove(MoveType.Rapid, AxisAbilited.Xyz, zIniziale, currentDia - avvicinamento, 0);

                //var line = new Line2D() {Start = iniPoint, End = intersectPoint};

                // poi devo fare stacco , ritorno a z e incremento diametro.
            }
        }
Пример #11
0
            internal static IEnumerable <Profile2D> ElaboratePathData(PathGeometry p1, Point2D startPoint)
            {
                /*
                 * La matrice di rotazione serve solamente a correggere il comportamento strano ( testo rovesciato) ottenuto dalla trasformazione in geometria del testo.
                 */
                var matrix = new Matrix3D();

                matrix.RotateAt(new Quaternion(new Vector3D(1, 0, 0), 180),
                                new System.Windows.Media.Media3D.Point3D(0, startPoint.Y, 0));



                var profiles = new List <Profile2D>();

                foreach (var figure in p1.Figures)
                {
                    var profile = new Profile2D();

                    profiles.Add(profile);

                    var d = figure.Segments;

                    foreach (var l in d)
                    {
                        if (l is PolyLineSegment)
                        {
                            var pl  = l as PolyLineSegment;
                            var pts = pl.Points;

                            foreach (var pnt in pts)
                            {
                                profile.AddPnt(new Point2D(pnt.X, pnt.Y), matrix);
                            }

                            if (pts.Count > 0)
                            {
                                profile.AddPnt(new Point2D(pts[0].X, pts[0].Y), matrix);
                            }

                            continue;
                        }
                        else if (l is PolyBezierSegment)
                        {
                            var pl  = l as PolyBezierSegment;
                            var pts = pl.Points;

                            foreach (var pnt in pts)
                            {
                                profile.AddPnt(new Point2D(pnt.X, pnt.Y), matrix);
                            }

                            //if (pts.Count > 0)
                            //    profile.AddPnt(new Point2D(pts[0].X, pts[0].Y));

                            continue;
                        }

                        else if (l is LineSegment)
                        {
                            var pl = l as LineSegment;

                            profile.AddPnt(new Point2D(pl.Point.X, pl.Point.Y), matrix);

                            continue;
                        }

                        else if (l is BezierSegment)
                        {
                            var pl = l as BezierSegment;

                            /*
                             * todo , calcolare bezier da 3 point
                             */
                            profile.AddPnt(new Point2D(pl.Point1.X, pl.Point1.Y), matrix);
                            profile.AddPnt(new Point2D(pl.Point2.X, pl.Point3.Y), matrix);
                            profile.AddPnt(new Point2D(pl.Point2.X, pl.Point3.Y), matrix);

                            continue;
                        }

                        //if (!(l is PolyLineSegment))
                        //{
                        Debug.Fail("XamlDataManager.ElaboratePathData");
                        throw new Exception("XamlDataManager.ElaboratePathData");
                        //}
                    }
                }
                return(profiles);
            }
Пример #12
0
        private void ElaborateAllargaturaBareno(ProgramOperation programPhase, Operazione operazione)
        {
            var opBarenatura = operazione.Lavorazione as IBarenoAble;

            if (opBarenatura == null)
            {
                throw new NullReferenceException();
            }

            var pntListBar = GetDrillPointList();

            var moveCollection = new MoveActionCollection();

            var iniZ = InizioZ;

            var endZ = InizioZ - opBarenatura.ProfonditaBareno;

            var fresa = operazione.Utensile as FresaCandela;

            var parametro = operazione.Utensile.ParametroUtensile as ParametroFresaCandela;

            var larghezzaPassata = parametro.GetLarghezzaPassata();

            var profPassata = parametro.GetProfonditaPassata();

            var diaAllargatura = opBarenatura.DiametroBarenatura - opBarenatura.MaterialePerFinitura;

            if (InizioZ <= endZ)
            {
                return;
            }
            if (fresa.Diametro > diaAllargatura)
            {
                return;
            }

            foreach (var point2D in pntListBar)
            {
                // Semplice)
                if (opBarenatura.ModalitaAllargatura == 0)
                {
                    var profile = Profile2D.CreateCircle(diaAllargatura / 2, point2D);

                    moveCollection.AddLinearMove(MoveType.Rapid, AxisAbilited.Xy, point2D.X,
                                                 point2D.Y, null, null);

                    MillProgrammingHelper.GetInternRoughing(moveCollection, profile, opBarenatura.ProfonditaBareno,
                                                            profPassata, larghezzaPassata, fresa.Diametro, 0, InizioZ, SicurezzaZ, 0, 0);

                    moveCollection.AddLinearMove(MoveType.Rapid, AxisAbilited.Xy, point2D.X,
                                                 point2D.Y, null, null);
                }

                // Interpolazione
                else if (opBarenatura.ModalitaAllargatura == 1)
                {
                    MillProgrammingHelper.GetRoughHelicalInterpolation(moveCollection, InizioZ, endZ, SicurezzaZ, point2D,
                                                                       diaAllargatura, fresa.Diametro, profPassata, larghezzaPassata);
                }
            }

            foreach (var a in moveCollection)
            {
                programPhase.AggiungiAzioneMovimento(a);
            }
        }
Пример #13
0
        /// <summary>
        /// Come anteprima creo rettangolo..
        /// </summary>
        /// <returns></returns>
        protected override List <IEntity3D> GetFinalPreview()
        {
            var diaExt = MaschiaturaSelezionata.DiametroMetrico;
            var passo  = MaschiaturaSelezionata.Passo;
            var diaMin = diaExt - passo;
            var zIni   = ZIniziale;
            var zEnd   = ZIniziale - LunghezzaFiletto;

            var p = new Profile2D();

            var l1 = new Line2D
            {
                Start = new Point2D
                {
                    X = zIni,
                    Y = diaExt,
                },

                End = new Point2D
                {
                    X = zEnd,
                    Y = diaExt,
                }
            };

            var l2 = new Line2D
            {
                Start = l1.End,

                End = new Point2D
                {
                    X = zEnd,
                    Y = diaMin,
                }
            };

            var l3 = new Line2D
            {
                Start = l2.End,

                End = new Point2D
                {
                    X = zIni,
                    Y = diaMin,
                }
            };

            var l4 = new Line2D
            {
                Start = l3.End,
                End   = l1.Start,
            };

            p.AddEntity(l1);
            p.AddEntity(l2);
            p.AddEntity(l3);
            p.AddEntity(l4);

            p.SetPlotStyle();

            var l = Entity3DHelper.Get3DProfile(p.Source);

            return(new List <IEntity3D>(l));
        }
Пример #14
0
        /*
         * Magari aggiungere inclinazione
         */

        public Profile2D GetClosedProfile()
        {
            var profile = Profile2D.CreateCavaLineare(Radius, LunghezzaCentri, new Point2D(CentroX, CentroY));

            return(profile);
        }
Пример #15
0
        internal static void GetFinishingProgram(PathGenerator.MoveActionCollection moveCollection, Profile2D profile2D, Tornitura.TipoTornitura tipoTornitura, double avvicinamento)
        {
            var s = profile2D.Source;

            var f = s.FirstOrDefault();

            if (f == null)
            {
                return;
            }

            var iniP = f.GetFirstPnt();

            moveCollection.AddLinearMove(MoveType.Rapid, AxisAbilited.Xyz, iniP.X + avvicinamento, iniP.Y, 0);

            foreach (var move in s)
            {
                if (move is Line2D)
                {
                    var m = move as Line2D;
                    var p = m.GetLastPnt();
                    moveCollection.AddLinearMove(MoveType.Work, AxisAbilited.Xyz, p.X, p.Y, 0);
                }
                else if (move is Arc2D)
                {
                    var m = move as Arc2D;

                    var p = m.GetLastPnt();

                    moveCollection.AddArcMove(AxisAbilited.Xyz, p.X, p.Y, 0, m.Radius, m.ClockWise, m.Center);
                }
            }

            moveCollection.AddLinearMove(MoveType.Rapid, AxisAbilited.Xyz, iniP.X + avvicinamento, null, null);
        }
        /*
         * mi serve
         * 1- metodo che mi restituisca i profili calcolati
         *
         *
         *
         */

        //private static List<Profile2D> CalculateInternOffset(Profile2D origin, double offsetValue, double diameterValue)
        //{
        //    offsetValue = -Math.Abs(offsetValue);

        //    var firstPaths = origin.Offset(-diameterValue, false);

        //    if (firstPaths == null)
        //        return null;

        //    var rslt = new List<Profile2D>();

        //    foreach (var firstPath in firstPaths)
        //    {
        //        rslt.Add(firstPath);

        //        RicorsivaGenerateInternOffset(firstPath, offsetValue, false, ref rslt);
        //    }


        //    return rslt;
        //}

        //private static void RicorsivaGenerateInternOffset(Profile2D profile2D, double offset, bool clockwise, ref List<Profile2D> profile2DsList)
        //{
        //    // Calcola offset , ritorna 1 o più contorni
        //    var offsetRslt = profile2D.Offset(offset, clockwise);


        //    // se non ritorna più niente termina metodo
        //    if (offsetRslt == null)
        //        return;

        //    foreach (var singleContour in offsetRslt)
        //    {
        //        profile2DsList.Add(singleContour);
        //        RicorsivaGenerateInternOffset(singleContour, offset, clockwise, ref profile2DsList);
        //    }
        //}



        private static void FresaturaSmussaturaScanalaturaChiusaProgram(MoveActionCollection moveActionCollection, Profile2D profile2D, double profonditaSmusso, double zSicurezza, double zIniziale, double diaFresa, double larghezzaScanaltura)
        {
            /*
             * teoria.
             * - Prendo profilo
             *  - Se valido faccio offset negativo del raggio della fresa
             * - Poi faccio offset della larghezza di passata fino a che il metodo non mi restituisce più niente. ( ho raggiunto il massimo )
             */

            /*
             * Controllo Valori
             */
            if (CheckValueHelper.GreatherThanZero(new[] { profonditaSmusso, diaFresa, larghezzaScanaltura }) ||
                CheckValueHelper.GreatherThan(new[]
            {
                new KeyValuePair <double, double>(zSicurezza, zIniziale),
            })
                )
            {
                return;
            }

            if (profile2D == null)
            {
                return;
            }

            /*
             * chiamo metodo comune per 2 profili (maggiore e minore della fresatura di scanalatura)
             */
            var offsetValue = larghezzaScanaltura / 2;

            var profileExt = profile2D.Offset(offsetValue, true);
            var profileInt = profile2D.Offset(-offsetValue, true);

            if ((profileExt == null || profileExt.Count == 0) ||
                (profileInt == null || profileInt.Count == 0))
            {
                return;
            }

            MillProgrammingHelper.GetExterChamfer(moveActionCollection, profileInt[0], null, false, profonditaSmusso, diaFresa, 0, false, zIniziale, zSicurezza);

            MillProgrammingHelper.GetInternChamfer(moveActionCollection, profileExt[0], profonditaSmusso, diaFresa, 0, false, zIniziale, zSicurezza);
        }
Пример #17
0
        protected override void CreateSpecificProgram(ProgramOperation programPhase, Operazione operazione)
        {
            /*
             * utensile e parametro lo prendo all'interno del cambio switch..
             */
            var fresa = operazione.Utensile as FresaCandela;

            var parametro = operazione.Utensile.ParametroUtensile as ParametroFresaCandela;

            if (fresa == null || parametro == null)
            {
                throw new NullReferenceException();
            }

            if (PatternDrilling == null)
            {
                return;
            }
            var diameter = DiametroMetricoFinale;

            var pntList = PatternDrilling.GetPointList();

            if (pntList == null || pntList.Count <= 0)
            {
                return;
            }

            var diaFresa = fresa.Diametro;


            var moveCollection = new MoveActionCollection();

            var workUp   = InizioLavorazioneZ;
            var workDown = InizioLavorazioneZ - ProfonditaLavorazione;

            foreach (var point2D in pntList)
            {
                switch (operazione.OperationType)
                {
                case LavorazioniEnumOperazioni.Smussatura:
                {
                    var profile = Profile2D.CreateCircle(DiametroMetricoFinale / 2, point2D);

                    MillProgrammingHelper.GetInternChamfer(moveCollection, profile, ProfonditaSvasatura, diaFresa, 0, false, InizioLavorazioneZ, SicurezzaZ);
                } break;

                case LavorazioniEnumOperazioni.FresaturaFilettare:
                {
                    var helicalRadius = (diameter - diaFresa) / 2;

                    if (FilettaturaSinistra && !FilettaturaEsterna)
                    {
                        //MillProgrammingHelper.GetInternThreadSx(moveCollection, );
                        MillProgrammingHelper.GetInternThreadSx(moveCollection, workUp, workDown, SicurezzaZ, point2D, PassoMetrico, DiametroMetricoFinale / 2, true);
                    }
                    else if (!FilettaturaSinistra && !FilettaturaEsterna)
                    {
                        MillProgrammingHelper.GetInternThreadDx(moveCollection, workUp, workDown, SicurezzaZ, point2D, PassoMetrico, DiametroMetricoFinale / 2, true);
                    }

                    else if (!FilettaturaSinistra && FilettaturaEsterna)
                    {
                        var extracorsa = diaFresa / 2 + ExtraCorsa;

                        MillProgrammingHelper.GetExternThreadDx(moveCollection, workUp, workDown, SicurezzaZ, point2D, PassoMetrico, DiametroMetricoFinale / 2, true, extracorsa);
                    }

                    else if (FilettaturaSinistra && FilettaturaEsterna)
                    {
                        var extracorsa = diaFresa / 2 + ExtraCorsa;

                        MillProgrammingHelper.GetExternThreadSx(moveCollection, workUp, workDown, SicurezzaZ, point2D, PassoMetrico, DiametroMetricoFinale / 2, true, extracorsa);
                    }
                }
                break;

                default:
                    throw  new Exception("FresaturaFilettatura.CreateSpecificProgram");
                    break;
                }
            }
            var mm = base.GetFinalProgram(moveCollection);

            foreach (var variable in mm)
            {
                programPhase.AggiungiAzioneMovimento(variable);
            }
        }
Пример #18
0
        internal static void GetRoughingTurnProgram(ProgramOperation programOperation, MoveActionCollection moveCollection, Profile2D profile2D, double profPassata, double avvicinamento, double stacco, Tornitura.TipoTornitura tipoTornitura, bool useMacro, double sovraX, double sovraZ)
        {
            // assumo che sia diametro esterno.

            if (CheckValueHelper.GreatherThanZero(new[] { profPassata, }))
            {
                return;
            }

            if (profile2D == null)
            {
                return;
            }

            if (useMacro)
            {
                var turnMacro = new MacroLongitudinalTurningAction(programOperation)
                {
                    SovraMetalloX        = sovraX,
                    SovraMetalloZ        = sovraZ,
                    Profile              = profile2D,
                    ProfonditaPassata    = profPassata,
                    Distacco             = stacco,
                    TipologiaLavorazione = tipoTornitura,
                };
            }

            switch (tipoTornitura)
            {
            case Tornitura.TipoTornitura.Esterna:
            {
                GetSgrossaturaEsterna(programOperation, moveCollection, profile2D, profPassata, avvicinamento, stacco);
            } break;

            case Tornitura.TipoTornitura.Interna:
            {
                GetSgrossaturaInterna(moveCollection, profile2D, profPassata, avvicinamento, stacco, useMacro);
            } break;
            }
        }