public CurcuitInfo(LogicalCircuit circuit)
 {
     this.Circuit = circuit;
 }
Example #2
0
 // Selects TextNote by LogicalCircuit
 public IEnumerable <TextNote> SelectByLogicalCircuit(LogicalCircuit logicalCircuit)
 {
     return(this.Select(this.Table.Select(TextNoteData.LogicalCircuitIdField.Field, logicalCircuit.LogicalCircuitId)));
 }
Example #3
0
        public RenderTargetBitmap ExportImage()
        {
            Rect           rect           = new Rect();
            bool           isEmpty        = true;
            LogicalCircuit logicalCircuit = this.Project.LogicalCircuit;

            foreach (Wire wire in logicalCircuit.Wires())
            {
                Rect wireRect = new Rect(Symbol.ScreenPoint(wire.Point1), Symbol.ScreenPoint(wire.Point2));
                if (isEmpty)
                {
                    rect    = wireRect;
                    isEmpty = false;
                }
                else
                {
                    rect.Union(wireRect);
                }
            }
            foreach (CircuitSymbol symbol in logicalCircuit.CircuitSymbols())
            {
                Rect symbolRect = new Rect(Symbol.ScreenPoint(symbol.Point), new Size(symbol.Glyph.Width, symbol.Glyph.Height));
                if (symbol.Rotation != Rotation.Up)
                {
                    symbolRect = Symbol.Transform(symbolRect, Symbol.RotationTransform(symbol.Rotation, symbol.X, symbol.Y, symbol.Circuit.SymbolWidth, symbol.Circuit.SymbolHeight));
                }
                if (isEmpty)
                {
                    rect    = symbolRect;
                    isEmpty = false;
                }
                else
                {
                    rect.Union(symbolRect);
                }
            }
            foreach (TextNote symbol in logicalCircuit.TextNotes())
            {
                Rect symbolRect = new Rect(Symbol.ScreenPoint(symbol.Point), new Size(symbol.Glyph.Width, symbol.Glyph.Height));
                if (symbol.Rotation != Rotation.Up)
                {
                    symbolRect = Symbol.Transform(symbolRect, Symbol.RotationTransform(symbol.Rotation, symbol.X, symbol.Y, symbol.Width, symbol.Height));
                }
                if (isEmpty)
                {
                    rect    = symbolRect;
                    isEmpty = false;
                }
                else
                {
                    rect.Union(symbolRect);
                }
            }
            if (!isEmpty)
            {
                this.ClearSelection();
                Canvas       diagram            = this.Diagram;
                Brush        oldBackground      = diagram.Background;
                Transform    oldRenderTransform = diagram.RenderTransform;
                Transform    oldLayoutTransform = diagram.LayoutTransform;
                double       horizontalOffset   = 0;
                double       verticalOffset     = 0;
                ScrollViewer scrollViewer       = diagram.Parent as ScrollViewer;
                try {
                    if (scrollViewer != null)
                    {
                        horizontalOffset = scrollViewer.HorizontalOffset;
                        verticalOffset   = scrollViewer.VerticalOffset;
                        scrollViewer.ScrollToHorizontalOffset(0);
                        scrollViewer.ScrollToVerticalOffset(0);
                        scrollViewer.UpdateLayout();
                    }
                    diagram.Background = Brushes.White;
                    rect.Inflate(Symbol.GridSize, Symbol.GridSize);
                    rect.Intersect(new Rect(0, 0, Symbol.LogicalCircuitWidth, Symbol.LogicalCircuitHeight));
                    diagram.RenderTransform = new TranslateTransform(-rect.X, -rect.Y);
                    diagram.LayoutTransform = Transform.Identity;
                    diagram.UpdateLayout();
                    RenderTargetBitmap bitmap = new RenderTargetBitmap(
                        (int)Math.Round(rect.Width), (int)Math.Round(rect.Height), 96, 96, PixelFormats.Pbgra32
                        );
                    bitmap.Render(diagram);
                    return(bitmap);
                } finally {
                    diagram.Background      = oldBackground;
                    diagram.RenderTransform = oldRenderTransform;
                    diagram.LayoutTransform = oldLayoutTransform;
                    diagram.UpdateLayout();
                    if (scrollViewer != null)
                    {
                        scrollViewer.ScrollToHorizontalOffset(horizontalOffset);
                        scrollViewer.ScrollToVerticalOffset(verticalOffset);
                        scrollViewer.UpdateLayout();
                    }
                }
            }
            return(null);
        }
