public void MergeShapes(DiagramDocumentCore other) { var otherShapes = other.Shapes.Clone(); var otherStyles = other.Styles.Clone(); var oldShapes = _core.Shapes.Clone(); int oldStyleCount = _core.Styles.Count; _undoStack.Do(@do => { if (@do) { foreach (Shape shape in otherShapes) { shape.OnBeingAdded(this); } int added = _core.Shapes.AddRange(otherShapes); Debug.Assert(added == otherShapes.Count); _core.Styles.AddRange(otherStyles); if (AfterShapesAdded != null) { AfterShapesAdded(otherShapes); } } else { foreach (Shape shape in otherShapes) { shape.OnBeingRemoved(this); } _core.Shapes = oldShapes; Debug.Assert(_core.Styles.Count - other.Styles.Count == oldStyleCount); _core.Styles.Resize(oldStyleCount); } }, true); }
public DiagramDocument(DiagramDocumentCore core = null) { _undoStack = new DDUndoStack(this); _core = core ?? new DiagramDocumentCore(); foreach (var shape in _core.Shapes) shape.OnBeingAdded(this); }
public DiagramDocument(DiagramDocumentCore core = null) { _undoStack = new DDUndoStack(this); _core = core ?? new DiagramDocumentCore(); foreach (var shape in _core.Shapes) { shape.OnBeingAdded(this); } }
private MemoryStream SerializeSelected() { var doc = new DiagramDocumentCore(); doc.Shapes.AddRange(_selectedShapes); // no need to populate doc.Styles, it is not used for copy/paste var buf = new MemoryStream(); doc.Save(buf); return(buf); }
private DiagramDocumentCore DeserializeAndEliminateDuplicateStyles(Stream buf) { var doc = DiagramDocumentCore.Load(buf); doc.Styles.Clear(); foreach (var shape in doc.Shapes) { var style = _doc.Styles.Where(s => s.Equals(shape.Style)).FirstOrDefault(); if (style != null) { shape.Style = style; } else { doc.Styles.Add(shape.Style); } } return(doc); }
private MemoryStream SerializeSelected() { var doc = new DiagramDocumentCore(); doc.Shapes.AddRange(_selectedShapes); // no need to populate doc.Styles, it is not used for copy/paste var buf = new MemoryStream(); doc.Save(buf); return buf; }
public static DiagramDocument Load(Stream stream) { var core = DiagramDocumentCore.Load(stream); return(new DiagramDocument(core)); }
public void MergeShapes(DiagramDocumentCore other) { var otherShapes = other.Shapes.Clone(); var otherStyles = other.Styles.Clone(); var oldShapes = _core.Shapes.Clone(); int oldStyleCount = _core.Styles.Count; _undoStack.Do(@do => { if (@do) { foreach (Shape shape in otherShapes) shape.OnBeingAdded(this); int added = _core.Shapes.AddRange(otherShapes); Debug.Assert(added == otherShapes.Count); _core.Styles.AddRange(otherStyles); if (AfterShapesAdded != null) AfterShapesAdded(otherShapes); } else { foreach (Shape shape in otherShapes) shape.OnBeingRemoved(this); _core.Shapes = oldShapes; Debug.Assert(_core.Styles.Count - other.Styles.Count == oldStyleCount); _core.Styles.Resize(oldStyleCount); } }, true); }