예제 #1
0
        public FrameworkElement CreateLedMatrixGlyph(CircuitGlyph mainSymbol)
        {
            Canvas canvas = this.CreateGlyphCanvas(mainSymbol);

            if (this == mainSymbol)
            {
                CircuitGlyph.AddJam(canvas, this.Jams(), null);
            }
            FrameworkElement shape = CircuitGlyph.Skin(canvas, SymbolShape.LedMatrix);
            UniformGrid      grid  = shape.FindName("ProbeView") as UniformGrid;

            Tracer.Assert(grid != null);
            if (this == mainSymbol)
            {
                this.ProbeView = grid;
            }
            LedMatrix matrix = (LedMatrix)this.Circuit;

            grid.Columns = matrix.Columns;
            grid.Rows    = matrix.Rows;
            string skin      = (matrix.CellShape == LedMatrixCellShape.Round) ? SymbolShape.LedMatrixRoundCell : SymbolShape.LedMatrixRectCell;
            int    cellCount = matrix.Rows * matrix.Columns;

            for (int i = 0; i < cellCount; i++)
            {
                grid.Children.Add(Symbol.Skin(skin));
            }
            return(canvas);
        }
예제 #2
0
        public FrameworkElement CreateShapedGlyph(string skin)
        {
            Gate gate = this.Circuit as Gate;

            Tracer.Assert(gate != null);
            Canvas canvas = this.CreateGlyphCanvas(this);

            CircuitGlyph.AddJam(canvas, this.Jams(), null);
            FrameworkElement shape = CircuitGlyph.Skin(canvas, skin);
            int       top          = Math.Max(0, gate.InputCount - 3) / 2;
            int       bottom       = Math.Max(0, gate.InputCount - 3 - top);
            Rectangle topLine      = shape.FindName("topLine") as Rectangle;

            if (topLine != null)
            {
                topLine.Height = Symbol.ScreenPoint(top);
            }
            Rectangle bottomLine = shape.FindName("bottomLine") as Rectangle;

            if (bottomLine != null)
            {
                bottomLine.Height = Symbol.ScreenPoint(bottom);
            }
            return(canvas);
        }
예제 #3
0
        public FrameworkElement CreateSimpleGlyph(string skin, CircuitGlyph mainSymbol)
        {
            Canvas canvas = this.CreateGlyphCanvas(mainSymbol);

            if (this == mainSymbol)
            {
                CircuitGlyph.AddJam(canvas, this.Jams(), null);
            }
            FrameworkElement shape     = CircuitGlyph.Skin(canvas, skin);
            FrameworkElement probeView = shape.FindName("ProbeView") as FrameworkElement;

            if (probeView != null)
            {
                if (this == mainSymbol)
                {
                    this.ProbeView = probeView;
                }
                TextBlock textBlock = probeView as TextBlock;
                if (textBlock != null)
                {
                    textBlock.Text = this.Circuit.Notation;
                }
            }
            return(canvas);
        }
예제 #4
0
        public FrameworkElement CreateSensorGlyph(string skin)
        {
            Canvas canvas = this.CreateGlyphCanvas(this);

            CircuitGlyph.AddJam(canvas, this.Jams(), null);
            FrameworkElement shape     = CircuitGlyph.Skin(canvas, skin);
            FrameworkElement probeView = shape.FindName("ProbeView") as FrameworkElement;

            Tracer.Assert(probeView != null);
            this.ProbeView = probeView;

            TextBlock textBlock = probeView as TextBlock;

            if (textBlock != null)
            {
                textBlock.Text = Sensor.UnknownValue;
            }
            else
            {
                TextBox textBox = (TextBox)probeView;
                textBox.Text = Sensor.UnknownValue;
            }

            TextBlock notation = shape.FindName("Notation") as TextBlock;

            Tracer.Assert(notation != null);
            notation.Text = this.Circuit.Notation;
            return(canvas);
        }
예제 #5
0
        public FrameworkElement CreateSimpleGlyph(string skin, CircuitGlyph mainSymbol)
        {
            Canvas canvas = this.CreateGlyphCanvas(mainSymbol);

            if (this == mainSymbol)
            {
                CircuitGlyph.AddJam(canvas, this.Jams(), null);
            }
            FrameworkElement shape = CircuitGlyph.Skin(canvas, skin);

            if (shape.FindName("ProbeView") is FrameworkElement probeView)
            {
                if (this == mainSymbol)
                {
                    this.ProbeView = probeView;
                }
                if (probeView is TextBlock textBlock)
                {
                    textBlock.Text = this.Circuit.Notation;
                }
                else if (probeView is Image)
                {
                    RenderOptions.SetBitmapScalingMode(probeView, BitmapScalingMode.NearestNeighbor);
                }
            }
            return(canvas);
        }
