Example #1
0
        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);
        }
Example #2
0
		public DiagramDocument(DiagramDocumentCore core = null)
		{
			_undoStack = new DDUndoStack(this);
			_core = core ?? new DiagramDocumentCore();
			foreach (var shape in _core.Shapes)
				shape.OnBeingAdded(this);
		}
Example #3
0
 public DiagramDocument(DiagramDocumentCore core = null)
 {
     _undoStack = new DDUndoStack(this);
     _core      = core ?? new DiagramDocumentCore();
     foreach (var shape in _core.Shapes)
     {
         shape.OnBeingAdded(this);
     }
 }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
		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;
		}
Example #7
0
        public static DiagramDocument Load(Stream stream)
        {
            var core = DiagramDocumentCore.Load(stream);

            return(new DiagramDocument(core));
        }
Example #8
0
		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);
		}