Example #4
0
 public abstract Symbol CopyTo(LogicalCircuit target);
        public DialogTruthTable(LogicalCircuit logicalCircuit)
        {
            this.logicalCircuit = logicalCircuit;
            this.InvertFilter   = true;
            this.testSocket     = new CircuitTestSocket(this.logicalCircuit);
            int inputBits = this.testSocket.Inputs.Sum(p => p.Pin.BitWidth);

            if (0 < inputBits)
            {
                this.TotalRows = BigInteger.One << inputBits;
            }
            else
            {
                this.TotalRows  = 0;
                this.TruthTable = new ListCollectionView(new List <TruthState>());
            }

            this.BuildTruthTable();

            this.CommandDeleteOldFilter = new LambdaUICommand("-", o => this.RemoveFilter(o as string))
            {
                IconPath = "Icon/Delete.xaml"
            };

            this.DataContext = this;
            this.InitializeComponent();

            Dictionary <DataGridTextColumn, Func <TruthState, int> > dataAccessor = new Dictionary <DataGridTextColumn, Func <TruthState, int> >();

            void addColumn(Pin pin, string path, int i)
            {
                DataGridTextColumn column = new DataGridTextColumn();

                column.Header  = pin.Name.Replace("_", "__");
                column.Binding = new Binding(path);
                if (pin.PinType == PinType.Input)
                {
                    column.Binding.StringFormat = "{0:X}";
                }
                Style style = new Style(typeof(DataGridColumnHeader));

                style.Setters.Add(new Setter(ToolTipService.ToolTipProperty, pin.ToolTip));
                column.HeaderStyle = style;
                this.dataGrid.Columns.Add(column);
                dataAccessor.Add(column, DialogTruthTable.InputFieldAccesor(i));
            }

            int index = 0;

            foreach (InputPinSocket socket in this.testSocket.Inputs)
            {
                addColumn(socket.Pin, "Input[" + index + "]", index);
                index++;
            }
            index = 0;
            foreach (OutputPinSocket socket in this.testSocket.Outputs)
            {
                addColumn(socket.Pin, "[" + index + "]", index);
                index++;
            }

            this.sortComparer      = new TruthStateComparer(dataAccessor);
            this.dataGrid.Sorting += new DataGridSortingEventHandler(this.DataGridSorting);
            DataObject.AddPastingHandler(this.filter, this.OnFilterPaste);
            this.OldFilters.AddRange(this.logicalCircuit.Validators.Split('\t').Where(f => !string.IsNullOrWhiteSpace(f)).Select(f => f.Trim()));
        }
Example #6
0
 public void LogicalCircuitUsage(LogicalCircuit logicalCircuit)
 {
     this.Mainframe.ShowDialog(new DialogUsage(logicalCircuit));
 }
Example #7
0
        }                                                                                                       // Show ? on power off.

        public override Circuit CopyTo(LogicalCircuit target)
        {
            return(target.CircuitProject.SensorSet.Copy(this));
        }
Example #8
0
        public override void Redraw()
        {
            LogicalCircuit current = this.CurrentLogicalCircuit;

            if (current != this.lastLogicalCircuit)
            {
                this.lastLogicalCircuit = current;
                for (int i = 0; i < this.row.Length; i++)
                {
                    this.row[i] = (State)(0xFF);
                }
                for (int i = 0; i < this.column.Length; i++)
                {
                    this.column[i] = -1;
                }
            }
            // track changes in the column state parameters
            for (int i = 0; i < this.column.Length; i++)
            {
                int value = 0;
                for (int j = 0; j < this.BitPerLed; j++)
                {
                    if (this[i * this.BitPerLed + j] == State.On1)
                    {
                        value |= 1 << j;
                    }
                }
                if (this.columnChanged[i] = (value != this.column[i]))
                {
                    this.column[i] = value;
                }
            }
            for (int i = 0; i < this.row.Length; i++)
            {
                State rowState = this[rowParameter + i];
                if (this.row[i] != rowState)
                {
                    // state of row was changed
                    this.row[i] = rowState;
                    if (rowState == State.On1)
                    {
                        // set all the columns values
                        for (int j = 0; j < this.column.Length; j++)
                        {
                            int value = this.column[j];
                            int index = i * this.column.Length + j;
                            if (value != 0)
                            {
                                this.Fill(index, value);
                            }
                            else
                            {
                                this.cellFlip[index] = this.flip;
                            }
                            this.cell[index] = value;
                        }
                    }
                    else                         // rowState == State.On0 or Off that is same as 0 here.
                    {
                        for (int j = 0; j < this.column.Length; j++)
                        {
                            int index = i * this.column.Length + j;
                            this.cell[index]     = 0;
                            this.cellFlip[index] = this.flip;
                        }
                    }
                }
                else if (rowState == State.On1)
                {
                    // row state was not changed so update all the columns that was changed in this row
                    for (int j = 0; j < this.column.Length; j++)
                    {
                        if (this.columnChanged[j])
                        {
                            int value = this.column[j];
                            int index = i * this.column.Length + j;
                            if (value != 0)
                            {
                                this.Fill(index, value);
                            }
                            else
                            {
                                this.cellFlip[index] = this.flip;
                            }
                            this.cell[index] = value;
                        }
                    }
                }
            }
            int toOff = this.flip - this.row.Length;

            for (int i = 0; i < this.cellFlip.Length; i++)
            {
                if (this.cell[i] == 0 && this.cellFlip[i] == toOff)
                {
                    this.Fill(i, 0);
                }
            }
        }
