public LogicalCircuit Copy(LogicalCircuit other, bool deepCopy) { LogicalCircuit logicalCircuit = this.FindByLogicalCircuitId(other.LogicalCircuitId); Tracer.Assert(deepCopy || logicalCircuit == null); if (logicalCircuit == null) { LogicalCircuitData data; other.CircuitProject.LogicalCircuitSet.Table.GetData(other.LogicalCircuitRowId, out data); data.Name = this.UniqueName(data.Name); data.LogicalCircuit = null; logicalCircuit = this.Register(this.Table.Insert(ref data)); if (deepCopy) { foreach (CircuitSymbol symbol in other.CircuitSymbols()) { symbol.CopyTo(logicalCircuit); } foreach (Wire wire in other.Wires()) { wire.CopyTo(logicalCircuit); } foreach (TextNote symbol in other.TextNotes()) { symbol.CopyTo(logicalCircuit); } } } return(logicalCircuit); }
public void SelectAllProbes(bool withWire) { if (this.InEditMode) { LogicalCircuit logicalCircuit = this.Project.LogicalCircuit; foreach (CircuitSymbol symbol in logicalCircuit.CircuitSymbols()) { if (symbol.Circuit is CircuitProbe) { this.Select(symbol); if (withWire) { Tracer.Assert(symbol.Jams().Count() == 1); GridPoint point = symbol.Jams().First().AbsolutePoint; foreach (Wire wire in logicalCircuit.Wires()) { if (wire.Point1 == point || wire.Point2 == point) { this.Select(wire); } } } } } } }
public int SelectFreeWires() { if (this.InEditMode) { LogicalCircuit logicalCircuit = this.Project.LogicalCircuit; Dictionary <GridPoint, int> pointCount = new Dictionary <GridPoint, int>(); Dictionary <GridPoint, Wire> firstWire = new Dictionary <GridPoint, Wire>(); foreach (Wire wire in logicalCircuit.Wires()) { Tracer.Assert(wire.Point1 != wire.Point2); int count; if (pointCount.TryGetValue(wire.Point1, out count)) { if (count < 2) { pointCount[wire.Point1] = count + 1; } } else { pointCount.Add(wire.Point1, 1); firstWire.Add(wire.Point1, wire); } if (pointCount.TryGetValue(wire.Point2, out count)) { if (count < 2) { pointCount[wire.Point2] = count + 1; } } else { pointCount.Add(wire.Point2, 1); firstWire.Add(wire.Point2, wire); } } foreach (CircuitSymbol symbol in logicalCircuit.CircuitSymbols()) { foreach (Jam jam in symbol.Jams()) { int count; if (pointCount.TryGetValue(jam.AbsolutePoint, out count) && count < 2) { pointCount[jam.AbsolutePoint] = count + 1; } } } int freeWireCount = 0; foreach (KeyValuePair <GridPoint, int> pair in pointCount) { if (pair.Value < 2) { this.Select(firstWire[pair.Key]); freeWireCount++; } } return(freeWireCount); } return(0); }
public int SelectFloatingSymbols() { if (this.InEditMode) { LogicalCircuit logicalCircuit = this.Project.LogicalCircuit; HashSet <GridPoint> wirePoint = new HashSet <GridPoint>(); foreach (Wire wire in logicalCircuit.Wires()) { wirePoint.Add(wire.Point1); wirePoint.Add(wire.Point2); } int count = 0; foreach (CircuitSymbol symbol in logicalCircuit.CircuitSymbols()) { foreach (Jam jam in symbol.Jams()) { if (!wirePoint.Contains(jam.AbsolutePoint)) { this.Select(symbol); count++; break; } } } return(count); } return(0); }
public ConductorMap(LogicalCircuit logicalCircuit) { foreach (Wire wire in logicalCircuit.Wires()) { GridPoint p1 = wire.Point1; GridPoint p2 = wire.Point2; Tracer.Assert(p1 != p2); Conductor conductor; if (this.TryGetValue(p1, out conductor)) { Conductor other; if (!this.TryGetValue(p2, out other)) { this.map.Add(p2, conductor); } else if (conductor != other) { conductor = this.Join(conductor, other); } } else if (this.TryGetValue(p2, out conductor)) { this.map.Add(p1, conductor); } else { conductor = new Conductor(); this.map.Add(p1, conductor); this.map.Add(p2, conductor); this.list.Add(conductor); } conductor.Add(wire); } }
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); }
public void SelectAll() { if (this.InEditMode) { LogicalCircuit logicalCircuit = this.Project.LogicalCircuit; foreach (CircuitSymbol symbol in logicalCircuit.CircuitSymbols()) { this.Select(symbol); } foreach (Wire wire in logicalCircuit.Wires()) { this.Select(wire); } foreach (TextNote symbol in logicalCircuit.TextNotes()) { this.Select(symbol); } } }
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); }
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); }