///-------------------------------------------------------------------------------- /// <summary>This method creates an entity and adds to the view model.</summary> /// /// <param name="entity">The entity to add.</param> /// <param name="position">The desired position to place the entity.</param> ///-------------------------------------------------------------------------------- public DiagramEntityViewModel CreateEntity(EntityViewModel entity, Point position) { // create diagram entity and add to solution diagram DiagramEntity dropDiagram = new DiagramEntity(); dropDiagram.DiagramEntityID = Guid.NewGuid(); DiagramEntityViewModel diagramEntity = new DiagramEntityViewModel(dropDiagram, entity, this); diagramEntity.X = Math.Max(0, position.X); diagramEntity.Y = Math.Max(0, position.Y); diagramEntity.Width = Double.NaN; diagramEntity.Height = Double.NaN; DiagramEntities.Add(diagramEntity); Items.Add(diagramEntity); ClearSelectedItems(); diagramEntity.IsSelected = true; diagramEntity.ZIndex = ++ZIndex; // add to diagram entites to add list ItemsToAdd.Add(diagramEntity); Refresh(false); return(diagramEntity); }
///-------------------------------------------------------------------------------- /// <summary>This method adds an entity to the view model.</summary> /// /// <param name="entity">The entity to add.</param> /// <param name="position">The desired position to place the entity.</param> ///-------------------------------------------------------------------------------- public DiagramEntityViewModel AddEntity(EntityViewModel entity, Point position, bool isNewEntity = false) { DiagramEntity dropDiagram = new DiagramEntity(); dropDiagram.DiagramID = DiagramID; dropDiagram.DiagramEntityID = Guid.NewGuid(); EntityViewModel entityView = entity; DiagramEntityViewModel diagramEntity = new DiagramEntityViewModel(dropDiagram, entityView, this); diagramEntity.X = Math.Max(0, position.X); diagramEntity.Y = Math.Max(0, position.Y); diagramEntity.Width = Double.NaN; diagramEntity.Height = Double.NaN; diagramEntity.Updated += new EventHandler(Children_Updated); diagramEntity.DiagramEntity.Entity = diagramEntity.EntityViewModel.Entity; diagramEntity.ResetModified(false); diagramEntity.EditDiagramEntity.ResetModified(false); if (isNewEntity == true) { AddDiagramEntity(diagramEntity); } else { DiagramEntities.Add(diagramEntity); Items.Add(diagramEntity); } ClearSelectedItems(); diagramEntity.IsSelected = true; diagramEntity.ZIndex = ++ZIndex; Entities.Remove(entity); EntitiesRemoved.Add(entity); diagramEntity.PositionChanged += new EventHandler(diagramEntity_PositionChanged); AddRelationships(diagramEntity); return(diagramEntity); }