コード例 #1
0
        public void Redraw()
        {
            LogicalCircuit currentCircuit = this.project.LogicalCircuit;

            if (this.lastLogicalCircuit != currentCircuit)
            {
                this.lastLogicalCircuit = currentCircuit;
                this.lastBack           = null;
            }
            if (this.lastBack == null)
            {
                if (this.circuitSymbol.Count == 1)
                {
                    this.lastBack = (Canvas)this.circuitSymbol[0].ProbeView;
                }
                else
                {
                    CircuitSymbol symbol = this.circuitSymbol.First(s => s.LogicalCircuit == currentCircuit);
                    this.lastBack = this.ProbeView(symbol);
                }
                Tracer.Assert(this.lastBack.Children.Count == this.BitWidth);
            }
            for (int i = 0; i < this.BitWidth; i++)
            {
                Function7Segment.SetVisual((Shape)this.lastBack.Children[i], this[i]);
            }
        }
コード例 #2
0
ファイル: PinComparer.cs プロジェクト: bloeys/LogicCircuit
        public int Compare(BasePin x, BasePin y)
        {
            Tracer.Assert(x.GetType() == y.GetType());
            DevicePin dp1 = x as DevicePin;

            if (dp1 != null)
            {
                DevicePin dp2 = (DevicePin)y;
                return(dp1.Order - dp2.Order);
            }
            else
            {
                CircuitSymbolSet symbolSet = x.CircuitProject.CircuitSymbolSet;
                Tracer.Assert(symbolSet == y.CircuitProject.CircuitSymbolSet);
                CircuitSymbol s1 = symbolSet.SelectByCircuit(x).FirstOrDefault();
                CircuitSymbol s2 = symbolSet.SelectByCircuit(y).FirstOrDefault();
                if (s1 != null && s2 != null)
                {
                    int d = s1.Y - s2.Y;
                    if (d == 0)
                    {
                        d = s1.X - s2.X;
                        if (d == 0)
                        {
                            return(StringComparer.Ordinal.Compare(x.Name, y.Name));
                        }
                    }
                    return(d);
                }
                return(StringComparer.Ordinal.Compare(x.Name, y.Name));
            }
        }
コード例 #3
0
        public void Redraw()
        {
            this.bitmap.WritePixels(this.drawingRect, this.data, this.bitmapStride, 0);

            LogicalCircuit currentCircuit = this.project.LogicalCircuit;

            if (this.lastLogicalCircuit != currentCircuit)
            {
                this.lastLogicalCircuit = currentCircuit;
                this.lastImage          = null;
            }
            if (this.lastImage == null)
            {
                if (this.circuitSymbol.Count == 1)
                {
                    this.lastImage = (Image)this.circuitSymbol[0].ProbeView;
                }
                else
                {
                    CircuitSymbol symbol = this.circuitSymbol.First(s => s.LogicalCircuit == currentCircuit);
                    this.lastImage = this.ProbeView(symbol);
                }
                this.lastImage.Source = this.bitmap;
                this.lastImage.Width  = this.bitmap.Width * this.zoom;
                this.lastImage.Height = this.bitmap.Height * this.zoom;
            }
        }
コード例 #4
0
        public FunctionSensor(CircuitState circuitState, CircuitSymbol symbol, int[] result) : base(circuitState, null, result)
        {
            this.CircuitSymbol = symbol;
            Tracer.Assert(this.BitWidth == result.Length);
            switch (this.Sensor.SensorType)
            {
            case SensorType.Series:
            case SensorType.Loop:
                this.sensorValue = new SeriesValue(this.Sensor.Data, this.Sensor.SensorType == SensorType.Loop, this.Sensor.BitWidth);
                break;

            case SensorType.Random:
                this.sensorValue = new RandomValue(this.Sensor.Data, this.Sensor.BitWidth, this.CircuitState.Random);
                break;

            case SensorType.Manual:
                this.sensorValue = new ManualValue(this.Sensor.Data, this.Sensor.BitWidth);
                break;

            default:
                Tracer.Fail();
                this.sensorValue = null;
                break;
            }
        }
