예제 #1
0
        /// <summary>
        /// from physical to visual
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        public static Size Physic2Visual(Size size)
        {
            double wPixel = VisualCommon.Convert2PixelXUnit(size.Width);
            double hPixel = VisualCommon.Convert2PixelYUnit(size.Height);

            return(new Size(wPixel, hPixel));
        }
예제 #2
0
        internal static int FindCorrespondingGrid(double xPixelOnCanvas)
        {
            double unitXPixels   = VisualCommon.Convert2PixelXUnit(Worktable.DistanceBetweenAdjacentPins);
            double startXmm      = Configurations.Instance.Worktable.TopLeftPinPosition.X;
            double xPixelsOffset = VisualCommon.Convert2PixelXUnit(startXmm);
            int    mapGrid       = (int)(Math.Ceiling((xPixelOnCanvas - GetXShift() - xPixelsOffset) / unitXPixels + 0.5));

            return(mapGrid);
        }
예제 #3
0
        /// <summary>
        /// from physical to visual
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static Rect Physic2Visual(double x, double y, Size size)
        {
            double xPixel = VisualCommon.Convert2PixelXUnit(x);
            double yPixel = VisualCommon.Convert2PixelYUnit(y);

            xPixel += GetXShift();
            yPixel += GetYShift();
            double wPixel = VisualCommon.Convert2PixelXUnit(size.Width);
            double hPixel = VisualCommon.Convert2PixelYUnit(size.Height);

            return(new Rect(new Point(xPixel, yPixel), new Size(wPixel, hPixel)));
        }
예제 #4
0
        internal static void DrawGridNumber(int grid, int firstPinX, DrawingContext dc)
        {
            double xPixel = VisualCommon.Convert2PixelXUnit(firstPinX) + GetXShift() * 0.95;
            //when height is 400 use font 10

            double yPixel = containerSize.Height * 0.81;

            dc.DrawText(new FormattedText((grid + 1).ToString(),
                                          CultureInfo.GetCultureInfo("en-us"),
                                          FlowDirection.LeftToRight,
                                          new Typeface("Verdana"),
                                          10 * containerSize.Height / 400, System.Windows.Media.Brushes.DarkBlue),
                        new System.Windows.Point(xPixel, yPixel));
        }
예제 #5
0
        /// <summary>
        /// draw circle
        /// </summary>
        /// <param name="position"></param>
        /// <param name="radius"></param>
        /// <param name="drawingContext"></param>
        /// <param name="color"></param>
        public static void DrawCircle(Point position, double radius, DrawingContext drawingContext, Color color, bool fill = false)
        {
            double xPixel = VisualCommon.Convert2PixelXUnit(position.X);
            double yPixel = VisualCommon.Convert2PixelYUnit(position.Y);

            xPixel += GetXShift();
            yPixel += GetYShift();
            double rXPixel   = VisualCommon.Convert2PixelXUnit(radius);
            double rYPixel   = VisualCommon.Convert2PixelYUnit(radius);
            Brush  brush     = new SolidColorBrush(color);
            Brush  fillBrush = fill ? brush : null;

            drawingContext.DrawEllipse(fillBrush, new Pen(new SolidColorBrush(color), 1), new Point(xPixel, yPixel), rXPixel, rYPixel);
        }
예제 #6
0
        internal static void DrawText(Point pt,
                                      string text,
                                      DrawingContext drawingContext)
        {
            double xPixel   = VisualCommon.Convert2PixelXUnit(pt.X) + GetXShift();
            double yPixel   = VisualCommon.Convert2PixelYUnit(pt.Y) + GetYShift();
            Point  ptVisual = new Point(xPixel, yPixel);
            double fontSize = 10 * containerSize.Height / 400;

            var formattedText = new FormattedText(text,
                                                  CultureInfo.GetCultureInfo("en-us"),
                                                  FlowDirection.LeftToRight,
                                                  new Typeface("Verdana"),
                                                  fontSize, System.Windows.Media.Brushes.DarkBlue);

            drawingContext.DrawText(formattedText, ptVisual);
        }