public static ShapeElement AddExistingModelElement(EFModelDiagram diagram, ModelElement element) { if (diagram?.NestedChildShapes?.Any(s => s.ModelElement == element) != false) { return(null); } using (Transaction t = element.Store.TransactionManager.BeginTransaction("add existing model elements")) { diagram.ForceAddShape = true; FixUpAllDiagrams.FixUp(diagram, element); diagram.ForceAddShape = false; // find all element links that are attached to our element where the ends are in the diagram but the link isn't already in the diagram List <ElementLink> elementLinks = element.Store.GetAll <ElementLink>() .Where(link => link.LinkedElements.Contains(element) && link.LinkedElements.All(linkedElement => diagram.DisplayedElements.Contains(linkedElement)) && !diagram.DisplayedElements.Contains(link)) .ToList(); foreach (ElementLink elementLink in elementLinks) { FixUpAllDiagrams.FixUp(diagram, elementLink); } t.Commit(); return(diagram.NestedChildShapes.FirstOrDefault(s => s.ModelElement == element)); } }
protected override void OnSelectionChanged(EventArgs e) { base.OnSelectionChanged(e); // select element in tree if (PrimarySelection != null && PrimarySelection is ModelElement element) { using (Transaction t = element.Store.TransactionManager.BeginTransaction("TreeSelectionChanged")) { Diagram diagram = element.GetActiveDiagramView()?.Diagram; switch (PrimarySelection) { case ModelDiagramData modelDiagramData: // user selected a diagram. Open it. EFModelDocData docData = (EFModelDocData)TreeContainer.ModelingDocData; docData.OpenView(Constants.LogicalView, new Mexedge.VisualStudio.Modeling.ViewContext(modelDiagramData.Name, typeof(EFModelDiagram), docData.RootElement)); break; case ModelClass modelClass: // user selected a class. If it's in the current diagram, find it, center it and make it visible ShapeElement primaryShapeElement = PresentationViewsSubject.GetPresentation(modelClass) .OfType <ShapeElement>() .FirstOrDefault(s => s.Diagram == diagram); //if (primaryShapeElement == null || !primaryShapeElement.IsVisible) // break; modelClass.LocateInDiagram(true); // then fix up the compartments since they might need it ModelElement[] classElements = { modelClass }; CompartmentItemAddRule.UpdateCompartments(classElements, typeof(ClassShape), "AttributesCompartment", false); CompartmentItemAddRule.UpdateCompartments(classElements, typeof(ClassShape), "AssociationsCompartment", false); CompartmentItemAddRule.UpdateCompartments(classElements, typeof(ClassShape), "SourcesCompartment", false); // any associations to visible classes on this diagram need to be visible as well foreach (NavigationProperty navigationProperty in modelClass.LocalNavigationProperties()) { ModelClass other = navigationProperty.AssociationObject.Source == modelClass ? navigationProperty.AssociationObject.Target : navigationProperty.AssociationObject.Source; // should never happen if (other == null) { continue; } ShapeElement shapeElement = PresentationViewsSubject.GetPresentation(other) .OfType <ShapeElement>() .FirstOrDefault(s => s.Diagram == diagram); if (shapeElement != null && shapeElement.IsVisible) { ShapeElement connectorElement = PresentationViewsSubject.GetPresentation(navigationProperty.AssociationObject) .OfType <AssociationConnector>() .FirstOrDefault(s => s.Diagram == diagram); connectorElement?.Show(); } } // so do generalizations, as long as both classes are available foreach (Generalization generalization in modelClass.Store.ElementDirectory.AllElements.OfType <Generalization>().Where(g => g.Superclass == modelClass || g.Subclass == modelClass)) { ModelClass other = generalization.Superclass == modelClass ? generalization.Subclass : generalization.Superclass; // should never happen if (other == null) { continue; } ShapeElement shapeElement = PresentationViewsSubject.GetPresentation(other) .OfType <ShapeElement>() .FirstOrDefault(s => s.Diagram == diagram); if (shapeElement != null && shapeElement.IsVisible) { ShapeElement connectorElement = PresentationViewsSubject.GetPresentation(generalization) .OfType <GeneralizationConnector>() .FirstOrDefault(s => s.Diagram == diagram); connectorElement?.Show(); } } FixUpAllDiagrams.FixUp(diagram, modelClass.ModelRoot, modelClass); break; case ModelEnum modelEnum: // user selected an enum. Find it in the current diagram, center it and make it visible modelEnum.LocateInDiagram(true); // then fix up the compartment since it might need it ModelElement[] enumElements = { modelEnum }; CompartmentItemAddRule.UpdateCompartments(enumElements, typeof(EnumShape), "ValuesCompartment", false); FixUpAllDiagrams.FixUp(diagram, modelEnum.ModelRoot, modelEnum); break; } t.Commit(); } } }
internal static void FixUp(global::Sawczyn.EFDesigner.EFModel.EFModelDiagram diagram) { // 300010 Guid[] l_300010_domainClassesIds = { }; using (Transaction transaction = diagram.Store.TransactionManager.BeginTransaction("FixUp:AddShapeRulePriority:Core")) { foreach (Guid domainClassId in l_300010_domainClassesIds) { ReadOnlyCollection <ModelElement> modelElements = diagram.Store.ElementDirectory.FindElements(domainClassId); foreach (ModelElement modelElement in modelElements.Where(diagram.ShouldSupport)) { FixUpAllDiagrams.FixUp(diagram, modelElement); } } transaction.Commit(); } // 300020 Guid[] l_300020_domainClassesIds = { global::Sawczyn.EFDesigner.EFModel.Comment.DomainClassId, global::Sawczyn.EFDesigner.EFModel.ModelEnum.DomainClassId, global::Sawczyn.EFDesigner.EFModel.ModelClass.DomainClassId, }; using (Transaction transaction = diagram.Store.TransactionManager.BeginTransaction("FixUp:AddShapeRulePriority:Core")) { foreach (Guid domainClassId in l_300020_domainClassesIds) { ReadOnlyCollection <ModelElement> modelElements = diagram.Store.ElementDirectory.FindElements(domainClassId); foreach (ModelElement modelElement in modelElements.Where(diagram.ShouldSupport)) { FixUpAllDiagrams.FixUp(diagram, modelElement); } } transaction.Commit(); } // 300021 Guid[] l_300021_domainClassesIds = { }; using (Transaction transaction = diagram.Store.TransactionManager.BeginTransaction("FixUp:AddShapeRulePriority:Core")) { foreach (Guid domainClassId in l_300021_domainClassesIds) { ReadOnlyCollection <ModelElement> modelElements = diagram.Store.ElementDirectory.FindElements(domainClassId); foreach (ModelElement modelElement in modelElements.Where(diagram.ShouldSupport)) { FixUpAllDiagrams.FixUp(diagram, modelElement); } } transaction.Commit(); } // 300100 Guid[] l_300100_domainClassesIds = { global::Sawczyn.EFDesigner.EFModel.CommentReferencesSubjects.DomainClassId, global::Sawczyn.EFDesigner.EFModel.UnidirectionalAssociation.DomainClassId, global::Sawczyn.EFDesigner.EFModel.Generalization.DomainClassId, global::Sawczyn.EFDesigner.EFModel.BidirectionalAssociation.DomainClassId, }; using (Transaction transaction = diagram.Store.TransactionManager.BeginTransaction("FixUp:AddConnectionRulePriority:AutoLayout")) { diagram.AutoLayoutShapeElements(diagram.NestedChildShapes, Microsoft.VisualStudio.Modeling.Diagrams.GraphObject.VGRoutingStyle.VGRouteTreeNS, Microsoft.VisualStudio.Modeling.Diagrams.GraphObject.PlacementValueStyle.VGPlaceSN, true); transaction.Commit(); } using (Transaction transaction = diagram.Store.TransactionManager.BeginTransaction("FixUp:AddConnectionRulePriority:Core")) { foreach (Guid domainClassId in l_300100_domainClassesIds) { ReadOnlyCollection <ModelElement> modelElements = diagram.Store.ElementDirectory.FindElements(domainClassId); foreach (ModelElement modelElement in modelElements.Where(diagram.ShouldSupport)) { FixUpAllDiagrams.FixUp(diagram, modelElement); } } transaction.Commit(); } diagram.OnSynchronized(); }
private void AddElementsToActiveDiagram(List <ModelElement> newElements) { // TODO: Needs sped up int elementCount = newElements.Count; List <ShapeElement> newShapes = new List <ShapeElement>(); using (Transaction t = Store.TransactionManager.BeginTransaction("adding diagram elements")) { for (int index = 0; index < elementCount; index++) { ModelElement newElement = newElements[index]; StatusDisplay.Show($"Adding element {index + 1} of {elementCount}"); ForceAddShape = true; FixUpAllDiagrams.FixUp(this, newElement); newShapes.Add(newElement.GetFirstShapeElement()); ForceAddShape = false; } t.Commit(); } using (Transaction t = Store.TransactionManager.BeginTransaction("adding diagram links")) { for (int index = 0; index < elementCount; index++) { ModelElement newElement = newElements[index]; StatusDisplay.Show($"Linking {index + 1} of {elementCount}"); // find all element links that are attached to our element where the ends are in the diagram but the link isn't already in the diagram List <ElementLink> elementLinks = Store.GetAll <ElementLink>() .Where(link => link.LinkedElements.Contains(newElement) && link.LinkedElements.All(linkedElement => DisplayedElements.Contains(linkedElement)) && !DisplayedElements.Contains(link)) .ToList(); foreach (ElementLink elementLink in elementLinks) { BinaryLinkShape linkShape = CreateChildShape(elementLink) as BinaryLinkShape; newShapes.Add(linkShape); NestedChildShapes.Add(linkShape); switch (elementLink) { case Association a: linkShape.FromShape = a.Source.GetFirstShapeElement() as NodeShape; linkShape.ToShape = a.Target.GetFirstShapeElement() as NodeShape; break; case Generalization g: linkShape.FromShape = g.Subclass.GetFirstShapeElement() as NodeShape; linkShape.ToShape = g.Superclass.GetFirstShapeElement() as NodeShape; break; } } } AutoLayoutShapeElements(newShapes); t.Commit(); } }