/// Ensures that DSL Diagram and Entity Diagram are in sync. /// This method also update the xref link between DSL Diagram and Model Diagram. private void ApplyLayoutInformationFromModelDiagram() { var artifact = Context.GetEFArtifactService().Artifact as EntityDesignArtifact; Debug.Assert(artifact != null, "Could not get the instance of EntityDesignArtifact from EditingContext."); if (artifact != null && artifact.IsDesignerSafe) { DesignerModel.Diagram modelDiagram = null; if (artifact.DesignerInfo != null && artifact.DesignerInfo.Diagrams != null) { modelDiagram = String.IsNullOrEmpty(_diagramId) ? artifact.DesignerInfo.Diagrams.FirstDiagram : artifact.DesignerInfo.Diagrams.GetDiagram(_diagramId); } // At this point DSL diagram should have been set. var diagram = Diagram as EntityDesignerDiagram; Debug.Assert(diagram != null, "Why does the DSL diagram is null?"); if (modelDiagram != null && diagram != null) { EntityModelToDslModelTranslatorStrategy.TranslateDiagram(diagram, modelDiagram); if (CurrentDesigner != null) { CurrentDesigner.ZoomAtViewCenter((float)modelDiagram.ZoomLevel.Value / 100); } } } }
/// <summary> /// This method reads the .diagram file and makes sure that shapes exist for every item /// in the .diagram file. /// </summary> internal static void ReloadDiagram(EntityDesignerViewModel viewModel) { var diagram = viewModel.GetDiagram(); if (diagram == null) { // Empty DSL diagram return; } diagram.ResetWatermark(diagram.ActiveDiagramView); // get our artifact var artifact = EditingContextManager.GetArtifact(viewModel.EditingContext); Debug.Assert(artifact != null); if (!artifact.IsDesignerSafe) { return; } var diagramModel = viewModel.ModelXRef.GetExisting(diagram) as DesignerModel.Diagram; if (diagramModel != null) { // ensure that we still have all of the parts we need to re-translate from the Model EntityModelToDslModelTranslatorStrategy.TranslateDiagram(diagram, diagramModel); } else { // this path will usually only happen if an UMFDB extension has deleted the diagram node // since we don't have a diagram anymore, lay it all out and create a new one if (diagram.ModelElement.EntityTypes.Count < EntityDesignerDiagram.IMPLICIT_AUTO_LAYOUT_CEILING) { diagram.AutoLayoutDiagram(); } EntityModelToDslModelTranslatorStrategy.CreateDefaultDiagram(viewModel.EditingContext, diagram); } // remove "Select All" selection if (diagram.ActiveDiagramView != null) { diagram.ActiveDiagramView.Selection.Set(new DiagramItem(diagram)); } }
public void EnsureDiagramIsCreated(EFArtifact artifact) { if (RootElement != null) { var modelRoot = RootElement as EntityDesignerViewModel; if (modelRoot != null) { var diagram = modelRoot.GetDiagram(); Debug.Assert(diagram != null, "DSL Diagram should have been created by now"); if (diagram != null) { Debug.Assert(artifact.DesignerInfo() != null, "artifact.DesignerInfo should not be null"); Debug.Assert(artifact.DesignerInfo().Diagrams != null, "artifact.DesignerInfo.Diagrams should not be null"); if (artifact.DesignerInfo() != null && artifact.DesignerInfo().Diagrams != null) { var saveDiagramDocument = false; if (artifact.DesignerInfo().Diagrams.FirstDiagram == null) { // layout is very slow. Only auto-layout if less than a max number of types if (diagram.ModelElement.EntityTypes.Count < EntityDesignerDiagram.IMPLICIT_AUTO_LAYOUT_CEILING) { diagram.AutoLayoutDiagram(); } try { EntityDesignerViewModel.RespondToModelChanges = false; EntityModelToDslModelTranslatorStrategy.CreateDefaultDiagram(modelRoot.EditingContext, diagram); // Ensure that DSL Diagram and Model Diagram are in sync: // - Update xref between 2 diagrams // - Propagetes model diagram info to DSL Diagram. var modelDiagram = artifact.DesignerInfo().Diagrams.FirstDiagram; Debug.Assert(modelDiagram != null, "modelDiagram should not be null"); if (modelDiagram != null) { ModelTranslatorContextItem.GetEntityModelTranslator(EditingContext) .SynchronizeSingleDslModelElement(modelRoot, modelDiagram); } } finally { EntityDesignerViewModel.RespondToModelChanges = true; } // save the file after adding Diagram element so it won't open as a dirty document saveDiagramDocument = true; } if (saveDiagramDocument) { var rdt = new RunningDocumentTable(ServiceProvider); rdt.SaveFileIfDirty(FileName); } _isDiagramLoaded = true; } } } } }