コード例 #5
0
		private Shape ProbeView(CircuitSymbol symbol) {
			if(symbol == this.circuitSymbol[0]) {
				return (Shape)this.circuitSymbol[0].ProbeView;
			} else {
				DisplayCanvas canvas = (DisplayCanvas)symbol.Glyph;
				return (Shape)canvas.DisplayOf(this.circuitSymbol);
			}
		}
コード例 #6
0
ファイル: CircuitProject.cs プロジェクト: bloeys/LogicCircuit
        private bool NeedToShift(List <Symbol> list)
        {
            bool           need    = false;
            Point          diagram = new Point(Symbol.LogicalCircuitWidth, Symbol.LogicalCircuitHeight);
            LogicalCircuit target  = this.ProjectSet.Project.LogicalCircuit;

            foreach (Symbol symbol in list)
            {
                CircuitSymbol circuitSymbol = symbol as CircuitSymbol;
                if (circuitSymbol != null)
                {
                    foreach (CircuitSymbol other in target.CircuitSymbols().Where(s => s != circuitSymbol && s.Circuit.Similar(circuitSymbol.Circuit)))
                    {
                        Point point = other.Bounds().BottomRight;
                        if (diagram.X < point.X || diagram.Y < point.Y)
                        {
                            return(false);
                        }
                        need = need || (other.X == circuitSymbol.X && other.Y == circuitSymbol.Y);
                    }
                }
                else
                {
                    TextNote textNote = symbol as TextNote;
                    if (textNote != null)
                    {
                        foreach (TextNote other in target.TextNotes().Where(n => n != textNote))
                        {
                            Point point = other.Bounds().BottomRight;
                            if (diagram.X < point.X || diagram.Y < point.Y)
                            {
                                return(false);
                            }
                            need = need || (other.X == textNote.X && other.Y == textNote.Y && other.Width == textNote.Width && other.Height == textNote.Height);
                        }
                    }
                    else
                    {
                        Wire wire = symbol as Wire;
                        if (wire != null)
                        {
                            foreach (Wire other in target.Wires().Where(w => w != wire))
                            {
                                if (diagram.X < Math.Max(wire.X1, wire.X2) || diagram.Y < Math.Max(wire.Y1, wire.Y2))
                                {
                                    return(false);
                                }
                                need = need || (wire.Point1 == other.Point1 && wire.Point2 == other.Point2);
                            }
                        }
                    }
                }
            }
            return(need);
        }
コード例 #7
0
 private Jam CreateJam(BasePin pin)
 {
     if (pin is Pin)
     {
         LogicalCircuit logicalCircuit = (LogicalCircuit)this.Circuit;
         CircuitSymbol  pinSymbol      = logicalCircuit.CircuitProject.CircuitSymbolSet.SelectByCircuit(pin).First();
         Jam            innerJam       = pinSymbol.Jams().First();
         return(new LogicalJamItem(pin, this, innerJam));
     }
     return(new JamItem(pin, this));
 }
コード例 #8
0
            public SymbolMap AddSymbol(CircuitMap circuitMap, CircuitSymbol circuitSymbol)
            {
                SymbolMapKey key = new SymbolMapKey(circuitMap, circuitSymbol);
                SymbolMap    map;

                if (!this.symbols.TryGetValue(key, out map))
                {
                    map = new SymbolMap(key);
                    this.symbols.Add(key, map);
                }
                return(map);
            }
コード例 #9
0
 public FunctionProbe(CircuitSymbol symbol, CircuitState circuitState, int[] parameter, int capacity) : base(circuitState, parameter)
 {
     Tracer.Assert(0 < this.BitWidth && this.BitWidth <= BasePin.MaxBitWidth);
     this.CircuitSymbol = symbol;
     this.tickHistory   = new History <State> [this.BitWidth];
     for (int i = 0; i < this.tickHistory.Length; i++)
     {
         this.tickHistory[i] = new History <State>(capacity);
     }
     this.valueHistory = new History <long>(capacity);
     this.valueHistory.Add(this.Pack());
 }
