Exemplo n.º 1
0
        protected override void DoRender(Graphics graphics, bool fastRendering = false)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            var primitives        = Component.GetPrimitivesOfType <PcbPrimitive>();
            var orderedPrimitives = primitives
                                    .Where(p => IsPrimitiveVisible(graphics, p))
                                    .OrderByDescending(p => p.Layer.DrawPriority)
                                    .ThenByDescending(p => p.Layer);

            Debug.WriteLine($"Rendering {orderedPrimitives.Count()} / {primitives.Count()}");

            foreach (var primitive in orderedPrimitives)
            {
                // using Graphics.BeginContainer() instead of Graphics.Save() because
                // the former saves the previous transform as the default, and we
                // can then call Graphics.ResetTransform() to go back to the transform
                // that was set when the container was created.
                // Save() just resets the transform to identity
                var graphicsContainer = graphics.BeginContainer();
                // Drawback is that we need to set SmothingMode, etc. for each container
                DrawingUtils.SetupGraphics(graphics, fastRendering);

                switch (primitive)
                {
                case PcbArc arc:
                    RenderArcPrimitive(graphics, arc);
                    break;

                case PcbPad pad:
                    RenderPadPrimitive(graphics, pad);
                    break;

                case PcbTrack track:
                    RenderTrackPrimitive(graphics, track);
                    break;

                case PcbString @string:
                    RenderStringPrimitive(graphics, @string);
                    break;

                case PcbRectangle rectangle:
                    RenderRectanglePrimitive(graphics, rectangle);
                    break;

                case PcbPolygon polygon:
                    RenderPolygonPrimitive(graphics, polygon);
                    break;
                }
                graphics.EndContainer(graphicsContainer);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Implements rendering of the SchLib.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="fastRendering"></param>
        protected override void DoRender(Graphics graphics, bool fastRendering = false)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            var primitives        = Component.GetPrimitivesOfType <SchPrimitive>();
            var orderedPrimitives = primitives
                                    .Where(p => IsPrimitiveVisible(graphics, p));

            Debug.WriteLine($"Rendering {orderedPrimitives.Count()} / {primitives.Count()}");

            foreach (var primitive in orderedPrimitives)
            {
                // using Graphics.BeginContainer() instead of Graphics.Save() because
                // the former saves the previous transform as the default, and we
                // can then call Graphics.ResetTransform() to go back to the transform
                // that was set when the container was created.
                // Save() just resets the transform to identity
                var graphicsContainer = graphics.BeginContainer();
                // Drawback is that we need to set SmothingMode, etc. for each container
                DrawingUtils.SetupGraphics(graphics, fastRendering);

                switch (primitive)
                {
                case PinRecord pin:
                    RenderPinPrimitive(graphics, pin);
                    break;

                case SymbolRecord symbol:
                    RenderSymbolPrimitive(graphics, symbol);
                    break;

                case TextStringRecord textString:
                    // this can handle Record34 and Record41 through inheritance
                    RenderTextStringPrimitive(graphics, textString);
                    break;

                case BezierRecord bezier:
                    RenderBezierPrimitive(graphics, bezier);
                    break;

                case PolylineRecord polyline:
                    RenderPolylinePrimitive(graphics, polyline);
                    break;

                case PolygonRecord polygon:
                    RenderPolygonPrimitive(graphics, polygon);
                    break;

                case EllipseRecord ellipse:
                    RenderEllipsePrimitive(graphics, ellipse);
                    break;

                case PieChartRecord pieChart:
                    RenderPieChartPrimitive(graphics, pieChart);
                    break;

                case RoundedRectangleRecord roundedRect:
                    RenderRoundedRectPrimitive(graphics, roundedRect);
                    break;

                case ArcRecord arc:
                    RenderArcPrimitive(graphics, arc);
                    break;

                case LineRecord line:
                    RenderLinePrimitive(graphics, line);
                    break;

                case RectangleRecord rectangle:
                    RenderRectanglePrimitive(graphics, rectangle);
                    break;

                case TextFrameRecord textFrame:
                    RenderTextFramePrimitive(graphics, textFrame);
                    break;

                case ImageRecord image:
                    RenderImagePrimitive(graphics, image);
                    break;
                }
                graphics.EndContainer(graphicsContainer);
            }
        }