public static void HatchFill(List <PathObject> graphicToFill)
        {
            double distance       = (double)Properties.Settings.Default.importGraphicHatchFillDistance;
            double angle          = (double)Properties.Settings.Default.importGraphicHatchFillAngle;
            double angle2         = (double)Properties.Settings.Default.importGraphicHatchFillAngle2;
            bool   cross          = Properties.Settings.Default.importGraphicHatchFillCross;
            bool   incrementAngle = Properties.Settings.Default.importGraphicHatchFillAngleInc;

            bool nextIsSameHatch;
            bool fillColor = graphicInformation.ApplyHatchFill;                 // only hatch if fillColor is set

            Logger.Trace("...HatchFill distance:{0} angle:{1} cross:{2}", distance, angle, cross);
            List <Point[]> hatchPattern = new List <Point[]>();
            List <Point[]> finalPattern = new List <Point[]>();

            int maxObject                   = graphicToFill.Count;
            List <PathObject> tmpPath       = new List <PathObject>();
            Dimensions        pathDimension = new Dimensions();

            for (int index = 0; index < maxObject; index++)
            {
                PathObject item = graphicToFill[index];
                if (item is ItemPath)
                {
                    ItemPath PathData = (ItemPath)item;                                     // is closed polygon?

                    if (isEqual(PathData.Start, PathData.End) && (PathData.path.Count > 2)) //(PathData.Start.X == PathData.End.X) && (PathData.Start.Y == PathData.End.Y))
                    {
                        string fill = PathData.Info.groupAttributes[(int)GroupOptions.ByFill];
                        if (fillColor && ((fill == "") || (fill == "none")))    // SVG: only hatch if fillColor is set
                        {
                            Logger.Trace("no fill"); continue;
                        }
                        else
                        {
                            countProperty((int)GroupOptions.ByColor, fill);     // now fill-color is also penColor -> for grouping
                        }
                        tmpPath.Add(PathData);                                  // collect paths
                        pathDimension.addDimensionXY(PathData.Dimension);       // adapt overall size
                        if (!pathDimension.isXYSet())                           // no dimension - nothing to do
                        {
                            Logger.Trace("no dim"); continue;
                        }

                        // collect paths of same id, process if id changes
//                        nextIsSameHatch = ((index != (maxObject - 1)) && (graphicToFill[index].Info.id == graphicToFill[index + 1].Info.id));
                        nextIsSameHatch = ((index < (maxObject - 1)) && (graphicToFill[index].Info.id == graphicToFill[index + 1].Info.id));
                        if (logModification)
                        {
                            Logger.Trace("  Add to PathData ID:{0}  nextIsSameHatch:{1}  max:{2}  index:{3}  id_now:{4}  id_next:{5}", PathData.Info.id, nextIsSameHatch, maxObject, index, graphicToFill[index].Info.id, graphicToFill[index + 1].Info.id);
                        }
                        if (nextIsSameHatch)
                        {
                            continue;
                        }

                        // create hatch pattern
                        hatchPattern.Clear();
                        hatchPattern.AddRange(CreateLinePattern(pathDimension, angle, distance));
                        if (cross)
                        {
                            hatchPattern.AddRange(CreateLinePattern(pathDimension, angle + 90, distance));
                        }

                        if (incrementAngle)
                        {
                            angle += angle2;
                        }

                        // process single hatch lines - shorten to match inside polygone
                        finalPattern.Clear();
                        foreach (Point[] hatchLine in hatchPattern)
                        {
                            ClipLineByPolygone(hatchLine[0], hatchLine[1], tmpPath, finalPattern);
                        }

                        // add processed hatch lines to final graphic
                        AddLinesToGraphic(finalPattern, PathData);

                        // tidy up for next object with new id
                        tmpPath.Clear();
                        pathDimension = new Dimensions();
                    }
                }
                else
                {
                    if (logModification)
                    {
                        Logger.Trace(" is Dot ID:{0} Length:{1:0.00}  start x:{2:0.00} y:{3:0.00} end x:{4:0.00} y:{5:0.00} ", item.Info.id, item.PathLength, item.Start.X, item.Start.Y, item.End.X, item.End.Y);
                    }
                }
            }
            if (logModification)
            {
                Logger.Trace("HatchFill End --------------------------------------", actualDimension.minx, actualDimension.miny);
            }
        }
예제 #2
0
 public void addDimensionXY(Dimensions tmp)
 {
     setDimensionXY(tmp.minx, tmp.miny);
     setDimensionXY(tmp.maxx, tmp.maxy);
 }
 private static List <Point[]> CreateLinePattern(Dimensions dim, double angle, double distance)
 {
     return(CreateLinePattern(dim.minx, dim.miny, dim.maxx, dim.maxy, angle, distance));
 }