示例#1
0
        private DisplayCanvas CreateDisplayCanvas(CircuitGlyph mainSymbol)
        {
            DisplayCanvas canvas = new DisplayCanvas();

            this.InitGlyphCanvas(canvas, mainSymbol);
            return(canvas);
        }
        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);
        }
示例#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 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);
        }
示例#6
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);
        }
            public Parameter AddParameter(Result result, CircuitMap circuitMap, Jam jam, int bitNumber)
            {
                Tracer.Assert(circuitMap.Circuit == jam.CircuitSymbol.LogicalCircuit && jam.CircuitSymbol == this.key.CircuitSymbol);
                JamKey    jamKey = new JamKey(jam, bitNumber);
                Parameter parameter;

                if (this.parameters.TryGetValue(jamKey, out parameter))
                {
                    if (!parameter.Result.IsTriState || !result.IsTriState)
                    {
                        if (parameter.Result == result && parameter.CircuitMap == circuitMap && parameter.Jam == jam && parameter.BitNumber == bitNumber)
                        {
                            return(parameter);
                        }
                        CircuitGlyph symbol = jam.CircuitSymbol;
                        throw new CircuitException(Cause.UserError,
                                                   Properties.Resources.ErrorManyResults(jam.Pin.Name, symbol.Circuit.Notation + symbol.Point.ToString())
                                                   );
                    }
                    parameter.Result.Link(result);
                }
                else
                {
                    parameter = new Parameter(result, circuitMap, jam, bitNumber);
                    this.parameters.Add(jamKey, parameter);
                    result.Add(parameter);
                }
                return(parameter);
            }
示例#8
0
        private Canvas CreateGlyphCanvas(CircuitGlyph mainSymbol)
        {
            Canvas canvas = new Canvas();

            this.InitGlyphCanvas(canvas, mainSymbol);
            return(canvas);
        }
示例#9
0
 public override FrameworkElement CreateDisplay(CircuitGlyph symbol, CircuitGlyph mainSymbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     if (this.IsValidDisplay())
     {
         return(symbol.CreateDisplayGlyph(mainSymbol));
     }
     return(base.CreateDisplay(symbol, mainSymbol));
 }
示例#10
0
 public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     if (this.IsValidDisplay())
     {
         return(symbol.CreateDisplayGlyph(symbol));
     }
     else
     {
         return(symbol.CreateRectangularGlyph());
     }
 }
示例#11
0
 private void InitGlyphCanvas(Canvas canvas, CircuitGlyph mainSymbol)
 {
     Panel.SetZIndex(canvas, this.Z);
     canvas.DataContext = mainSymbol;
     canvas.Width       = Symbol.ScreenPoint(this.Circuit.SymbolWidth);
     canvas.Height      = Symbol.ScreenPoint(this.Circuit.SymbolHeight);
     if (this == mainSymbol)
     {
         canvas.ToolTip = this.Circuit.ToolTip;
     }
     canvas.RenderTransform = new RotateTransform();
 }
示例#12
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);
        }
示例#13
0
 public override FrameworkElement CreateDisplay(CircuitGlyph symbol, CircuitGlyph mainSymbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     if (this.GateType == LogicCircuit.GateType.Led)
     {
         string skin;
         if (this.InputCount == 1)
         {
             skin = SymbolShape.Led;
         }
         else
         {
             Tracer.Assert(this.InputCount == 8);
             skin = SymbolShape.SevenSegment;
         }
         return(symbol.CreateSimpleGlyph(skin, mainSymbol));
     }
     return(base.CreateDisplay(symbol, mainSymbol));
 }
示例#14
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);
        }
示例#15
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);
        }
示例#16
0
        public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
        {
            Tracer.Assert(this == symbol.Circuit);
            string skin = SymbolShape.SensorAuto;

            switch (this.SensorType)
            {
            case LogicCircuit.SensorType.Series:
            case LogicCircuit.SensorType.Loop:
            case LogicCircuit.SensorType.Random:
                break;

            case LogicCircuit.SensorType.Manual:
                skin = SymbolShape.SensorManual;
                break;

            default:
                Tracer.Fail();
                break;
            }
            return(symbol.CreateSensorGlyph(skin));
        }