Example #9
0
 public TextNote Create(LogicalCircuit logicalCircuit, GridPoint point, string note)
 {
     return(this.CreateItem(Guid.NewGuid(), logicalCircuit, point.X, point.Y,
                            TextNoteData.WidthField.Field.DefaultValue, TextNoteData.HeightField.Field.DefaultValue, note, TextNoteData.RotationField.Field.DefaultValue
                            ));
 }
        private HashSet <Wire> Bad(LogicalCircuit current)
        {
            Dictionary <GridPoint, List <Jam> > jams = new Dictionary <GridPoint, List <Jam> >();

            IEnumerable <Jam> connected(Conductor conductor)
            {
                IEnumerable <Jam> at(GridPoint point)
                {
                    List <Jam> list;

                    if (jams.TryGetValue(point, out list))
                    {
                        return(list);
                    }
                    return(Enumerable.Empty <Jam>());
                }

                return(conductor.Points.SelectMany(point => at(point)));
            }

            foreach (CircuitSymbol symbol in current.CircuitSymbols())
            {
                if (!(symbol.Circuit is CircuitProbe))
                {
                    foreach (Jam jam in symbol.Jams())
                    {
                        if (this.stopPending)
                        {
                            return(null);
                        }
                        GridPoint  point = jam.AbsolutePoint;
                        List <Jam> list;
                        if (!jams.TryGetValue(point, out list))
                        {
                            list = new List <Jam>(1);
                            jams.Add(point, list);
                        }
                        list.Add(jam);
                    }
                }
            }

            HashSet <Wire> bad = new HashSet <Wire>();

            foreach (Conductor conductor in current.ConductorMap().Conductors)
            {
                int first = 0;
                foreach (Jam jam in connected(conductor))
                {
                    if (this.stopPending)
                    {
                        return(null);
                    }
                    if (first == 0)
                    {
                        first = jam.Pin.BitWidth;
                    }
                    else if (first != jam.Pin.BitWidth)
                    {
                        bad.UnionWith(conductor.Wires);
                        break;
                    }
                }
                if (this.stopPending)
                {
                    return(null);
                }
            }
            return(bad);
        }
Example #11
0
 public CircuitInfo(LogicalCircuit circuit, bool canImport) : base(circuit, s => false)
 {
     this.CanImport = canImport;
     // Expand all categories for a better UX
     this.CategoryExpanded = true;
 }
 public override Circuit CopyTo(LogicalCircuit target)
 {
     return(target.CircuitProject.GraphicsArraySet.Copy(this));
 }
Example #13
0
 public CircuitSymbol Create(Circuit circuit, LogicalCircuit logicalCircuit, int x, int y)
 {
     return(this.CreateItem(Guid.NewGuid(), circuit, logicalCircuit, x, y, CircuitSymbolData.RotationField.Field.DefaultValue));
 }
Example #14
0
 public override Circuit CopyTo(LogicalCircuit target)
 {
     return(target.CircuitProject.LedMatrixSet.Copy(this));
 }
Example #15
0
 public override Circuit CopyTo(LogicalCircuit target)
 {
     return(target.CircuitProject.LogicalCircuitSet.Copy(this, true));
 }
 public CircuitTestSocket(LogicalCircuit circuit) : this(circuit, true)
 {
 }
 private ReportBuilder(LogicalCircuit root)
 {
     this.Root = root;
     this.ReportFunctions(root);
 }
        public static bool IsTestable(LogicalCircuit circuit)
        {
            IEnumerable <Pin> pins = circuit.CircuitProject.PinSet.SelectByCircuit(circuit);

            return(pins.Any(p => p.PinType == PinType.Input) && pins.Any(p => p.PinType == PinType.Output));
        }