コード例 #10
0
 private Canvas ProbeView(CircuitSymbol symbol)
 {
     if (symbol == this.circuitSymbol[0])
     {
         return((Canvas)this.circuitSymbol[0].ProbeView);
     }
     else
     {
         DisplayCanvas canvas = (DisplayCanvas)symbol.Glyph;
         return((Canvas)canvas.DisplayOf(this.circuitSymbol));
     }
 }
コード例 #11
0
        public OutputPinSocket(Pin pin)
        {
            Tracer.Assert(pin.PinType == PinType.Output);
            CircuitProject project = pin.CircuitProject;

            this.Pin   = pin;
            this.Value = project.CircuitProbeSet.Create(null);
            CircuitSymbol pinSymbol = project.CircuitSymbolSet.SelectByCircuit(pin).FirstOrDefault();

            Tracer.Assert(pinSymbol != null);
            this.Symbol          = project.CircuitSymbolSet.Create(this.Value, pin.LogicalCircuit, pinSymbol.X, pinSymbol.Y);
            this.Symbol.Rotation = pinSymbol.Rotation;
            pinSymbol.X          = pinSymbol.Y = int.MinValue;
        }
コード例 #12
0
        public InputPinSocket(Pin pin)
        {
            Tracer.Assert(pin.PinType == PinType.Input);
            CircuitProject project = pin.CircuitProject;

            this.Pin   = pin;
            this.Value = project.ConstantSet.Create(pin.BitWidth, 0, PinSide.Right);
            this.Value.IsInputPinSocket = true;
            CircuitSymbol pinSymbol = project.CircuitSymbolSet.SelectByCircuit(pin).FirstOrDefault();

            Tracer.Assert(pinSymbol != null);
            this.Symbol          = project.CircuitSymbolSet.Create(this.Value, pin.LogicalCircuit, pinSymbol.X, pinSymbol.Y);
            this.Symbol.Rotation = pinSymbol.Rotation;
            pinSymbol.X          = pinSymbol.Y = int.MinValue;
        }
コード例 #13
0
        public CircuitSymbol Copy(CircuitSymbol other, LogicalCircuit target)
        {
            CircuitSymbolData data;

            other.CircuitProject.CircuitSymbolSet.Table.GetData(other.CircuitSymbolRowId, out data);
            if (this.Find(data.CircuitSymbolId) != null)
            {
                data.CircuitSymbolId = Guid.NewGuid();
            }
            data.LogicalCircuitId = target.LogicalCircuitId;
            Circuit circuit = other.Circuit.CopyTo(target);

            data.CircuitId     = circuit.CircuitId;
            data.CircuitSymbol = null;
            return(this.Create(this.Table.Insert(ref data)));
        }
コード例 #14
0
ファイル: DisplayCanvas.cs プロジェクト: bloeys/LogicCircuit
 public void AddDisplay(CircuitSymbol symbol, FrameworkElement glyph)
 {
     if (symbol.Circuit is LogicalCircuit)
     {
         Tracer.Assert(glyph is DisplayCanvas);
         this.symbolMap.Add(symbol, glyph);
     }
     else
     {
         Tracer.Assert(!(glyph is DisplayCanvas));
         FrameworkElement probeView = (FrameworkElement)glyph.FindName("ProbeView");
         Tracer.Assert(probeView != null);
         this.symbolMap.Add(symbol, probeView);
     }
     this.Children.Add(glyph);
 }
コード例 #15
0
        protected void Fill(int index, int value)
        {
            UniformGrid grid = null;

            if (this.circuitSymbol.Count == 1)
            {
                grid = (UniformGrid)this.circuitSymbol[0].ProbeView;
            }
            else
            {
                LogicalCircuit currentCircuit = this.CurrentLogicalCircuit;
                CircuitSymbol  symbol         = this.circuitSymbol.First(s => s.LogicalCircuit == currentCircuit);
                grid = this.ProbeView(symbol);
            }
            ((Shape)grid.Children[index]).Fill = FunctionLedMatrix.brush[value];
        }
