// ------------------------------------------------------------------ /// <summary> /// Unwraps the specified collection. /// </summary> /// <param name="collection">The collection.</param> // ------------------------------------------------------------------ public void Unwrap(CollectionBase <IDiagramEntity> collection) { if (collection == null) { return; } foreach (IDiagramEntity entity in collection) { Unwrap(entity); } //reconnect the connectors, just like the deserialization of a filed diagram Dictionary <Guid, Anchor> .Enumerator enumer = Anchors.GetEnumerator(); System.Collections.Generic.KeyValuePair <Guid, Anchor> pair; Anchor anchor; while (enumer.MoveNext()) { pair = enumer.Current; anchor = pair.Value; if (anchor.Parent != Guid.Empty) //there's a parent connector { if (Anchors.ContainsKey(anchor.Parent)) { Anchors.GetAnchor(anchor.Parent).Instance.AttachConnector(anchor.Instance); } } } //clean up the anchoring matrix Anchors.Clear(); }
/// <summary> /// Called when the tool is activated. /// </summary> protected override void OnActivateTool() { if (Selection.SelectedItems.Count == 0) { return; } try { //Clear the Anchors otherwise subsequent Copy operations will raise an exception due to the fact that the Anchors class is a static helper class Anchors.Clear(); //this will create a volatile collection of entities, they need to be unwrapped! //I never managed to get things working by putting the serialized collection directly onto the Clipboad. Thanks to Leppie's suggestion it works by //putting the Stream onto the Clipboard, which is weird but it works. MemoryStream copy = Selection.SelectedItems.ToStream(); DataFormats.Format format = DataFormats.GetFormat(typeof(CopyTool).FullName); IDataObject dataObject = new DataObject(); dataObject.SetData(format.Name, false, copy); Clipboard.SetDataObject(dataObject, false); } catch (Exception exc) { throw new InconsistencyException("The Copy operation failed.", exc); } finally { DeactivateTool(); } }
/// <summary> /// Runs when the entire object graph has been deserialized. /// </summary> /// <param name="sender">The object that initiated the callback. The functionality for this parameter is not currently implemented.</param> public void OnDeserialization(object sender) { if (Tracing.BinaryDeserializationSwitch.Enabled) { Trace.WriteLine("IDeserializationCallback of 'Model' called."); } Init(); #region Binding of connectors Dictionary <Guid, Anchor> .Enumerator enumer = Anchors.GetEnumerator(); System.Collections.Generic.KeyValuePair <Guid, Anchor> pair; Anchor anchor; while (enumer.MoveNext()) { pair = enumer.Current; anchor = pair.Value; if (anchor.Parent != Guid.Empty) //there's a parent connector { if (Anchors.ContainsKey(anchor.Parent)) { Anchors.GetAnchor(anchor.Parent).Instance.AttachConnector(anchor.Instance); } } } //clean up the anchoring matrix Anchors.Clear(); #endregion }
void OnDeserializing(StreamingContext context) { if (Tracing.BinaryDeserializationSwitch.Enabled) { Trace.WriteLine("Starting deserializing the 'Model' class..."); } //the anchors is a temporary collection of Uid's and parent entities to re-connect connectors //to their parent. The serialization process does serialize parenting because you need on deserialization an //instance in order to connect to it. Anchors.Clear(); }
/// <summary> /// Deserialization constructor /// </summary> /// <param name="info">The info.</param> /// <param name="context">The context.</param> protected ConnectorBase(SerializationInfo info, StreamingContext context) : base(info, context) { if (Tracing.BinaryDeserializationSwitch.Enabled) { Trace.WriteLine("Deserializing the fields of 'ConnectorBase'."); } this.mPoint = (Point)info.GetValue("Point", typeof(Point)); attachedConnectors = new CollectionBase <IConnector>(); #region Preparation of the anchoring process Guid tuid = new Guid(info.GetString("AttachedTo")); Anchors.Add(this.Uid, new Anchor(tuid, this)); #endregion }
/// <summary> /// Called when the tool is activated. /// </summary> protected override void OnActivateTool() { try { IDataObject data = Clipboard.GetDataObject(); string format = typeof(CopyTool).FullName; if (data.GetDataPresent(format)) { MemoryStream stream = data.GetData(format) as MemoryStream; CollectionBase <IDiagramEntity> collection = null; GenericFormatter <BinaryFormatter> f = new GenericFormatter <BinaryFormatter>(); //Anchors collection is a helper collection to re-connect connectors to their parent Anchors.Clear(); //but is it actually a stream coming this application? collection = f.Deserialize <CollectionBase <IDiagramEntity> >(stream); if (collection != null) { #region Unwrap the bundle this.Controller.Model.Unwrap(collection); Rectangle rec = Utils.BoundingRectangle(collection); rec.Inflate(30, 30); this.Controller.View.Invalidate(rec); #endregion } } else if (data.GetDataPresent(DataFormats.Bitmap)) { Bitmap bmp = data.GetData(DataFormats.Bitmap) as Bitmap; if (bmp != null) { #region Unwrap into an image shape //TODO: Insert the image shape here #endregion } } } catch (Exception exc) { throw new InconsistencyException("The Copy operation failed.", exc); } finally { DeactivateTool(); } }
// ------------------------------------------------------------------ /// <summary> /// Called when the tool is activated. /// </summary> // ------------------------------------------------------------------ protected override void OnActivateTool() { if (this.Controller.Model.Selection.SelectedItems.Count == 0) { return; } try { //Clear the Anchors otherwise subsequent Copy operations will // raise an exception due to the fact that the Anchors class // is a static helper class. Anchors.Clear(); // First add the image to the Windows Clipboard so it can be // pasted into other applications, like PowerPoint. Bitmap image = this.Controller.Model.Selection.ToBitmap(); Clipboard.SetDataObject(image, true); // This will create a volatile collection of entities, but they // need to be unwrapped! I never managed to get things // working by putting the serialized collection directly onto // the Clipboad. Thanks to Leppie's suggestion it works by // putting the Stream onto the Clipboard, which is weird but // it works. //MemoryStream copy = Selection.SelectedItems.ToStream(); //DataFormats.Format format = // DataFormats.GetFormat(typeof(CopyTool).FullName); //IDataObject dataObject = new DataObject(); //dataObject.SetData(format.Name, false, copy); //Clipboard.SetDataObject(dataObject, false); // Rather than placing the stream of entities on the Windows // Clipboard, we're using our custom clipboard to keep the // Windows clipboard for moving data across apps. NetronClipboard.Clear(); NetronClipboard.Add(this.Controller.Model.Selection.SelectedItems.Copy()); } catch (Exception exc) { //throw new InconsistencyException( // "The Copy operation failed.", exc); MessageBox.Show("Unable to copy the selection.\n\n" + "Error Message: " + exc.Message); } finally { DeactivateTool(); } }
/// <summary> /// Deserialization constructor /// </summary> /// <param name="info">The info.</param> /// <param name="context">The context.</param> protected ConnectorBase(SerializationInfo info, StreamingContext context) : base(info, context) { if (Tracing.BinaryDeserializationSwitch.Enabled) { Trace.WriteLine("Deserializing the fields of 'ConnectorBase'."); } double version = info.GetDouble("ConnectorBaseVersion"); this.mShowName = info.GetBoolean("ShowName"); this.mNameLocation = (ConnectorNameLocation)info.GetValue( "NameLocation", typeof(ConnectorNameLocation)); this.mPoint = (Point)info.GetValue("Point", typeof(Point)); mAttachedConnectors = new CollectionBase <IConnector>(); #region Preparation of the anchoring process Guid tuid = new Guid(info.GetString("AttachedTo")); Anchors.Add(this.Uid, new Anchor(tuid, this)); #endregion }
/// <summary> /// Called when the tool is activated. /// </summary> protected override void OnActivateTool() { try { // Used to get a collection of entities from the // NetronClipboard. Type entitiesType = typeof(CollectionBase <IDiagramEntity>); // First calculate the insertion point based on the // current location of the cursor. InsertionPoint = Point.Round( Controller.View.ViewToWorld( Controller.View.DeviceToView( Controller.ParentControl.PointToClient(Cursor.Position)))); IDataObject data = Clipboard.GetDataObject(); string format = typeof(CopyTool).FullName; if (data.GetDataPresent(format)) { MemoryStream stream = data.GetData(format) as MemoryStream; CollectionBase <IDiagramEntity> collection = null; GenericFormatter <BinaryFormatter> f = new GenericFormatter <BinaryFormatter>(); //Anchors collection is a helper collection to re-connect connectors to their parent Anchors.Clear(); //but is it actually a stream coming this application? collection = f.Deserialize <CollectionBase <IDiagramEntity> >(stream); UnwrapBundle(collection); } else if (NetronClipboard.ContainsData(entitiesType)) { CollectionBase <IDiagramEntity> collection = (CollectionBase <IDiagramEntity>)NetronClipboard.Get( entitiesType); UnwrapBundle(collection.DeepCopy()); } else if (data.GetDataPresent(DataFormats.Bitmap)) { Bitmap bmp = data.GetData(DataFormats.Bitmap) as Bitmap; if (bmp != null) { #region Unwrap into an image shape //TODO: Insert the image shape here ImageShape shape = new ImageShape(); shape.Image = bmp; shape.Location = InsertionPoint; Controller.Model.AddShape(shape); #endregion } } else if (data.GetDataPresent(DataFormats.Text)) { string text = (string)data.GetData(typeof(string)); TextOnly textShape = new TextOnly(Controller.Model); textShape.Text = text; textShape.Location = InsertionPoint; Controller.Model.AddShape(textShape); } } catch (Exception exc) { throw new InconsistencyException("The Paste operation failed.", exc); } finally { DeactivateTool(); } }