Пример #1
0
        private static void ScaleAndTranslate(Graphics graphics, RenderInformation renderInfo)
        {
            if (renderInfo.RenderType == GerberRenderQuality.Default)
            {
                graphics.SmoothingMode = SmoothingMode.Default;
            }

            else if (renderInfo.RenderType == GerberRenderQuality.HighQuality)
            {
                graphics.SmoothingMode = SmoothingMode.HighQuality;
            }

            else
            {
                graphics.SmoothingMode = SmoothingMode.HighSpeed;
            }

            graphics.PageUnit = GraphicsUnit.Inch;
            double translateX = (renderInfo.Left * renderInfo.ScaleFactorX);
            double translateY = (renderInfo.Bottom * renderInfo.ScaleFactorY);

            //  Translate the draw area before drawing. We must translate the whole drawing down
            //  an additional displayHeight to account for the negative y flip done later.
            graphics.ScaleTransform(1, -1);
            graphics.TranslateTransform((float)(translateX + renderInfo.ScrollValueX), (float)(translateY - renderInfo.ScrollValueY));
            //graphics.TranslateTransform(-(float)(translateX - renderInfo.ScrollValueX), (float)(translateY + renderInfo.ImageHeight + renderInfo.ScrollValueY));
            //graphics.ScaleTransform((float)renderInfo.ScaleFactorY, -(float)renderInfo.ScaleFactorY);
        }
Пример #2
0
        private void RenderLayer(Graphics graphics, GerberProject project, RenderInformation renderInfo, int fileIndex)
        {
            GerberFileInformation fileInfo = project.FileInfo[fileIndex];
            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.SourceCopy;
                    ScaleAndTranslate(backBuffer, renderInfo);

                    // For testing.

                    /*BoundingBox bb = GetProjectBounds(project);
                     * RectangleF r = new RectangleF((float)bb.Left, (float)bb.Top, (float)(bb.Right - bb.Left), (float)(bb.Top - bb.Bottom));
                     * GraphicsPath path = new GraphicsPath();
                     * path.AddLine((float)bb.Left, (float)bb.Bottom, (float)bb.Left, (float)(bb.Top));
                     * path.AddLine((float)bb.Left, (float)bb.Top, (float)bb.Right, (float)bb.Top);
                     * path.AddLine((float)bb.Right, (float)bb.Top, (float)bb.Right, (float)bb.Bottom);
                     * path.AddLine((float)bb.Right, (float)bb.Bottom, (float)bb.Left, (float)bb.Bottom);
                     * backBuffer.DrawPath(new Pen(Color.FromArgb(117, 200, 0, 0), 0.015f), path); */

                    // Add transparency to the rendering color.
                    Color foregroundColor = Color.FromArgb(fileInfo.Alpha, fileInfo.Color);
                    GerberDraw.DrawImageToTarget(backBuffer, fileInfo, project.UserTransform, foregroundColor, backgroundColor);

                    // Copy the back buffer to the visible surface with alpha level.
                    graphics.CompositingMode = CompositingMode.SourceOver;
                    graphics.DrawImage(bitmap, 0, 0);
                }
        }
Пример #3
0
        /// <summary>
        /// Draws all the visible layers contained in the project.
        /// </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>
        public void RenderAllLayers(Graphics graphics, GerberProject project, RenderInformation renderInfo)
        {
            int fileIndex = project.FileInfo.Count - 1;

            backgroundColor = project.BackgroundColor;
            graphics.Clear(backgroundColor);

            for (int i = fileIndex; i >= 0; i--)
            {
                if (project.FileInfo[i] != null && project.FileInfo[i].IsVisible)
                {
                    RenderLayer(graphics, project, renderInfo, i);
                }
            }
        }
Пример #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);
                }
        }
Пример #5
0
        /// <summary>
        /// Translates the rendered image to the top left of the display area.
        /// </summary>
        /// <param name="project">project information</param>
        /// <param name="renderInfo">render information</param>
        public void TranslateToFitDisplay(GerberProject project, RenderInformation renderInfo)
        {
            double      width, height;
            BoundingBox projectBounds = GetProjectBounds(project);

            if (!projectBounds.IsValid())
            {
                return;
            }

            double left   = projectBounds.Left - 0.25f;
            double bottom = projectBounds.Bottom - 0.25f;
            double right  = projectBounds.Right + 0.25f;
            double top    = projectBounds.Top + 0.25f;

            width  = right - left;
            height = top - bottom;
            renderInfo.ImageWidth  = width;
            renderInfo.ImageHeight = height;
            renderInfo.Left        = left;
            renderInfo.Bottom      = right;
        }
Пример #6
0
        /// <summary>
        /// Translates the rendered image to the centre of the display area.
        /// </summary>
        /// <param name="project">project details</param>
        /// <param name="renderInfo">render information</param>
        public void TranslateToCentreDisplay(GerberProject project, RenderInformation renderInfo)
        {
            BoundingBox projectBounds = GetProjectBounds(project);

            if (!projectBounds.IsValid())
            {
                return;
            }

            double left        = projectBounds.Left - 0.25f;
            double bottom      = projectBounds.Bottom - 0.25f;
            double right       = projectBounds.Right + 0.25f;
            double top         = projectBounds.Top + 0.25f;
            double imageWidth  = right - left;
            double imageHeight = top - bottom;

            renderInfo.ImageWidth  = imageWidth;
            renderInfo.ImageHeight = imageHeight;
            //renderInfo.Left = -((renderInfo.DisplayWidth - imageWidth) / 2) + left;
            //renderInfo.Bottom = ((renderInfo.DisplayHeight - imageHeight) / 2) + bottom;

            renderInfo.Left   = ((renderInfo.DisplayWidth - imageWidth) / 2) - left;
            renderInfo.Bottom = -((renderInfo.DisplayHeight + imageHeight) / 2) - bottom;
            if (imageWidth > renderInfo.DisplayWidth)
            {
                //renderInfo.Left = left;
                renderInfo.Left = -left;
            }

            if (imageHeight > renderInfo.DisplayHeight)
            {
                //renderInfo.Bottom = bottom;
                renderInfo.Bottom = -(imageHeight + bottom);
            }

            renderInfo.ScaleFactorX = 1.0;
            renderInfo.ScaleFactorY = 1.0;
        }