예제 #6
0
        public FrameworkElement CreateRectangularGlyph()
        {
            Canvas canvas = this.CreateGlyphCanvas(this);

            canvas.Background = Symbol.CircuitFill;
            bool             ln    = CircuitGlyph.AddJam(canvas, this.Left, (j, t) => { Canvas.SetLeft(t, Symbol.PinRadius); Canvas.SetTop(t, Symbol.ScreenPoint(j.Y) - 2 * Symbol.PinRadius); });
            bool             tn    = CircuitGlyph.AddJam(canvas, this.Top, (j, t) => { Canvas.SetLeft(t, Symbol.ScreenPoint(j.X) - Symbol.PinRadius); Canvas.SetTop(t, Symbol.PinRadius); });
            bool             rn    = CircuitGlyph.AddJam(canvas, this.Right, (j, t) => { Canvas.SetRight(t, Symbol.PinRadius); Canvas.SetTop(t, Symbol.ScreenPoint(j.Y) - 2 * Symbol.PinRadius); });
            bool             bn    = CircuitGlyph.AddJam(canvas, this.Bottom, (j, t) => { Canvas.SetLeft(t, Symbol.ScreenPoint(j.X) - Symbol.PinRadius); Canvas.SetBottom(t, Symbol.PinRadius); });
            FrameworkElement shape = CircuitGlyph.Skin(canvas, SymbolShape.Rectangular);

            if (shape.FindName("Notation") is TextBlock text)
            {
                text.Margin = new Thickness(ln ? 10 : 5, tn ? 10 : 5, rn ? 10 : 5, bn ? 10 : 5);
                text.Text   = this.Circuit.Notation;
            }
            return(canvas);
        }
예제 #7
0
        public FrameworkElement CreateDisplayGlyph(CircuitGlyph mainSymbol)
        {
            Tracer.Assert(mainSymbol != null);
            List <CircuitSymbol> list   = ((LogicalCircuit)this.Circuit).CircuitSymbols().Where(s => s.Circuit.IsValidDisplay()).ToList();
            GridPoint            offset = Symbol.GridPoint(list.Select(s => s.Bounds()).Aggregate((r1, r2) => Rect.Union(r1, r2)).TopLeft);
            DisplayCanvas        canvas = this.CreateDisplayCanvas(mainSymbol);

            if (this == mainSymbol)
            {
                Border border = Symbol.Skin <Border>(SymbolShape.DisplayBackground);
                border.Width  = canvas.Width;
                border.Height = canvas.Height;
                canvas.Children.Add(border);

                CircuitGlyph.AddJam(canvas, this.Left, (j, t) => { Canvas.SetLeft(t, Symbol.PinRadius); Canvas.SetTop(t, Symbol.ScreenPoint(j.Y) - 2 * Symbol.PinRadius); });
                CircuitGlyph.AddJam(canvas, this.Top, (j, t) => { Canvas.SetLeft(t, Symbol.ScreenPoint(j.X) - Symbol.PinRadius); Canvas.SetTop(t, Symbol.PinRadius); });
                CircuitGlyph.AddJam(canvas, this.Right, (j, t) => { Canvas.SetRight(t, Symbol.PinRadius); Canvas.SetTop(t, Symbol.ScreenPoint(j.Y) - 2 * Symbol.PinRadius); });
                CircuitGlyph.AddJam(canvas, this.Bottom, (j, t) => { Canvas.SetLeft(t, Symbol.ScreenPoint(j.X) - Symbol.PinRadius); Canvas.SetBottom(t, Symbol.PinRadius); });

                border        = Symbol.Skin <Border>(SymbolShape.DisplayBorder);
                border.Width  = canvas.Width;
                border.Height = canvas.Height;
                Panel.SetZIndex(border, int.MaxValue - 1);
                canvas.Children.Add(border);
            }

            foreach (CircuitSymbol symbol in list)
            {
                FrameworkElement display = symbol.Circuit.CreateDisplay(symbol, mainSymbol);
                Canvas.SetLeft(display, Symbol.ScreenPoint(symbol.X - offset.X));
                Canvas.SetTop(display, Symbol.ScreenPoint(symbol.Y - offset.Y));
                display.RenderTransformOrigin = Symbol.RotationCenter(symbol.Circuit.SymbolWidth, symbol.Circuit.SymbolHeight);
                RotateTransform rotation = (RotateTransform)display.RenderTransform;
                rotation.Angle = Symbol.Angle(symbol.Rotation);
                canvas.AddDisplay(symbol, display);
            }

            return(canvas);
        }
예제 #8
0
        public FrameworkElement CreateButtonGlyph(CircuitGlyph mainSymbol)
        {
            Tracer.Assert(this.Circuit is CircuitButton);
            Canvas canvas = this.CreateGlyphCanvas(mainSymbol);

            if (this == mainSymbol)
            {
                CircuitGlyph.AddJam(canvas, this.Jams(), null);
            }
            ButtonControl buttonControl = (ButtonControl)CircuitGlyph.Skin(canvas, SymbolShape.Button);

            Panel.SetZIndex(buttonControl, 0);
            buttonControl.Content = this.Circuit.Notation;
            buttonControl.Width   = canvas.Width;
            buttonControl.Height  = canvas.Height;
            if (this == mainSymbol)
            {
                this.ProbeView = buttonControl;
            }
            this.UpdateButtonGlyph(canvas);
            return(canvas);
        }