public UmlDiagramRelation AddRelationFromModel(UmlRelation umlRelation) { var startUmlDiagramClass = Classes.FirstOrDefault(c => c.Class == umlRelation.StartClass); var endUmlDiagramClass = Classes.FirstOrDefault(c => c.Class == umlRelation.EndClass); UmlDiagramRelation umlDiagramRelation = null; if (umlRelation is UmlDependenceRelation) { umlDiagramRelation = new UmlDiagramDependenceRelation(umlRelation, startUmlDiagramClass, endUmlDiagramClass); } else if (umlRelation is UmlAssociationRelation) { umlDiagramRelation = new UmlDiagramAssociationRelation(umlRelation, startUmlDiagramClass, endUmlDiagramClass); } else if (umlRelation is UmlImplementsInterfaceRelation) { umlDiagramRelation = new UmlDiagramImplementsInterfaceRelation(umlRelation, startUmlDiagramClass, endUmlDiagramClass); } else if (umlRelation is UmlInheritanceRelation) { umlDiagramRelation = new UmlDiagramInheritanceRelation(umlRelation, startUmlDiagramClass, endUmlDiagramClass); } else if (umlRelation is UmlCompositionRelation) { umlDiagramRelation = new UmlDiagramCompositionRelation(umlRelation, startUmlDiagramClass, endUmlDiagramClass); } else if (umlRelation is UmlAggregationRelation) { umlDiagramRelation = new UmlDiagramAggregationRelation(umlRelation, startUmlDiagramClass, endUmlDiagramClass); } if (umlDiagramRelation != null && startUmlDiagramClass != null && endUmlDiagramClass != null) { modelToDiagramRelations[umlRelation] = umlDiagramRelation; AddRelation(umlDiagramRelation); startUmlDiagramClass.AddRelation(umlDiagramRelation); endUmlDiagramClass.AddRelation(umlDiagramRelation); } UpdateBendingOffsets(endUmlDiagramClass, startUmlDiagramClass); return(umlDiagramRelation); }
/// <summary> /// Add a class that already exists in the Model to the diagram. /// </summary> private void AddClassFromModel(UmlClass umlClass) { var umlDiagramClass = new UmlDiagramClass(umlClass, this) { ShowsMembers = ShowsMembers }; CheckForTags(umlDiagramClass); Model.FillMethodsFromClass(umlClass); umlDiagramClass.SyncAttributesAndOperationsFromModel(); modelToDiagramClasses[umlClass] = umlDiagramClass; umlDiagramClass.Pos = new Point(rand.NextDouble() * 300, rand.NextDouble() * 300); AddClass(umlDiagramClass); // // Add any relation that should be visible in the diagram now. // // // Don't just add all umlClass.Relations, only the ones that are connected to an // already shown class. // foreach (var umlDiagramClass2 in Classes) { List <UmlRelation> umlRelations = Model.Relations.Where( r => r.StartClass == umlClass && r.EndClass == umlDiagramClass2.Class || r.StartClass == umlDiagramClass2.Class && r.EndClass == umlClass ).ToList(); foreach (var umlRelation in umlRelations) { UmlDiagramRelation umlDiagramRelation = GetDiagramRelation(umlRelation); if (umlDiagramRelation == null) { AddRelationFromModel(umlRelation); } } } NotifyPropertyChanged(() => ClassNames); }
public void RemoveDiagramRelation(UmlDiagramRelation umlDiagramRelation) { RemoveRelation(umlDiagramRelation); modelToDiagramRelations.Remove(umlDiagramRelation.Relation); }