示例#1
0
 /// <summary>
 /// Clear the selection buffer.
 /// </summary>
 /// <param name="selectionInfo">selection info</param>
 public void ClearSelectionBuffer(SelectionInformation selectionInfo)
 {
     if (selectionInfo.SelectedNetList.Count > 0)
     {
         selectionInfo.ClearSelectionList();
     }
 }
示例#2
0
        public static void DrawImageToTarget(Graphics graphics, SelectionInformation selectionInfo, GerberUserTransform userTransform,
                                             Color foreGroundColor, Color backGroundColor)
        {
            bool invert = false;

            RenderToTarget(graphics, selectionInfo.SelectionImage, selectionInfo.SelectedNetList, userTransform, foreGroundColor, backGroundColor, invert);
        }
示例#3
0
        /// <summary>
        /// Adds a gerber object to the selection buffer if it lies within the selection region.
        /// </summary>
        /// <param name="selectionInfo">current selection info</param>
        /// <param name="image">gerber image containing the net</param>
        /// <param name="net">net to add to the selection info</param>
        public void ObjectInSelectedRegion(SelectionInformation selectionInfo, ref int i, Graphics graphics)
        {
            bool        inSelect = false;
            GerberImage image    = selectionInfo.SelectionImage;
            GerberNet   net      = image.GerberNetList[i];
            float       x1       = (float)selectionInfo.LowerLeftX;
            float       y1       = (float)selectionInfo.LowerLeftY;
            float       x2       = (float)selectionInfo.UpperRightX;
            float       y2       = (float)selectionInfo.UpperRightY;

            if (selectionInfo.SelectionType == GerberSelection.PointClick)
            {
                if (net.BoundingBox != null)
                {
                    if (!net.BoundingBox.Contains(new PointD(x1, y1)))
                    {
                        return;
                    }

                    if (net.ApertureState == GerberApertureState.Flash)
                    {
                        inSelect = net.BoundingBox.Contains(new PointD(x1, y1));
                    }

                    else if (net.ApertureState == GerberApertureState.On)
                    {
                        switch (net.Interpolation)
                        {
                        case GerberInterpolation.PolygonAreaStart:
                            inSelect = net.BoundingBox.Contains(new PointD(x1, y1));
                            break;

                        case GerberInterpolation.LinearX10:
                        case GerberInterpolation.LinearX1:
                        case GerberInterpolation.LinearX01:
                        case GerberInterpolation.LinearX001:
                            using (GraphicsPath gp = new GraphicsPath())
                                using (Pen pen = new Pen(Color.Transparent))
                                {
                                    pen.Width    = (float)image.ApertureArray[net.Aperture].Parameters[0];
                                    pen.StartCap = pen.EndCap = LineCap.Round;
                                    PointF start = new PointF((float)(net.StartX), (float)(net.StartY));
                                    PointF end   = new PointF((float)(net.StopX), (float)(net.StopY));
                                    gp.AddLine(start, end);
                                    if (gp.IsOutlineVisible(new PointF(x1, y1), pen, graphics))
                                    {
                                        inSelect = true;
                                    }

                                    break;
                                }

                        case GerberInterpolation.ClockwiseCircular:
                        case GerberInterpolation.CounterClockwiseCircular:
                            using (GraphicsPath gp = new GraphicsPath())
                                using (Pen pen = new Pen(Color.Transparent))
                                {
                                    float centerX    = (float)net.CircleSegment.CenterX;
                                    float centerY    = (float)net.CircleSegment.CenterY;
                                    float width      = (float)net.CircleSegment.Width;
                                    float height     = (float)net.CircleSegment.Height;
                                    float startAngle = (float)net.CircleSegment.StartAngle;
                                    float sweepAngle = (float)net.CircleSegment.SweepAngle;
                                    if (image.ApertureArray[net.Aperture].ApertureType == GerberApertureType.Rectangle)
                                    {
                                        pen.StartCap = pen.EndCap = LineCap.Square;
                                    }

                                    else
                                    {
                                        pen.StartCap = pen.EndCap = LineCap.Round;
                                    }

                                    RectangleF arcRectangle = new RectangleF(centerX - (width / 2), centerY - (height / 2), width, height);
                                    pen.Width = width;

                                    gp.AddArc(arcRectangle, startAngle, sweepAngle);
                                    if (gp.IsOutlineVisible(new PointF(x1, y1), pen, graphics))
                                    {
                                        inSelect = true;
                                    }
                                }
                            break;
                        }
                    }
                }
            }

            else if (selectionInfo.SelectionType == GerberSelection.DragBox)
            {
                if (net.BoundingBox != null)
                {
                    double left   = Math.Min(selectionInfo.LowerLeftX, selectionInfo.UpperRightX);
                    double right  = Math.Max(selectionInfo.LowerLeftX, selectionInfo.UpperRightX);
                    double top    = Math.Min(selectionInfo.LowerLeftY, selectionInfo.UpperRightY);
                    double bottom = Math.Max(selectionInfo.LowerLeftY, selectionInfo.UpperRightY);

                    BoundingBox box = new BoundingBox(left, bottom, right, top);
                    if (!box.Contains(net.BoundingBox))
                    {
                        return;
                    }

                    if (net.ApertureState == GerberApertureState.Flash)
                    {
                        inSelect = box.Contains(net.BoundingBox);
                    }

                    else if (net.ApertureState == GerberApertureState.On)
                    {
                        inSelect = box.Contains(net.BoundingBox);
                    }
                }
            }

            if (inSelect)
            {
                selectionInfo.SelectedNetList.Add(net);
                selectionInfo.SelectionCount++;
                if (net.Interpolation == GerberInterpolation.PolygonAreaStart)  // Add all the poly points.
                {
                    do
                    {
                        i++;
                        net = image.GerberNetList[i];
                        selectionInfo.SelectedNetList.Add(net);
                    } while (net.Interpolation != GerberInterpolation.PolygonAreaEnd);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Draw the user selection layer;
        /// </summary>
        /// <param name="graphics">surface to render the image</param>
        /// <param name="project">project containing the files to render</param>
        /// <param name="renderInfo">information for positioning, scaling and translating</param>
        /// <param name="selectionInfo">information about the users selection</param>
        public void RenderSelectionLayer(Graphics graphics, GerberProject project, RenderInformation renderInfo, SelectionInformation selectionInfo)
        {
            int bmWidth  = 0;
            int bmHeight = 0;

            // Calculate how big to make the bitmap back buffer.
            if (renderInfo.ImageWidth < renderInfo.DisplayWidth)
            {
                bmWidth = (int)(renderInfo.DisplayWidth * graphics.DpiX);
            }

            else
            {
                bmWidth = (int)(renderInfo.ImageWidth * graphics.DpiX);
            }

            if (renderInfo.ImageHeight < renderInfo.DisplayHeight)
            {
                bmHeight = (int)(renderInfo.DisplayHeight * graphics.DpiY);
            }

            else
            {
                bmHeight = (int)(renderInfo.ImageHeight * graphics.DpiY);
            }

            // Create a back buffer and draw to it with no alpha level.
            using (Bitmap bitmap = new Bitmap(bmWidth, bmHeight, graphics))
                using (Graphics backBuffer = Graphics.FromImage(bitmap))
                {
                    backBuffer.CompositingMode = CompositingMode.SourceOver;
                    ScaleAndTranslate(backBuffer, renderInfo);
                    Color foregroundColor = Color.FromArgb(177, Color.White);
                    GerberDraw.DrawImageToTarget(backBuffer, selectionInfo, project.UserTransform, foregroundColor, backgroundColor);
                    // Copy the back buffer to the visible surface with alpha level.
                    graphics.CompositingMode = CompositingMode.SourceOver;
                    graphics.DrawImage(bitmap, 0, 0);
                }
        }