コード例 #16
0
		public void Redraw() {
			LogicalCircuit currentCircuit = this.project.LogicalCircuit;
			if(this.lastLogicalCircuit != currentCircuit) {
				this.lastLogicalCircuit = currentCircuit;
				this.lastShape = null;
			}
			if(this.lastShape == null) {
				if(this.circuitSymbol.Count == 1) {
					this.lastShape = (Shape)this.circuitSymbol[0].ProbeView;
				} else {
					CircuitSymbol symbol = this.circuitSymbol.First(s => s.LogicalCircuit == currentCircuit);
					this.lastShape = this.ProbeView(symbol);
				}
			}
			this.lastShape.Fill = FunctionLed.stateBrush[(int)this[0]];
		}
コード例 #17
0
 public void Redraw()
 {
     if (this.isToggle)
     {
         ButtonControl button = null;
         if (this.circuitSymbol.Count == 1)
         {
             button = (ButtonControl)this.circuitSymbol[0].ProbeView;
         }
         else
         {
             LogicalCircuit currentCircuit = this.project.LogicalCircuit;
             CircuitSymbol  symbol         = this.circuitSymbol.First(s => s.LogicalCircuit == currentCircuit);
             button = this.ProbeView(symbol);
         }
         FunctionButton.DrawState(button, this.State);
     }
 }
コード例 #18
0
 private void StateChangedAction(CircuitSymbol symbol, bool isPressed)
 {
     if (isPressed)
     {
         if (this.isToggle)
         {
             this.SetState(CircuitFunction.Not(this.State));
             this.Invalid = true;
         }
         else
         {
             this.SetState(State.On1);
         }
     }
     else if (!this.isToggle)
     {
         this.SetState(State.On0);
     }
 }
コード例 #19
0
            public ButtonMarker(CircuitSymbol symbol) : base(symbol, new Canvas())
            {
                Tracer.Assert(symbol.Circuit is CircuitButton);

                this.resizeMarker = new ResizeMarker <ButtonMarker>[] {
                    new ResizeMarker <ButtonMarker>(this, 0, 0), new ResizeMarker <ButtonMarker>(this, 1, 0), new ResizeMarker <ButtonMarker>(this, 2, 0),
                    new ResizeMarker <ButtonMarker>(this, 0, 1), new ResizeMarker <ButtonMarker>(this, 2, 1),
                    new ResizeMarker <ButtonMarker>(this, 0, 2), new ResizeMarker <ButtonMarker>(this, 1, 2), new ResizeMarker <ButtonMarker>(this, 2, 2)
                };

                this.rectangle = Symbol.Skin <Rectangle>(SymbolShape.MarkerRectangle);
                Panel.SetZIndex(this.rectangle, 0);

                Canvas markerCanvas = (Canvas)this.Glyph;

                markerCanvas.Children.Add(this.rectangle);

                foreach (ResizeMarker <ButtonMarker> marker in this.resizeMarker)
                {
                    markerCanvas.Children.Add(marker.Glyph);
                }

                this.Refresh();
            }
コード例 #20
0
 public void Invalidate(CircuitSymbol symbol)
 {
     this.invalid.Add(symbol);
 }
コード例 #21
0
 public FunctionConstant(CircuitState circuitState, CircuitSymbol symbol, int[] result) : base(circuitState, null, result)
 {
     this.CircuitSymbol = symbol;
     Tracer.Assert(this.BitWidth == result.Length);
 }
コード例 #22
0
 protected CircuitMarker(CircuitSymbol symbol, FrameworkElement markerGlyph) : base(symbol)
 {
     this.markerGlyph             = markerGlyph;
     this.markerGlyph.DataContext = this;
 }
コード例 #23
0
 public CircuitSymbolMarker(CircuitSymbol symbol) : base(symbol, Symbol.Skin <Rectangle>(SymbolShape.MarkerRectangle))
 {
     this.Glyph.RenderTransform = this.CircuitSymbol.Glyph.RenderTransform;
     this.Refresh();
 }
