/// 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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <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));
            }
        }