예제 #1
0
        public void DrawWire(object gfx, Core.IStyle style, Core.XWire wire)
        {
            var position = WirePosition.Calculate(
                wire,
                InvertSize,
                ShortenWire,
                ShortenSize);

            if (wire.InvertStart)
            {
                double x      = position.InvertX1 - InvertSize;
                double y      = position.InvertY1 - InvertSize;
                double width  = InvertSize + InvertSize;
                double height = InvertSize + InvertSize;

                (gfx as XGraphics).DrawEllipse(
                    ToXPen(style),
                    ScaleToPage(x),
                    ScaleToPage(y),
                    ScaleToPage(width),
                    ScaleToPage(height));
            }

            if (wire.InvertEnd)
            {
                double x      = position.InvertX2 - InvertSize;
                double y      = position.InvertY2 - InvertSize;
                double width  = InvertSize + InvertSize;
                double height = InvertSize + InvertSize;

                (gfx as XGraphics).DrawEllipse(
                    ToXPen(style),
                    ScaleToPage(x),
                    ScaleToPage(y),
                    ScaleToPage(width),
                    ScaleToPage(height));
            }

            (gfx as XGraphics).DrawLine(
                ToXPen(style),
                ScaleToPage(position.StartX),
                ScaleToPage(position.StartY),
                ScaleToPage(position.EndX),
                ScaleToPage(position.EndY));
        }
예제 #2
0
        public static WirePosition Calculate(
            XWire wire,
            double invertSize,
            bool shortenWire,
            double shortenSize)
        {
            var position = new WirePosition();

            // initialize start position
            if (wire.Start != null)
            {
                position.StartX = wire.Start.X;
                position.StartY = wire.Start.Y;
            }
            else
            {
                position.StartX = wire.X1;
                position.StartY = wire.Y1;
            }

            // initialize end position
            if (wire.End != null)
            {
                position.EndX = wire.End.X;
                position.EndY = wire.End.Y;
            }
            else
            {
                position.EndX = wire.X2;
                position.EndY = wire.Y2;
            }

            // shorten wire
            if (shortenWire == true &&
                wire.Start != null &&
                wire.End != null &&
                (wire.Start.Owner != null || wire.End.Owner != null))
            {
                bool isHorizontal = Math.Round(position.StartY, 1) == Math.Round(position.EndY, 1);
                if (isHorizontal == true)
                {
                    bool isStartSignal = wire.Start.Owner != null?
                                         SupportedOwners.Contains(wire.Start.Owner.Name) : false;

                    bool isEndSignal = wire.End.Owner != null?
                                       SupportedOwners.Contains(wire.End.Owner.Name) : false;

                    // shorten start
                    if (isStartSignal == true && isEndSignal == false)
                    {
                        position.StartX = wire.End.X - shortenSize;
                    }

                    // shorten end
                    if (isStartSignal == false && isEndSignal == true)
                    {
                        position.EndX = wire.Start.X + shortenSize;
                    }
                }
            }

            // initialize invert start position
            position.InvertX1 = position.StartX;
            position.InvertY1 = position.StartY;

            // initialize invert end position
            position.InvertX2 = position.EndX;
            position.InvertY2 = position.EndY;

            // vertical wire
            if (position.StartX == position.EndX && position.StartY != position.EndY)
            {
                if (position.StartY < position.EndY)
                {
                    if (wire.InvertStart)
                    {
                        position.StartY   += 2 * invertSize;
                        position.InvertY1 += invertSize;
                    }

                    if (wire.InvertEnd)
                    {
                        position.EndY     -= 2 * invertSize;
                        position.InvertY2 -= invertSize;
                    }
                }
                else
                {
                    if (wire.InvertStart)
                    {
                        position.StartY   -= 2 * invertSize;
                        position.InvertY1 -= invertSize;
                    }

                    if (wire.InvertEnd)
                    {
                        position.EndY     += 2 * invertSize;
                        position.InvertY2 += invertSize;
                    }
                }
            }

            // horizontal wire
            if (position.StartX != position.EndX && position.StartY == position.EndY)
            {
                if (position.StartX < position.EndX)
                {
                    if (wire.InvertStart)
                    {
                        position.StartX   += 2 * invertSize;
                        position.InvertX1 += invertSize;
                    }

                    if (wire.InvertEnd)
                    {
                        position.EndX     -= 2 * invertSize;
                        position.InvertX2 -= invertSize;
                    }
                }
                else
                {
                    if (wire.InvertStart)
                    {
                        position.StartX   -= 2 * invertSize;
                        position.InvertX1 -= invertSize;
                    }

                    if (wire.InvertEnd)
                    {
                        position.EndX     += 2 * invertSize;
                        position.InvertX2 += invertSize;
                    }
                }
            }

            return(position);
        }