Beispiel #1
0
 public PathAdapter(ItemPath path)
 {
     _path = path;
 }
 public ItemPathWrapper(ItemPath itemPath)
 {
     _itemPath = itemPath;
 }
        public static void CalculateTangentialAxis()
        {
            const uint loggerSelect      = (uint)LogEnable.PathModification;
            double     maxAngleChangeDeg = (double)Properties.Settings.Default.importGCTangentialAngle;
            bool       limitRange        = Properties.Settings.Default.importGCTangentialRange;

            double maxAngleRad = maxAngleChangeDeg * Math.PI / 180;     // in RAD
            double angleNow, angleLast, angleOffset, angleApply, angleLastApply;

            finalPathList = new List <PathObject>();    // figures of one tile
            ItemPath tempPath = new ItemPath();
            Point    pStart, pEnd;

            Logger.Trace("...CalculateTangentialAxis maxAngle:{0}", maxAngleChangeDeg);
            gcodeMath.resetAngles();

            foreach (PathObject graphicItem in completeGraphic)
            {
                angleLast   = angleApply = angleLastApply = 0;
                angleOffset = 0;
                if (!(graphicItem is ItemDot))
                {
                    ItemPath item = (ItemPath)graphicItem;

                    if (item.path.Count == 0)
                    {
                        continue;
                    }

                    pStart = item.path[0].MoveTo;

                    /* copy general info */
                    actualDashArray = new double[0];
                    if (item.dashArray.Length > 0)
                    {
                        actualDashArray = new double[item.dashArray.Length];
                        item.dashArray.CopyTo(actualDashArray, 0);
                    }

                    tempPath = new ItemPath(new Point(pStart.X, pStart.Y));     // create new path
                    tempPath.Info.CopyData(graphicItem.Info);                   // preset global info for GROUP
                    if (actualDashArray.Length > 0)                             // set dash array
                    {
                        tempPath.dashArray = new double[actualDashArray.Length];
                        actualDashArray.CopyTo(tempPath.dashArray, 0);
                    }

                    for (int i = 1; i < item.path.Count; i++)                   // go through path objects
                    {
                        pStart = item.path[i - 1].MoveTo;
                        pEnd   = item.path[i].MoveTo;

                        /* Process Line */
                        if (item.path[i] is GCodeLine)
                        {
                            angleNow = gcodeMath.getAlpha(pStart, pEnd);      // angle-i = p[i-1] to p[i] in radiant

                            //                            if ((loggerTrace & loggerSelect) > 0) Logger.Trace("    TangentialAxis diff:{0:0.00} now:{1:0.00}  last:{2:0.00} offfset:{3:0.00}  ", diff, angleNow,angleLast, angleOffset);

                            if (i == 1)
                            {
                                angleLast           = item.path[0].Angle = angleNow;
                                tempPath.StartAngle = angleNow;
                                angleLastApply      = angleApply = angleNow;
                            }

                            if ((logFlags & loggerSelect) > 0)
                            {
                                Logger.Trace("    before angleNow:{0:0.00}  angleLast:{1:0.00} angleApply:{2:0.00}  offset:{3:0.00}", (angleNow * 180 / Math.PI), (angleLast * 180 / Math.PI), (angleApply * 180 / Math.PI), (angleOffset * 180 / Math.PI));
                            }

                            double diff = angleNow - angleLast; // + angleOffset;
                            if (diff > Math.PI)
                            {
                                angleOffset -= 2 * Math.PI;
                            }
                            else if (diff < -Math.PI)
                            {
                                angleOffset += 2 * Math.PI;
                            }
                            angleApply = angleNow + angleOffset;

                            if ((logFlags & loggerSelect) > 0)
                            {
                                Logger.Trace("    after  angleNow:{0:0.00}  angleLast:{1:0.00} angleApply:{2:0.00}  offset:{3:0.00}", (angleNow * 180 / Math.PI), (angleLast * 180 / Math.PI), (angleApply * 180 / Math.PI), (angleOffset * 180 / Math.PI));
                            }

                            item.path[i].Angle = angleApply;
                            //		if ((loggerTrace & loggerSelect) > 0) Logger.Trace("    TangentialAxis Line   X:{0:0.00} Y:{1:0.00}  end X:{2:0.00} Y:{3:0.00}  angleNow:{4:0.00}  angleApply:{5:0.00}  offset:{6:0.00}", pStart.X, pStart.Y, pEnd.X, pEnd.Y, (angleNow * 180 / Math.PI), (angleApply * 180 / Math.PI), (angleOffset* 180 / Math.PI));

                            /* split path if swivel angle is reached*/
                            if ((Math.Abs(angleLastApply - angleApply) > maxAngleRad) || fixAngleExceed(ref angleApply, ref angleNow, ref angleOffset))         // change in angle is too large -> insert pen up/turn/down -> seperate path
                            {
                                if (tempPath.path.Count > 1)
                                {
                                    finalPathList.Add(tempPath);                // save prev path, start new path to force pen up/turn/down
                                }
                                if ((logFlags & loggerSelect) > 0)
                                {
                                    Logger.Trace("      Exceed angle max:{0:0.00}  actual:{1:0.00}", (maxAngleRad * 180 / Math.PI), (Math.Abs(angleLast - angleNow) * 180 / Math.PI));
                                }

                                tempPath = new ItemPath(new Point(pStart.X, pStart.Y));     // start new path with clipped start position
                                tempPath.Info.CopyData(graphicItem.Info);                   // preset global info for GROUP
                                if (actualDashArray.Length > 0)                             // set dash array
                                {
                                    tempPath.dashArray = new double[actualDashArray.Length];
                                    actualDashArray.CopyTo(tempPath.dashArray, 0);
                                }
                                tempPath.Add(pEnd, item.path[i].Depth, angleApply);
                                tempPath.StartAngle = angleApply;
                            }
                            else
                            {
                                tempPath.Add(pEnd, item.path[i].Depth, angleApply);
                            }                            // add point and angle

                            angleLast      = angleApply; //angleNow;
                            angleLastApply = angleApply;
                        }
                        else
                        /* Process Arc   implement fixAngleExceed(ref angleApply, ref angleNow, ref angleOffset)?*/
                        {
                            double offset = +Math.PI / 2;        // angle-i = center to p[i] + 90° it is the tangente
                            double aStart = 0;
                            if (!((GCodeArc)item.path[i]).IsCW)
                            {
                                offset = -offset;
                            }                                                                                                  // angleStart-i = center to p[i-1] + 90°

                            Point center = new Point(pStart.X + ((GCodeArc)item.path[i]).CenterIJ.X, pStart.Y + ((GCodeArc)item.path[i]).CenterIJ.Y);

                            aStart = gcodeMath.getAngle(pStart, center, offset, 0);     // angle of tangente
                            if (i == 1)
                            {
                                angleLast           = item.path[0].Angle = aStart;
                                tempPath.StartAngle = aStart;
                            }

                            double diff = aStart - angleLast;   // + angleOffset;
                            if (diff > Math.PI)
                            {
                                angleOffset -= 2 * Math.PI;
                            }
                            else if (diff < -Math.PI)
                            {
                                angleOffset += 2 * Math.PI;
                            }
                            angleApply = aStart + angleOffset;

                            //             if (loggerTrace) Logger.Trace(" Tang Circle a-start:{0:0.00} a-end:{1:0.00}  ", (angle * 180 / Math.PI));
                            ((GCodeArc)item.path[i]).AngleStart = angleApply;

                            angleNow = gcodeMath.getAngle(pEnd, center, offset, 0);
                            diff     = angleNow - angleLast;     //+ angleOffset;
                            if (diff > Math.PI)
                            {
                                angleOffset -= 2 * Math.PI;
                            }
                            else if (diff < -Math.PI)
                            {
                                angleOffset += 2 * Math.PI;
                            }
                            angleApply = angleNow + angleOffset;

                            ((GCodeArc)item.path[i]).Angle = angleApply;
                            if ((logFlags & loggerSelect) > 0)
                            {
                                Logger.Trace("    Tangential Circle X:{0:0.00} Y:{1:0.00}  end X:{2:0.00} Y:{3:0.00}  angleStart:{4:0.00} angleEnd:{5:0.00}", pStart.X, pStart.Y, pEnd.X, pEnd.Y, (aStart * 180 / Math.PI), (angleNow * 180 / Math.PI));
                            }

                            if (Math.Abs(angleLast - angleNow) > maxAngleRad)                     // change in angle is too large -> insert pen up/turn/down -> seperate path
                            {
                                if (tempPath.path.Count > 1)
                                {
                                    finalPathList.Add(tempPath);                        // save prev path, start new path to force pen up/turn/down
                                }
                                tempPath = new ItemPath(new Point(pStart.X, pStart.Y)); // start new path with clipped start position
                                tempPath.Info.CopyData(graphicItem.Info);               // preset global info for GROUP
                                if (actualDashArray.Length > 0)
                                {
                                    tempPath.dashArray = new double[actualDashArray.Length];
                                    actualDashArray.CopyTo(tempPath.dashArray, 0);
                                }
                            }
                            else
                            {
                                tempPath.AddArc((GCodeArc)item.path[i], aStart, angleApply, item.path[i].Depth);
                            }                                                                                                   // add point and angle
                        }
                        angleLast = angleNow;
                    }
                    if (tempPath.path.Count > 1)
                    {
                        finalPathList.Add(tempPath);                       // save prev path
                    }
                }
                else
                /* Process Dot */
                {
                    ItemDot dot = new ItemDot(graphicItem.Start.X, graphicItem.Start.Y);
                    dot.Info.CopyData(graphicItem.Info);              // preset global info for GROUP
                    finalPathList.Add(dot);
                    if ((logFlags & loggerSelect) > 0)
                    {
                        Logger.Trace("   Clip Dot copied");
                    }
                }
            }
            completeGraphic.Clear();
            foreach (PathObject item in finalPathList)     // add tile to full graphic
            {
                completeGraphic.Add(item);
            }
        }
        public static void DragToolModification(List <PathObject> graphicToModify)
        {
            const uint loggerSelect    = (uint)LogEnable.PathModification;
            double     gcodeDragRadius = (double)Properties.Settings.Default.importGCDragKnifeLength;

            /*       if (Properties.Settings.Default.importGCDragKnifePercentEnable)
             *     {   gcodeDragRadius = Math.Abs((double)Properties.Settings.Default.importGCZDown * (double)Properties.Settings.Default.importGCDragKnifePercent / 100); }
             */
            double gcodeDragAngle = (double)Properties.Settings.Default.importGCDragKnifeAngle;

            Logger.Trace("...DragToolModification radius:{0:0.00} angle:{1:0.00}", gcodeDragRadius, gcodeDragAngle);
            ListGraphicObjects(graphicToModify, true);

            List <PathObject> modifiedGraphic = new List <PathObject>();

            foreach (PathObject item in graphicToModify) // replace original list?
            {
                if (item is ItemPath)                    // if Dot: nothing to correct
                {
                    Point    origMoveTo, center, shorten;
                    double   a, a1, a2;
                    ItemPath opath = (ItemPath)item;
                    if (opath.path.Count > 1)
                    {
                        origMoveTo           = opath.path[0].MoveTo;
                        gcodeDragRadius      = getDragRadius(opath.path[0]); //  2020-08-03
                        opath.path[0].MoveTo = extendPath(opath.path[0].MoveTo, opath.path[1].MoveTo, gcodeDragRadius, ExtendDragPath.startEarlier);
                        opath.Start          = opath.path[0].MoveTo;

/*Go from path-end to path-start for easier path-insertion*/
                        for (int i = opath.path.Count - 1; i > 0; i--)
                        {
                            if (isEqual(opath.path[i - 1].MoveTo, opath.path[i].MoveTo))
                            {
                                if ((logFlags & loggerSelect) > 0)
                                {
                                    Logger.Trace(" Error same coord: Drag (i-1) x:{0:0.00} y:{1:0.00} (i) x:{2:0.00} y:{3:0.00}  ", opath.path[i - 1].MoveTo.X, opath.path[i - 1].MoveTo.Y, opath.path[i].MoveTo.X, opath.path[i].MoveTo.Y);
                                }
                                continue;
                            }

                            origMoveTo           = opath.path[i].MoveTo;
                            gcodeDragRadius      = getDragRadius(opath.path[i]); //  2020-08-03
                            opath.path[i].MoveTo = extendPath(opath.path[i - 1].MoveTo, opath.path[i].MoveTo, gcodeDragRadius, ExtendDragPath.endLater);
                            if (i < opath.path.Count - 1)
                            {
                                a1 = gcodeMath.getAlpha(opath.path[i - 1].MoveTo, origMoveTo);
                                a2 = gcodeMath.getAlpha(origMoveTo, opath.path[i + 1].MoveTo);
                                a  = a2 - a1;
                                if (a > Math.PI)
                                {
                                    a = a - 2 * Math.PI;
                                }
                                if (a < -Math.PI)
                                {
                                    a = 2 * Math.PI + a;
                                }
                                if ((logFlags & loggerSelect) > 0)
                                {
                                    Logger.Trace(" Drag (i-1) x:{0:0.00} y:{1:0.00} (i) x:{2:0.00} y:{3:0.00}  (i+1) x:{4:0.00} y:{5:0.00} a1:{6:0.00} a2:{7:0.00}", opath.path[i - 1].MoveTo.X, opath.path[i - 1].MoveTo.Y, opath.path[i].MoveTo.X, opath.path[i].MoveTo.Y, opath.path[i + 1].MoveTo.X, opath.path[i + 1].MoveTo.Y, (a1 * 180 / Math.PI), (a2 * 180 / Math.PI));
                                }
                                /* if change in angle is too much, insert extra path */
                                if ((Math.Abs(a) * 180 / Math.PI) > gcodeDragAngle)
                                {
                                    if ((logFlags & loggerSelect) > 0)
                                    {
                                        Logger.Trace("   Abs angle exceeds max a:{0:0.00} > max:{1:0.00}", (a * 180 / Math.PI), gcodeDragAngle);
                                    }
                                    shorten = extendPath(origMoveTo, opath.path[i + 1].MoveTo, gcodeDragRadius, ExtendDragPath.startLater);
                                    center  = (Point)Point.Subtract(origMoveTo, opath.path[i].MoveTo);

/* insert arc as line segments to avoid problems with other options 2020-08-03*/
                                    insertArcMove(opath, i, opath.path[i].MoveTo, shorten, center, Math.Sign(a) < 0, opath.path[i].Depth);
                                    //       GCodeMotion tmpArc = new GCodeArc(shorten, center, Math.Sign(a) < 0, opath.path[i].Depth);
                                    //       opath.path.Insert(i + 1, tmpArc);
                                }
                            }
                        }
                        opath.End = opath.path[opath.path.Count - 1].MoveTo;
                    }
                }
            }
        }
        public byte[] Write()
        {
            MemoryStream       m  = new MemoryStream();
            EndianBinaryWriter er = new EndianBinaryWriter(m, Endianness.LittleEndian);
            int NrSections        = 0;

            if (ObjectInformation != null)
            {
                NrSections++;
            }
            if (Path != null)
            {
                NrSections++;
            }
            if (Point != null)
            {
                NrSections++;
            }
            if (Stage != null)
            {
                NrSections++;
            }
            if (KartPointStart != null)
            {
                NrSections++;
            }
            if (KartPointJugem != null)
            {
                NrSections++;
            }
            if (KartPointSecond != null)
            {
                NrSections++;
            }
            if (KartPointCannon != null)
            {
                NrSections++;
            }
            if (KartPointMission != null)
            {
                NrSections++;
            }
            if (CheckPoint != null)
            {
                NrSections++;
            }
            if (CheckPointPath != null)
            {
                NrSections++;
            }
            if (ItemPoint != null)
            {
                NrSections++;
            }
            if (ItemPath != null)
            {
                NrSections++;
            }
            if (EnemyPoint != null)
            {
                NrSections++;
            }
            if (EnemyPath != null)
            {
                NrSections++;
            }
            if (MiniGameEnemyPoint != null)
            {
                NrSections++;
            }
            if (MiniGameEnemyPath != null)
            {
                NrSections++;
            }
            if (Area != null)
            {
                NrSections++;
            }
            if (Camera != null)
            {
                NrSections++;
            }
            Header.SectionOffsets = new UInt32[NrSections];
            Header.Write(er);

            int SectionIdx = 0;

            if (ObjectInformation != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                ObjectInformation.Write(er);
                SectionIdx++;
            }
            if (Path != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                Path.Write(er);
                SectionIdx++;
            }
            if (Point != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                Point.Write(er);
                SectionIdx++;
            }
            if (Stage != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                Stage.Write(er);
                SectionIdx++;
            }
            if (KartPointStart != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                KartPointStart.Write(er);
                SectionIdx++;
            }
            if (KartPointJugem != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                KartPointJugem.Write(er);
                SectionIdx++;
            }
            if (KartPointSecond != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                KartPointSecond.Write(er);
                SectionIdx++;
            }
            if (KartPointCannon != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                KartPointCannon.Write(er);
                SectionIdx++;
            }
            if (KartPointMission != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                KartPointMission.Write(er);
                SectionIdx++;
            }
            if (CheckPoint != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                CheckPoint.Write(er);
                SectionIdx++;
            }
            if (CheckPointPath != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                CheckPointPath.Write(er);
                SectionIdx++;
            }
            if (ItemPoint != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                ItemPoint.Write(er);
                SectionIdx++;
            }
            if (ItemPath != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                ItemPath.Write(er);
                SectionIdx++;
            }
            if (EnemyPoint != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                EnemyPoint.Write(er);
                SectionIdx++;
            }
            if (EnemyPath != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                EnemyPath.Write(er);
                SectionIdx++;
            }
            if (MiniGameEnemyPoint != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                MiniGameEnemyPoint.Write(er);
                SectionIdx++;
            }
            if (MiniGameEnemyPath != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                MiniGameEnemyPath.Write(er);
                SectionIdx++;
            }
            if (Area != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                Area.Write(er);
                SectionIdx++;
            }
            if (Camera != null)
            {
                WriteHeaderInfo(er, SectionIdx);
                Camera.Write(er);
                SectionIdx++;
            }

            byte[] result = m.ToArray();
            er.Close();
            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Gets the type of the referenced file.
        /// </summary>
        /// <returns>The referenced file type.</returns>
        public WarcraftFileType GetReferencedFileType()
        {
            string itemPath = ItemPath.ToLower();

            if (!itemPath.EndsWith("\\"))
            {
                string fileExtension = Path.GetExtension(itemPath).Replace(".", "");

                switch (fileExtension)
                {
                case "mpq":
                {
                    return(WarcraftFileType.MoPaQArchive);
                }

                case "toc":
                {
                    return(WarcraftFileType.AddonManifest);
                }

                case "sig":
                {
                    return(WarcraftFileType.AddonManifestSignature);
                }

                case "wtf":
                {
                    return(WarcraftFileType.ConfigurationFile);
                }

                case "dbc":
                {
                    return(WarcraftFileType.DatabaseContainer);
                }

                case "bls":
                {
                    return(WarcraftFileType.Shader);
                }

                case "wlw":
                {
                    return(WarcraftFileType.TerrainWater);
                }

                case "wlq":
                {
                    return(WarcraftFileType.TerrainLiquid);
                }

                case "wdl":
                {
                    return(WarcraftFileType.TerrainLiquid);
                }

                case "wdt":
                {
                    return(WarcraftFileType.TerrainTable);
                }

                case "adt":
                {
                    return(WarcraftFileType.TerrainData);
                }

                case "blp":
                {
                    return(WarcraftFileType.BinaryImage);
                }

                case "trs":
                {
                    return(WarcraftFileType.Hashmap);
                }

                case "m2":
                case "mdx":
                {
                    return(WarcraftFileType.GameObjectModel);
                }

                case "wmo":
                {
                    Regex groupDetectRegex = new Regex("(.+_[0-9]{3}.wmo)", RegexOptions.Multiline);

                    if (groupDetectRegex.IsMatch(itemPath))
                    {
                        return(WarcraftFileType.WorldObjectModelGroup);
                    }
                    else
                    {
                        return(WarcraftFileType.WorldObjectModel);
                    }
                }

                default:
                {
                    return(WarcraftFileType.Unknown);
                }
                }
            }
            else
            {
                return(WarcraftFileType.Directory);
            }
        }