/// <summary> /// Called whenever a child element is added to a diagram. /// </summary> /// <param name="e"></param> public override void ElementAdded(ElementAddedEventArgs e) { base.ElementAdded(e); DiagramHasChildren con = e.ModelElement as DiagramHasChildren; if (con != null) { NodeShape nodeShape = con.ChildShape; Diagram diagram = con.Diagram; if (nodeShape != null && diagram != null) { if (nodeShape.IsDeleted) { return; } diagram.AddToShapeMapping(nodeShape); if (nodeShape.Location == PointD.Empty) { nodeShape.SetAtFreePositionOnParent(); } } else { con.Delete(); } } }
/// <summary> /// Called whenever a model element is added to the store. /// </summary> /// <param name="sender">ViewModelStore</param> /// <param name="args">Event Arguments for notification of the creation of new model element.</param> private void OnElementAdded(object sender, ElementAddedEventArgs args) { if (!ModelData.DoSendModelEvents) { return; } // update shape mapping (this is required, becauso undo/redo does not trigger events) if (args.ModelElement is DiagramHasChildren) { DiagramHasChildren con = args.ModelElement as DiagramHasChildren; if (con != null) { NodeShape nodeShape = con.ChildShape; Diagram diagram = con.Diagram; if (nodeShape != null && diagram != null) { if (nodeShape.IsDeleted) { return; } diagram.AddToShapeMapping(nodeShape); } } } else if (args.ModelElement is ShapeElementContainsChildShapes) { ShapeElementContainsChildShapes con = args.ModelElement as ShapeElementContainsChildShapes; if (con != null) { NodeShape childShape = con.ChildShape; NodeShape parentShape = con.ParentShape; if (childShape != null && parentShape != null) { if (childShape.IsDeleted) { return; } if (parentShape.IsDeleted) { return; } parentShape.AddToShapeMapping(childShape); } } } }
/// <summary> /// Called whenever a child element is deleted. /// </summary> /// <param name="e"></param> public override void ElementDeleted(ElementDeletedEventArgs e) { base.ElementDeleted(e); DiagramHasChildren con = e.ModelElement as DiagramHasChildren; if (con != null) { NodeShape nodeShape = con.ChildShape; Diagram diagram = con.Diagram; if (nodeShape != null && diagram != null) { diagram.RemoveFromShapeMapping(nodeShape); } } }
public override void OnChildShapeElementAdded(DiagramHasChildren con, DiagramSurfaceViewModel diagVm) { if (IsDisplayingNodeShape(con.ChildShape)) { return; } if (con.ChildShape is GraphicalDependencyShape) { GraphicalDependencyHostViewModel vm = new GraphicalDependencyHostViewModel( this.ViewModelStore, this, con.ChildShape as GraphicalDependencyShape); diagVm.AddElement(vm); } else if (con.ChildShape is GraphicalDependencyMainShape) { GraphicalDependencyMainItemViewModel vm = new GraphicalDependencyMainItemViewModel( this.ViewModelStore, this, con.ChildShape as GraphicalDependencyMainShape); diagVm.AddElement(vm); } else { DomainClassInfo info = con.ChildShape.GetDomainClass(); if (info.Id != NodeShape.DomainClassId) { DiagramItemElementViewModel elementVM = this.ViewModelStore.Factory.CreateDiagramItemViewModel( info.Id, this, con.ChildShape); if (elementVM != null) { diagVm.AddElement(elementVM); return; } } GraphicalDependencyItemViewModel vm = new GraphicalDependencyItemViewModel( this.ViewModelStore, this, con.ChildShape); diagVm.AddElement(vm); } }
/// <summary> /// Called whenever a model element is deleted from the store. /// </summary> /// <param name="sender">ViewModelStore</param> /// <param name="args">Event Arguments for notification of the removal of an ModelElement.</param> private void OnElementDeleted(object sender, ElementDeletedEventArgs args) { if (args.ModelElement is DiagramHasChildren) { DiagramHasChildren con = args.ModelElement as DiagramHasChildren; if (con != null) { NodeShape nodeShape = con.ChildShape; Diagram diagram = con.Diagram; if (nodeShape != null && diagram != null) { if (nodeShape.Element != null) { diagram.RemoveFromShapeMapping(nodeShape); } } } } else if (args.ModelElement is ShapeElementContainsChildShapes) { ShapeElementContainsChildShapes con = args.ModelElement as ShapeElementContainsChildShapes; if (con != null) { NodeShape childShape = con.ChildShape; NodeShape parentShape = con.ParentShape; if (childShape != null && parentShape != null) { if (childShape.Element != null) { parentShape.RemoveFromShapeMapping(childShape); } } } } }