コード例 #24
0
        protected override void Edit(Symbol symbol)
        {
            CircuitSymbol circuitSymbol = symbol as CircuitSymbol;

            if (circuitSymbol != null)
            {
                if (this.InEditMode)
                {
                    LogicalCircuit lc = circuitSymbol.Circuit as LogicalCircuit;
                    if (lc != null)
                    {
                        this.OpenLogicalCircuit(lc);
                        return;
                    }
                    CircuitProbe cp = circuitSymbol.Circuit as CircuitProbe;
                    if (cp != null)
                    {
                        this.Edit(cp);
                        return;
                    }
                    CircuitButton cb = circuitSymbol.Circuit as CircuitButton;
                    if (cb != null)
                    {
                        this.Edit(cb);
                        return;
                    }
                    Constant ct = circuitSymbol.Circuit as Constant;
                    if (ct != null)
                    {
                        this.Edit(ct);
                        return;
                    }
                    Sensor sr = circuitSymbol.Circuit as Sensor;
                    if (sr != null)
                    {
                        this.Edit(sr);
                        return;
                    }
                    Memory m = circuitSymbol.Circuit as Memory;
                    if (m != null)
                    {
                        this.Edit(m);
                        return;
                    }
                    Pin pin = circuitSymbol.Circuit as Pin;
                    if (pin != null)
                    {
                        this.Edit(pin);
                        return;
                    }
                    LedMatrix ledMatrix = circuitSymbol.Circuit as LedMatrix;
                    if (ledMatrix != null)
                    {
                        this.Edit(ledMatrix);
                        return;
                    }
                    Sound sound = circuitSymbol.Circuit as Sound;
                    if (sound != null)
                    {
                        this.Edit(sound);
                        return;
                    }
                    GraphicsArray graphicsArray = circuitSymbol.Circuit as GraphicsArray;
                    if (graphicsArray != null)
                    {
                        this.Edit(graphicsArray);
                        return;
                    }
                }
                else if (this.CircuitRunner != null && this.CircuitRunner.VisibleMap != null)
                {
                    CircuitMap map = this.CircuitRunner.VisibleMap.Child(circuitSymbol);
                    if (map != null)
                    {
                        this.OpenLogicalCircuit(map);
                        return;
                    }
                    if (circuitSymbol.Circuit is CircuitProbe)
                    {
                        FunctionProbe functionProbe = this.CircuitRunner.VisibleMap.FunctionProbe(circuitSymbol);
                        if (functionProbe != null)
                        {
                            this.Mainframe.ShowDialog(new DialogProbeHistory(functionProbe));
                        }
                        return;
                    }
                    if ((circuitSymbol.Circuit is Memory) || (circuitSymbol.Circuit is GraphicsArray))
                    {
                        IFunctionMemory functionMemory = this.CircuitRunner.VisibleMap.FunctionMemory(circuitSymbol);
                        if (functionMemory != null)
                        {
                            this.Mainframe.ShowDialog(new DialogMemory(functionMemory));
                        }
                        return;
                    }
                    if (circuitSymbol.Circuit is Constant)
                    {
                        if (this.CircuitRunner.Root.First() == this.CircuitRunner.VisibleMap)
                        {
                            FunctionConstant functionConstant = this.CircuitRunner.VisibleMap.FunctionConstant(circuitSymbol);
                            if (functionConstant != null)
                            {
                                this.CircuitProject.InOmitTransaction(() => functionConstant.Value++);
                            }
                        }
                        else
                        {
                            this.Mainframe.Status = Properties.Resources.MessageNotRootConstant(this.CircuitRunner.Root.First().Circuit.Name);
                        }
                    }
                }
            }
            else if (this.InEditMode)
            {
                TextNote textNote = symbol as TextNote;
                if (textNote != null)
                {
                    this.Edit(textNote);
                }
            }
        }
コード例 #25
0
 public SymbolMapKey(CircuitMap circuitMap, CircuitSymbol circuitSymbol)
 {
     this.CircuitMap    = circuitMap;
     this.CircuitSymbol = circuitSymbol;
 }