Example #19
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);
                }
            }
        }
Example #20
0
 public Wire Create(LogicalCircuit logicalCircuit, GridPoint point1, GridPoint point2)
 {
     return(this.CreateItem(Guid.NewGuid(), logicalCircuit, point1.X, point1.Y, point2.X, point2.Y));
 }
Example #21
0
        private bool NeedToShift(List <Symbol> list)
        {
            bool covered(int pos1, int size1, int pos2, int size2) => pos2 <= pos1 && pos1 + size1 <= pos2 + size2;

            HashSet <Symbol> exclude = new HashSet <Symbol>(list);
            bool             need    = false;
            LogicalCircuit   target  = this.ProjectSet.Project.LogicalCircuit;

            foreach (Symbol symbol in list)
            {
                if (symbol is CircuitSymbol circuitSymbol)
                {
                    if (Symbol.LogicalCircuitGridWidth <= circuitSymbol.X + circuitSymbol.Circuit.SymbolWidth ||
                        Symbol.LogicalCircuitGridHeight <= circuitSymbol.Y + circuitSymbol.Circuit.SymbolHeight
                        )
                    {
                        return(false);
                    }
                    if (target.CircuitSymbols().Any(other =>
                                                    !exclude.Contains(other) && circuitSymbol.Circuit.Similar(other.Circuit) &&
                                                    covered(circuitSymbol.X, circuitSymbol.Circuit.SymbolWidth, other.X, other.Circuit.SymbolWidth) &&
                                                    covered(circuitSymbol.Y, circuitSymbol.Circuit.SymbolHeight, other.Y, other.Circuit.SymbolHeight)
                                                    ))
                    {
                        need = true;
                    }
                }
                else if (symbol is TextNote textNote)
                {
                    if (Symbol.LogicalCircuitGridWidth <= textNote.X + textNote.Width ||
                        Symbol.LogicalCircuitGridHeight <= textNote.Y + textNote.Height
                        )
                    {
                        return(false);
                    }
                    if (target.TextNotes().Any(other => !exclude.Contains(other) &&
                                               covered(textNote.X, textNote.Width, other.X, other.Width) &&
                                               covered(textNote.Y, textNote.Height, other.Y, other.Height)
                                               ))
                    {
                        need = true;
                    }
                }
                else if (symbol is Wire wire)
                {
                    if (Symbol.LogicalCircuitGridWidth <= wire.X1 || Symbol.LogicalCircuitGridWidth <= wire.X2 ||
                        Symbol.LogicalCircuitGridHeight <= wire.Y1 || Symbol.LogicalCircuitGridHeight <= wire.Y2
                        )
                    {
                        return(false);
                    }
                    if (target.Wires().Any(other => !exclude.Contains(other) && (
                                               wire.Point1 == other.Point1 || wire.Point1 == other.Point2 ||
                                               wire.Point2 == other.Point1 || wire.Point2 == other.Point2
                                               )))
                    {
                        need = true;
                    }
                }
            }
            return(need);
        }
Example #22
0
 public override Symbol CopyTo(LogicalCircuit target)
 {
     return(target.CircuitProject.WireSet.Copy(this, target));
 }
Example #23
0
 public abstract Circuit CopyTo(LogicalCircuit target);
 public bool IsConnected(LogicalCircuit logicalCircuit)
 {
     return(this.connected.Contains(logicalCircuit));
 }
Example #25
0
 public override Circuit CopyTo(LogicalCircuit target)
 {
     return(target.CircuitProject.GateSet.Gate(this.GateId));
 }
 public void MarkConnected(LogicalCircuit logicalCircuit)
 {
     Tracer.Assert(!this.IsConnected(logicalCircuit));
     this.connected.Add(logicalCircuit);
 }
Example #27
0
 protected override void UpdateGlyph(LogicalCircuit logicalCircuit)
 {
     this.CircuitDescriptorList.UpdateGlyph(logicalCircuit);
 }
 public override Symbol CopyTo(LogicalCircuit target)
 {
     throw new InvalidOperationException();
 }
Example #29
0
 public override void Edit(LogicalCircuit logicalCircuit)
 {
     this.Mainframe.ShowDialog(new DialogCircuit(logicalCircuit));
 }
Example #30
0
 // Selects CircuitSymbol by LogicalCircuit
 public IEnumerable <CircuitSymbol> SelectByLogicalCircuit(LogicalCircuit logicalCircuit)
 {
     return(this.Select(this.Table.Select(CircuitSymbolData.LogicalCircuitIdField.Field, logicalCircuit.LogicalCircuitId)));
 }