// ------------------------------------------------------------------ /// <summary> /// Removes all entities that are currently selected. /// </summary> /// <param name="entity">The entity.</param> // ------------------------------------------------------------------ public void RemoveSelectedItems() { if (this.Selection.SelectedItems.Count < 1) { return; } int numberOfItems = this.Selection.SelectedItems.Count; for (int i = 0; i < numberOfItems - 1; i++) { IDiagramEntity entity = Selection.SelectedItems[0]; foreach (IPage page in mPages) { foreach (ILayer layer in page.Layers) { if (layer.Entities.Contains(entity)) { layer.Entities.Remove(entity); entity.Detached(DefaultPage.DefaultLayer); } } } } }
/// <summary> /// Sends the entity up the z-order stack with the specified amount. /// </summary> /// <param name="entity">The entity.</param> /// <param name="zShift">The z shift.</param> public void SendForwards(IDiagramEntity entity, int zShift) { ILayer layer = CurrentPage.GetLayer(entity); if (layer != null) { int newpos = layer.Entities.IndexOf(entity) + zShift; //if this is the last in the row you cannot move it higher if (newpos < layer.Entities.Count) { layer.Entities.Remove(entity); layer.Entities.Insert(newpos, entity); //does it works when this is an addition at the top? ReAssignSceneIndex(layer.Entities); Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } } //if (Paintables.Contains(entity) && zShift>=1) //{ // int newpos = Paintables.IndexOf(entity) + zShift; // //if this is the last in the row you cannot move it higher // if (newpos < Paintables.Count) // { // Paintables.Remove(entity); // Paintables.Insert(newpos, entity); //does it works when this is an addition at the top? // ReAssignSceneIndex(Paintables); // Rectangle rec = entity.Rectangle; // rec.Inflate(20, 20); // this.RaiseOnInvalidateRectangle(Rectangle); // } //} }
// ------------------------------------------------------------------ /// <summary> /// Sets the model (recursively) on the given entity. /// </summary> /// <param name="entity">The entity.</param> // ------------------------------------------------------------------ public void SetModel(IDiagramEntity entity) { if (entity is IConnector) { (entity as IConnector).Model = this; } else if (entity is IConnection) { IConnection con = entity as IConnection; con.Model = this; Debug.Assert(con.From != null, "The 'From' connector is not set."); con.From.Model = this; Debug.Assert(con.From != null, "The 'To' connector is not set."); con.To.Model = this; } else if (entity is IShape) { IShape shape = entity as IShape; shape.Model = this; foreach (IConnector co in shape.Connectors) { co.Model = this; } } else if (entity is IGroup) { IGroup group = entity as IGroup; group.Model = this; foreach (IDiagramEntity child in group.Entities) { SetModel(child); } } }
/// <summary> /// Sends the entity down the z-order stack with the specified amount. /// </summary> /// <param name="entity">The entity.</param> /// <param name="zShift">The z shift.</param> public void SendBackwards(IDiagramEntity entity, int zShift) { ILayer layer = CurrentPage.GetLayer(entity); if (layer != null) { int newpos = layer.Entities.IndexOf(entity) - zShift; //if this is the first in the row you cannot move it lower if (newpos >= 0) { layer.Entities.Remove(entity); layer.Entities.Insert(newpos, entity); ReAssignSceneIndex(layer.Entities); Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } } //if (Paintables.Contains(entity)) //{ // int newpos = Paintables.IndexOf(entity) - zShift; // //if this is the first in the row you cannot move it lower // if (newpos >= 0) // { // Paintables.Remove(entity); // Paintables.Insert(newpos, entity); // ReAssignSceneIndex(Paintables); // Rectangle rec = entity.Rectangle; // rec.Inflate(20, 20); // this.RaiseOnInvalidateRectangle(Rectangle); // } //} }
public void Remove(IDiagramEntity entity) { if (DefaultPage.DefaultLayer.Entities.Contains(entity)) { DefaultPage.DefaultLayer.Entities.Remove(entity); } }
public void DiagramEntitySelected(IDiagramEntity obj) { if (EditModel == null) { return; } if (obj is DiagramShape) { var shape = (DiagramShape)obj; IModelObject entity; if (ShapeLookup.TryGetValue(shape, out entity)) { EditModel.ShowObjectPropertyGrid(entity); if (entity is ModelObject) { EditModel.SyncCurrentlySelectedObject(entity as ModelObject); } } } else if (obj is Connection) { var connection = (Connection)obj; IModelObject rel; if (ConnectionLookup.TryGetValue(connection, out rel)) { EditModel.ShowObjectPropertyGrid(rel); if (rel is ModelObject) { EditModel.SyncCurrentlySelectedObject(rel as ModelObject); } } } }
/// <summary> /// Unwraps an entity /// <list type="bullet"> /// <term>Uid</term><description>Generates a new <see cref="IDiagramEntity.Uid"/> for the entity. </description> /// <tem>Model</tem><description>Assigns the Model property to the entity.</description> /// /// </list> /// </summary> public void Unwrap(IDiagramEntity entity) { //set a new unique identifier for this copied object entity.NewUid(true); //this assignment will be recursive if needed SetModel(entity); DefaultPage.DefaultLayer.Entities.Add(entity); }
// ------------------------------------------------------------------ /// <summary> /// Removes the specified entity. /// </summary> /// <param name="entity">The entity.</param> // ------------------------------------------------------------------ public void Remove(IDiagramEntity entity) { if (CurrentPage.DefaultLayer.Entities.Contains(entity)) { CurrentPage.DefaultLayer.Entities.Remove(entity); entity.Detached(CurrentPage.DefaultLayer); } }
/// <summary> /// Initializes a new instance of the <see cref="T:EntityMenuEventArgs"/> class. /// </summary> /// <param name="entity">The entity.</param> /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> /// <param name="additionalItems">The additional items.</param> public EntityMenuEventArgs( IDiagramEntity entity, MouseEventArgs e, ref ToolStripItem[] additionalItems) { this.entity = entity; this.e = e; this.additionalItems = additionalItems; }
public EntityMouseEventArgs(IDiagramEntity entity, MouseEventArgs e) : base(e.Button, e.Clicks, e.X, e.Y, e.Delta) { if (e == null) { throw new ArgumentNullException("The argument object is 'null'"); } this.mEntity = entity; }
public void MouseMove(MouseEventArgs e) { if (!IsSuspended && this.Enabled) { IHoverListener listener = null; CollectionBase<IDiagramEntity> paintables= this.Controller.Model.Paintables; IDiagramEntity entity; if(paintables.Count==0) return; //going from top to the bottom of the z-order for (int k=paintables.Count-1; k>=0; k--) { entity = paintables[k]; if(entity.Rectangle.Contains(e.Location)) //we caught an entity { //unhover the previous, if any if(previousHovered != null) previousHovered.Hovered = false; entity.Hovered = true; //tell the current one it's being hovered //fetch the hovering service, if defined listener = entity.GetService(typeof(IHoverListener)) as IHoverListener; if(listener != null) //the caught entity does listen { if(currentListener == listener) //it's the same as the previous time listener.MouseHover(e); else //we moved from one entity to another listening entity { if(currentListener!=null) //tell the previous entity we are leaving currentListener.MouseLeave(e); listener.MouseEnter(e); //tell the current one we enter currentListener = listener; } } else //the caught entity does not listen { if(currentListener != null) { currentListener.MouseLeave(e); currentListener = null; } } previousHovered = entity;//remember, for the next time return; //if another entity is listening underneath this entity it will not receive the notification } } if(currentListener != null) { currentListener.MouseLeave(e); currentListener = null; } //unhover the previous, if any if(previousHovered != null) previousHovered.Hovered = false; } }
// ------------------------------------------------------------------ /// <summary> /// Adds an entity to the diagram. The magnification level for the /// entity is set to the current magnification level of the current /// page. /// </summary> /// <param name="entity">IDiagramEntity: The entity to add.</param> /// <returns>IDiagramEntity: The added entity.</returns> // ------------------------------------------------------------------ public IDiagramEntity AddEntity(IDiagramEntity entity) { SetModel(entity); //By default the new entity is added to the default layer in the // current page. CurrentPage.DefaultLayer.Entities.Add(entity); entity.Attached(CurrentPage.DefaultLayer); entity.Magnification = CurrentPage.Magnification; return(entity); }
public void SendToFront(IDiagramEntity entity) { if (mPaintables.Contains(entity)) { mPaintables.Remove(entity); mPaintables.Add(entity); Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } }
internal void RemoveFromPaintables(IDiagramEntity entity) { this.Model.Paintables.Remove(entity); if (entity is CollapsibleGroupShape && !(entity as CollapsibleGroupShape).Collapsed) { foreach (IDiagramEntity ent in (entity as CollapsibleGroupShape).Entities) { RemoveFromPaintables(ent); } } }
internal void AddToPaintables(IDiagramEntity entity) { this.Model.Paintables.Add(entity); if (entity is CollapsibleGroupShape && !(entity as CollapsibleGroupShape).Collapsed) { foreach (IDiagramEntity ent in (entity as CollapsibleGroupShape).Entities) { AddToPaintables(ent); } } }
// ------------------------------------------------------------------ /// <summary> /// Gets the layer that has the entity specified. If the entity /// specified could not be found, 'null' is returned. /// </summary> /// <param name="entity">IDiagramEntity</param> /// <returns>ILayer</returns> // ------------------------------------------------------------------ public ILayer GetLayer(IDiagramEntity entity) { foreach (ILayer layer in mLayers) { if (layer.Entities.Contains(entity)) { return(layer); } } return(null); }
/// <summary> /// Sends to entity to the bottom of the z-order stack. /// </summary> /// <param name="entity">The entity.</param> public void SendToBack(IDiagramEntity entity) { if (mPaintables.Contains(entity)) { mPaintables.Remove(entity); mPaintables.Insert(0, entity); ReAssignSceneIndex(); Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } }
public void SendForwards(IDiagramEntity entity, int zShift) { if (mPaintables.Contains(entity) && zShift >= 1) { int newpos = mPaintables.IndexOf(entity) + zShift; //if this is the last in the row you cannot move it higher if (newpos < mPaintables.Count) { mPaintables.Remove(entity); mPaintables.Insert(newpos, entity); //does it works when this is an addition at the top? Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } } }
public void SendBackwards(IDiagramEntity entity, int zShift) { if (mPaintables.Contains(entity)) { int newpos = mPaintables.IndexOf(entity) - zShift; //if this is the first in the row you cannot move it lower if (newpos >= 0) { mPaintables.Remove(entity); mPaintables.Insert(newpos, entity); Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } } }
// ------------------------------------------------------------------ /// <summary> /// Aligns the center of all selected entities horizontally. The /// 'X' component of the center location of the first entity in the /// selection is used for all other entities. /// </summary> // ------------------------------------------------------------------ public override void Align(IDiagramEntity[] entities) { // The amount to offset the entities by. Point offset; for (int i = 1; i < entities.Length; i++) { IDiagramEntity entity = entities[i]; // Keep the entities same y location but offset it's // x location. offset = new Point( this.centerOfFirstEntity.X - entity.Center.X, 0); // Move the entity by this amount. entity.MoveBy(offset); } }
internal void SelectEntity(IDiagramEntity entity, Point surfacePoint) { // Groups are treated specially because we can drill-down // into the group. The process of drilling is the first // mouse hit will select the group. The second mouse hit // will select a child, if there's a child at that point. if (entity is IGroup) { if (entity.IsSelected == false) { entity.IsSelected = true; mSelection.Add(entity); } else { IGroup group = entity as IGroup; for (int j = group.Entities.Count - 1; j >= 0; j--) { IDiagramEntity child = group.Entities[j]; if (child.Hit(surfacePoint)) { // Repeat the process because what if this // child is too a group! SelectEntity(child, surfacePoint); group.IsSelected = false; if (mSelection.Contains(group)) { mSelection.Remove(group); } break; } } } } //else if (entity.Group != null) //{ // //entity.Group.IsSelected = true; // //mSelection.Add(entity.Group); //} else { entity.IsSelected = true; mSelection.Add(entity); } }
// ------------------------------------------------------------------ /// <summary> /// Activates the tool. First a check is performed to ensure there /// are at least two IDiagramEntities selected. If so, then the /// x, y, top edge, bottom edge, and center of the first entity /// is stored in local, protected variables for all other alignment /// tools to use. /// </summary> // ------------------------------------------------------------------ protected override void OnActivateTool() { base.OnActivateTool(); // Make sure enough items were selected. if (this.Controller.Model.Selection.SelectedItems == null) { MessageBox.Show( "Nothing is selected, you need to select at " + "least two items to align.", "Nothing selected.", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } if (this.Controller.Model.Selection.SelectedItems.Count <= 1) { MessageBox.Show( "You need to select at least two items to align.", "Nothing selected.", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } // Since there are enough items, peform the alignment. But // first get all aspects about the location of the first // entity. this.firstEntity = this.Controller.Model.Selection.SelectedItems[0]; this.xLocationOfFirstEntity = firstEntity.Rectangle.X; this.yLocationOfFirstEntity = firstEntity.Rectangle.Y; this.topEdgeOfFirstEntity = firstEntity.Rectangle.Top; this.bottomEdgeOfFirstEntity = firstEntity.Rectangle.Bottom; this.rightEdgeOfFirstEntity = firstEntity.Rectangle.Right; this.centerOfFirstEntity = firstEntity.Center; this.Align(this.Controller.Model.Selection.SelectedItems.ToArray()); // Reset the Tracker. this.Controller.View.ShowTracker(); DeactivateTool(); }
void NetronEntityRemovedHandler(object sender, EntityEventArgs e) { IDiagramEntity entity = e.Entity; SignalShape ss = entity as SignalShape; if (ss != null) { if (!_bridge.Signals.ContainsValue(ss)) { return; } _bridge.Signals.Remove(ss.SignalReference.InstanceId); PostCommandRemoveSignal(ss.SignalReference, true); return; } BusShape bs = entity as BusShape; if (bs != null) { if (!_bridge.Buses.ContainsValue(bs)) { return; } _bridge.Buses.Remove(bs.BusReference.InstanceId); PostCommandRemoveBus(bs.BusReference); return; } PortShape ps = entity as PortShape; if (ps != null) { if (!_bridge.Ports.ContainsValue(ps)) { return; } _bridge.Ports.Remove(ps.PortReference.InstanceId); PostCommandRemovePort(ps.PortReference, true); return; } IConnection cn = entity as IConnection; if (cn != null) { } }
// ------------------------------------------------------------------ /// <summary> /// Aligns the center of all selected entities vertically. The /// 'Y' component of the center location of the first entity in the /// selection is used for all other entities. /// </summary> // ------------------------------------------------------------------ public override void Align(IDiagramEntity[] entities) { // The amount to offset the entities by. Point offset; for (int i = 1; i < entities.Length; i++) { IDiagramEntity entity = entities[i]; // Keep the entities same x location but offset it's // y location. offset = new Point( 0, this.centerOfFirstEntity.Y - entity.Center.Y); // Move the entity by this amount. entity.MoveBy(offset); } }
// ------------------------------------------------------------------ /// <summary> /// Aligns the bottom edges of all selected entities. The vertical /// location of the first entity in the selection is used for all /// other entities vertical location. /// </summary> // ------------------------------------------------------------------ public override void Align(IDiagramEntity[] entities) { // We want to align the bottom edges, so we need to set the // vertical location of each shape to one value. We're // going use the first entity in the selection to determine // this setting. Point offset; for (int i = 1; i < entities.Length; i++) { IDiagramEntity entity = entities[i]; // Keep the entities same y location but offset it's // x location. offset = new Point( 0, this.bottomEdgeOfFirstEntity - entity.Rectangle.Bottom); // Move the entity by this amount. entity.MoveBy(offset); } }
protected override void OnActivateTool() { base.OnActivateTool(); DeleteCommand cmd; if (this.Controller.Model.Selection.SelectedItems.Count > 0) { // If any one entity in the selction can't be deleted, // remove it from the selection. for (int i = 0; i < this.Controller.Model.Selection.SelectedItems.Count; i++) { IDiagramEntity entity = this.Controller.Model.Selection.SelectedItems[i]; if (entity.AllowDelete == false) { this.Controller.Model.Selection.SelectedItems.Remove(entity); i--; } } cmd = new DeleteCommand( this.Controller, this.Controller.Model.Selection.SelectedItems.Copy()); this.Controller.UndoManager.AddUndoCommand(cmd); // Alert each entity that they're about to be deleted. foreach (IDiagramEntity entity in this.Controller.Model.Selection.SelectedItems) { entity.OnBeforeDelete(cmd); } cmd.Redo(); // Alert each entity that they have been deleted. foreach (IDiagramEntity entity in this.Controller.Model.Selection.SelectedItems) { entity.OnAfterDelete(cmd); } } DeactivateTool(); }
/// <summary> /// Perform undo of this command. /// </summary> public override void Undo() { if (mGroup.CanUnGroup == false) { return; } //remove the group from the layer this.Controller.Model.DefaultPage.DefaultLayer.Entities.Remove(mGroup); // keep track of the entities removed. CollectionBase <IDiagramEntity> removedItems = new CollectionBase <IDiagramEntity>(); int numberOfItems = mGroup.Entities.Count; //detach the entities from the group for (int i = 0; i < numberOfItems; numberOfItems--) { IDiagramEntity entity = mGroup.Entities[0]; //this will be recursive if an entity is itself an IGroup entity.Group = null; mGroup.Entities.Remove(entity); Controller.Model.AddEntity(entity); entity.Invalidate(); removedItems.Add(entity); } //change the visuals such that the entities in the group are selected this.Controller.Model.Selection.SelectedItems = removedItems; //mGroup.Entities.Clear(); //mGroup.Invalidate(); mGroup = null; //note that the entities have never been disconnected from the layer //so they don't have to be re-attached to the anything. //The insertion of the Group simply got pushed in the scene-graph. }
/// <summary> /// Sends to entity to the bottom of the z-order stack. /// </summary> /// <param name="entity">The entity.</param> public void SendToBack(IDiagramEntity entity) { ILayer layer = CurrentPage.GetLayer(entity); if (layer != null) { layer.Entities.Remove(entity); layer.Entities.Insert(0, entity); ReAssignSceneIndex(layer.Entities); Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } //if(Paintables.Contains(entity)) //{ // Paintables.Remove(entity); // Paintables.Insert(0, entity); // ReAssignSceneIndex(); // Rectangle rec = entity.Rectangle; // rec.Inflate(20, 20); // this.RaiseOnInvalidateRectangle(Rectangle); //} }
public void SendToFront(IDiagramEntity entity) { if(mPaintables.Contains(entity)) { mPaintables.Remove(entity); mPaintables.Add(entity); Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } }
// ------------------------------------------------------------------ /// <summary> /// Abstract method to be implemented by all alignment tools. /// </summary> /// <param name="entities">IDiagramEntity[]: All selected /// entities.</param> // ------------------------------------------------------------------ public abstract void Align(IDiagramEntity[] entities);
public EntityMouseEventArgs(IDiagramEntity entity, MouseButtons button, int clicks, int x, int y, int delta) : base(button, clicks, x, y, delta) { this.mEntity = entity; }
protected override bool ShouldHighlightObject(IDiagramEntity obj) { return obj is ConnectionPoint && CanConnect(obj as ConnectionPoint); }
protected abstract bool ShouldHighlightObject(IDiagramEntity obj);
/// <summary> /// Sends the entity to the front of the z-order stack. /// </summary> /// <param name="entity">The entity.</param> public void SendToFront(IDiagramEntity entity) { ILayer layer = CurrentPage.GetLayer(entity); if (layer != null) { layer.Entities.Remove(entity); layer.Entities.Add(entity); ReAssignSceneIndex(layer.Entities); Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } //if(Paintables.Contains(entity)) //{ // Paintables.Remove(entity); // Paintables.Add(entity); // ReAssignSceneIndex(Paintables); // Rectangle rec = entity.Rectangle; // rec.Inflate(20, 20); // this.RaiseOnInvalidateRectangle(Rectangle); //} }
// ------------------------------------------------------------------ /// <summary> /// Gets the layer that has the entity specified. If the entity /// specified could not be found, 'null' is returned. /// </summary> /// <param name="entity">IDiagramEntity</param> /// <returns>ILayer</returns> // ------------------------------------------------------------------ public ILayer GetLayer(IDiagramEntity entity) { foreach (ILayer layer in mLayers) { if (layer.Entities.Contains(entity)) { return layer; } } return null; }
public void SendForwards(IDiagramEntity entity) { SendForwards(entity, 1); }
/// <summary> /// Sends to entity to the bottom of the z-order stack. /// </summary> /// <param name="entity">The entity.</param> public void SendToBack(IDiagramEntity entity) { if(mPaintables.Contains(entity)) { mPaintables.Remove(entity); mPaintables.Insert(0, entity); ReAssignSceneIndex(); Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } }
// ------------------------------------------------------------------ /// <summary> /// Adds an entity to the diagram. The magnification level for the /// entity is set to the current magnification level of the current /// page. /// </summary> /// <param name="entity">IDiagramEntity: The entity to add.</param> /// <returns>IDiagramEntity: The added entity.</returns> // ------------------------------------------------------------------ public IDiagramEntity AddEntity(IDiagramEntity entity) { SetModel(entity); //By default the new entity is added to the default layer in the // current page. CurrentPage.DefaultLayer.Entities.Add(entity); entity.Attached(CurrentPage.DefaultLayer); entity.Magnification = CurrentPage.Magnification; return entity; }
public static void CollectEntitiesAt(Point surfacePoint) { if (surfacePoint == Point.Empty) { return; } if (Selection.mController == null) { return; } //only change the current selection if the mouse did not hit an already selected element if (mSelection.Count > 0) { foreach (IDiagramEntity entity in mSelection) { if (entity.Rectangle.Contains(surfacePoint)) { return; } } } //here the scene-graph will play a role in the future, //for now we'll keep is simple Selection.Clear(); IConnection con; IShape sh; //we use the paintables here rather than traversing the scene-graph because only //visible things can be collected //We traverse the paintables from top to bottom since the highest z-order //is at the top of the stack. for (int k = Model.Paintables.Count - 1; k >= 0; k--) { IDiagramEntity entity = Model.Paintables[k]; #region we give priority to the connector selection if (typeof(IConnection).IsInstanceOfType(entity)) { con = entity as IConnection; if (con.From.Hit(surfacePoint)) { connector = con.From; connector.IsSelected = true; Invalidate(); return; } if (con.To.Hit(surfacePoint)) { connector = con.To; connector.IsSelected = true; Invalidate(); return; } } else if (typeof(IShape).IsInstanceOfType(entity)) { sh = entity as IShape; foreach (IConnector cn in sh.Connectors) { //if there are connectors attached to the shape connector, the attached ones should be picked up and not the one of the shape if (cn.Hit(surfacePoint) && cn.AttachedConnectors.Count == 0) { connector = cn; connector.IsSelected = true; Invalidate(); //this will invalidate only the selected connector return; //we hit a connector and quit the selection. If the user intended to select the entity it had to be away from the connector! } } } #endregion #region no connector was hit, maybe the entity itself if (entity.Hit(surfacePoint)) { //if the entity is part of an IGroup, the IGroup should be selected //rather than the entity itself //Note that the Group property returns the top group parent and not //just the immediate parent of an entity if (entity.Group != null) { entity.Group.IsSelected = true; mSelection.Add(entity.Group); } else { entity.IsSelected = true; mSelection.Add(entity); } break; } #endregion } RaiseOnNewSelection(); Invalidate(); //Using a full invalidate is rather expensive, so we'll only refresh the current selection //Controller.View.Invalidate(); }
// ------------------------------------------------------------------ /// <summary> /// Unwraps an entity /// <list type="bullet"> /// <term>Uid</term><description>Generates a new <see cref="IDiagramEntity.Uid"/> for the entity. </description> /// <tem>Model</tem><description>Assigns the Model property to the entity.</description> /// /// </list> /// </summary> // ------------------------------------------------------------------ public void Unwrap(IDiagramEntity entity) { //set a new unique identifier for this copied object entity.NewUid(true); //this assignment will be recursive if needed SetModel(entity); CurrentPage.DefaultLayer.Entities.Add(entity); entity.Attached(CurrentPage.DefaultLayer); }
protected override bool ShouldHighlightObject(IDiagramEntity obj) { return false; }
public void Remove(IDiagramEntity entity) { if (DefaultPage.DefaultLayer.Entities.Contains(entity)) { entity.OnRemove(); DefaultPage.DefaultLayer.Entities.Remove(entity); } }
public CancelableEntityEventArgs(IDiagramEntity entity) { this.Entity = entity; }
public void SendForwards(IDiagramEntity entity, int zShift) { if (mPaintables.Contains(entity) && zShift>=1) { int newpos = mPaintables.IndexOf(entity) + zShift; //if this is the last in the row you cannot move it higher if (newpos < mPaintables.Count) { mPaintables.Remove(entity); mPaintables.Insert(newpos, entity); //does it works when this is an addition at the top? Rectangle rec = entity.Rectangle; rec.Inflate(20, 20); this.RaiseOnInvalidateRectangle(Rectangle); } } }
// ------------------------------------------------------------------ /// <summary> /// Handles the mouse move event /// </summary> /// <param name="e">The <see cref= /// "T:System.Windows.Forms.MouseEventArgs"/> instance containing /// the event data.</param> // ------------------------------------------------------------------ public void MouseMove(MouseEventArgs e) { if (!IsSuspended && this.Enabled) { IHoverListener listener = null; CollectionBase <IDiagramEntity> paintables = this.Controller.Model.Paintables; IDiagramEntity entity; if (paintables.Count == 0) { return; } //going from top to the bottom of the z-order for (int k = paintables.Count - 1; k >= 0; k--) { entity = paintables[k]; if (entity.Hit(e.Location)) //we caught an entity { //unhover the previous, if any if (previousHovered != null) { previousHovered.Hovered = false; } //tell the current one it's being hovered entity.Hovered = true; //fetch the hovering service, if defined listener = entity.GetService( typeof(IHoverListener)) as IHoverListener; if (listener != null) //the caught entity does listen { if (currentListener == listener) //it's the same as the previous time { listener.MouseHover(e); } else //we moved from one entity to another listening entity { if (currentListener != null) //tell the previous entity we are leaving { currentListener.MouseLeave(e); } listener.MouseEnter(e); //tell the current one we enter currentListener = listener; } } else //the caught entity does not listen { if (currentListener != null) { currentListener.MouseLeave(e); currentListener = null; } } previousHovered = entity; //remember, for the next time return; //if another entity is listening underneath this entity it will not receive the notification } } if (currentListener != null) { currentListener.MouseLeave(e); currentListener = null; } //unhover the previous, if any if (previousHovered != null) { previousHovered.Hovered = false; } } }
public void SetModel(IDiagramEntity entity) { if(entity is IConnector) { (entity as IConnector).Model = this; } else if(entity is IConnection) { IConnection con = entity as IConnection; con.Model = this; Debug.Assert(con.From != null, "The 'From' connector is not set."); con.From.Model = this; Debug.Assert(con.From != null, "The 'To' connector is not set."); con.To.Model = this; } else if(entity is IShape) { IShape shape = entity as IShape; shape.Model = this; foreach(IConnector co in shape.Connectors) { co.Model = this; } } }