public override void ElementAdded(ElementAddedEventArgs e) { ShapeElementContainsChildShapes con = e.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); childShape.UpdateAbsoluteLocation(); if (childShape.Location == PointD.Empty) { childShape.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); } } } }
public override void RolePlayerChanged(RolePlayerChangedEventArgs e) { ShapeElementContainsChildShapes con = e.ElementLink as ShapeElementContainsChildShapes; if (con == null) { return; } if (e.DomainRole.Id == ShapeElementContainsChildShapes.DomainClassId) { NodeShape childShape = con.ChildShape; NodeShape parentShapeOld = e.OldRolePlayer as NodeShape; NodeShape parentShapeNew = e.NewRolePlayer as NodeShape; // delete from old parent shape if (childShape != null && parentShapeOld != null) { if (childShape.IsDeleted) { return; } parentShapeOld.RemoveFromShapeMapping(childShape); } // add to new parent shape if (childShape != null && parentShapeNew != null) { if (childShape.IsDeleted) { return; } parentShapeNew.AddToShapeMapping(childShape); if (childShape.IsRelativeChildShape && childShape.MovementBehaviour == ShapeMovementBehaviour.PositionOnEdgeOfParent) { childShape.CorrectLocation(); } if (!childShape.IsRelativeChildShape) { childShape.ResizeParentIfRequired(); } } } }