示例#17
0
        public void UpdateButtonGlyph(Panel panel)
        {
            Tracer.Assert(panel != null);
            CircuitButton button = this.Circuit as CircuitButton;

            Tracer.Assert(button != null);
            if (button.IsToggle)
            {
                if (panel.Children.Count < 3)
                {
                    panel.Children.Add(CircuitGlyph.Skin <Border>(SymbolShape.ToggleLed));
                }
            }
            else
            {
                if (2 < panel.Children.Count)
                {
                    UIElement rect = panel.Children[2];
                    Tracer.Assert(rect is Border);
                    panel.Children.Remove(rect);
                }
            }
        }
示例#18
0
 public LogicalJamItem(BasePin pin, CircuitGlyph symbol, Jam innerJam) : base(pin, symbol)
 {
     Tracer.Assert(innerJam != null && innerJam.CircuitSymbol.LogicalCircuit == symbol.Circuit);
     this.innerJam = innerJam;
 }
示例#19
0
 public JamItem(BasePin pin, CircuitGlyph symbol)
 {
     Tracer.Assert(pin.Circuit == symbol.Circuit);
     this.Pin           = pin;
     this.CircuitSymbol = symbol;
 }
示例#20
0
 public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     return(symbol.CreateSimpleGlyph(SymbolShape.Sound, symbol));
 }
示例#21
0
 public virtual FrameworkElement CreateDisplay(CircuitGlyph symbol, CircuitGlyph mainSymbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     throw new InvalidOperationException();
 }
 public override FrameworkElement CreateDisplay(CircuitGlyph symbol, CircuitGlyph mainSymbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     return(symbol.CreateButtonGlyph(mainSymbol));
 }
示例#23
0
 public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
 {
     return(symbol.CreateSimpleGlyph(SymbolShape.Pin, symbol));
 }
示例#24
0
 public abstract FrameworkElement CreateGlyph(CircuitGlyph symbol);
示例#25
0
        public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
        {
            Tracer.Assert(this == symbol.Circuit);
            string skin;

            switch (this.GateType)
            {
            case GateType.Clock:
                skin = SymbolShape.Clock;
                break;

            case GateType.Odd:
            case GateType.Even:
            case GateType.Probe:
                Tracer.Fail();
                return(null);

            case GateType.Led:
                if (this.InputCount == 1)
                {
                    skin = SymbolShape.Led;
                }
                else
                {
                    Tracer.Assert(this.InputCount == 8);
                    skin = SymbolShape.SevenSegment;
                }
                break;

            default:
                if (Settings.User.GateShape == GateShape.Rectangular)
                {
                    return(symbol.CreateRectangularGlyph());
                }
                else
                {
                    switch (this.GateType)
                    {
                    case GateType.Not:
                        skin = SymbolShape.ShapedNot;
                        break;

                    case GateType.Or:
                        skin = SymbolShape.ShapedOr;
                        break;

                    case GateType.And:
                        skin = SymbolShape.ShapedAnd;
                        break;

                    case GateType.Xor:
                        skin = SymbolShape.ShapedXor;
                        break;

                    case GateType.TriState1:
                        skin = SymbolShape.ShapedTriState1;
                        break;

                    case GateType.TriState2:
                        skin = SymbolShape.ShapedTriState2;
                        break;

                    default:
                        Tracer.Fail();
                        return(null);
                    }
                    return(symbol.CreateShapedGlyph(skin));
                }
            }
            return(symbol.CreateSimpleGlyph(skin, symbol));
        }
示例#26
0
 public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
 {
     throw new InvalidOperationException();
 }
示例#27
0
 public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     return(symbol.CreateLedMatrixGlyph(symbol));
 }
示例#28
0
 public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
 {
     return(symbol.CreateRectangularGlyph());
 }
 public override FrameworkElement CreateDisplay(CircuitGlyph symbol, CircuitGlyph mainSymbol)
 {
     Tracer.Assert(this == symbol.Circuit);
     return(symbol.CreateSimpleGlyph(SymbolShape.GraphicsArray, mainSymbol));
 }