src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/CustomSerializer/EntityModelToDslModelTranslatorStrategy.cs
/// <summary>
///     Apply layout information from modelDiagram to DSL Diagram.
///     We loop through all shape element in DSL Diagram, get its model diagram element and apply the layout information.
///     Note that we don't assert if we didn't find the corresponding model diagram element.
///     In this case, we let DSL to auto layout the shape.
/// </summary>
Apply layout information from modelDiagram to DSL Diagram.
We loop through all shape element in DSL Diagram, get its model diagram element and apply the layout information.
Note that we don't assert if we didn't find the corresponding model diagram element.
In this case, we let DSL to auto layout the shape.
Apply layout information from modelDiagram to DSL Diagram . We loop through all shape element in DSL Diagram get its model diagram element and apply the layout information . Note that we don ' t assert if we didn ' t find the corresponding model diagram element . In this case we let DSL to auto layout the shape .
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        internal static void TranslateDiagram(EntityDesignerDiagram diagram, DesignerModel.Diagram modelDiagram)
        {
            var viewModel = diagram.ModelElement;
            viewModel.ModelXRef.Add(modelDiagram, diagram, viewModel.EditingContext);
            using (var t = diagram.Store.TransactionManager.BeginTransaction("Translate diagram", true))
            {
                var shapesToAutoLayout = new List<ViewModelDiagram.ShapeElement>();
                foreach (var shapeElement in diagram.NestedChildShapes)
                {
                    var entityShape = shapeElement as EntityTypeShape;
                    if (entityShape != null
                        && entityShape.ModelElement != null)
                    {
                        var modelEntity = viewModel.ModelXRef.GetExisting(entityShape.ModelElement) as ModelEntityType;
                        if (modelEntity != null)
                        {
                            var modelEntityTypeShape =
                                modelDiagram.EntityTypeShapes.FirstOrDefault(ets => ets.EntityType.Target == modelEntity);
                            if (modelEntityTypeShape != null)
                            {
                                viewModel.ModelXRef.Add(modelEntityTypeShape, entityShape, viewModel.EditingContext);
                                var rectangle = new ViewModelDiagram.RectangleD(
                                    modelEntityTypeShape.PointX.Value, modelEntityTypeShape.PointY.Value
                                    , modelEntityTypeShape.Width.Value, 0.0);
                                entityShape.AbsoluteBounds = rectangle;
                                entityShape.IsExpanded = modelEntityTypeShape.IsExpanded.Value;
                                entityShape.FillColor = modelEntityTypeShape.FillColor.Value;
                            }
                        }
                        if (viewModel.ModelXRef.GetExisting(entityShape) == null)
                        {
                            shapesToAutoLayout.Add(entityShape);
                        }
                        continue;
                    }
                    var associationConnector = shapeElement as AssociationConnector;
                    if (associationConnector != null
                        && associationConnector.ModelElement != null)
                    {
                        var modelAssociation = viewModel.ModelXRef.GetExisting(associationConnector.ModelElement) as ModelAssociation;
                        if (modelAssociation != null)
                        {
                            var modelAssociationConnector =
                                modelDiagram.AssociationConnectors.FirstOrDefault(ac => ac.Association.Target == modelAssociation);
                            if (modelAssociationConnector != null)
                            {
                                viewModel.ModelXRef.Add(modelAssociationConnector, associationConnector, viewModel.EditingContext);
                                TranslateAssociationConnectors(associationConnector, modelAssociationConnector, shapesToAutoLayout);
                            }
                        }
                        continue;
                    }
                    var inheritanceConnector = shapeElement as InheritanceConnector;
                    if (inheritanceConnector != null
                        && inheritanceConnector.ModelElement != null)
                    {
                        var entityTypeBase = viewModel.ModelXRef.GetExisting(inheritanceConnector.ModelElement) as EntityTypeBaseType;
                        var modelEntity = entityTypeBase.Parent as ModelEntityType;
                        if (modelEntity != null)
                        {
                            var modelInheritanceConnector =
                                modelDiagram.InheritanceConnectors.FirstOrDefault(ic => ic.EntityType.Target == modelEntity);
                            if (modelInheritanceConnector != null)
                            {
                                viewModel.ModelXRef.Add(modelInheritanceConnector, inheritanceConnector, viewModel.EditingContext);
                                TranslateInheritanceConnectors(inheritanceConnector, modelInheritanceConnector, shapesToAutoLayout);
                            }
                        }
                        continue;
                    }
                }
                diagram.AutoLayoutDiagram(shapesToAutoLayout);
                diagram.ZoomLevel = modelDiagram.ZoomLevel.Value;
                diagram.ShowGrid = modelDiagram.ShowGrid.Value;
                diagram.SnapToGrid = modelDiagram.SnapToGrid.Value;
                diagram.DisplayNameAndType = modelDiagram.DisplayType.Value;
                diagram.DiagramId = modelDiagram.Id.Value;
                diagram.Title = modelDiagram.Name.Value;
                t.Commit();
            }
        }
[ SuppressMessage ( " " , " " ) ] internal static void TranslateDiagram ( EntityDesignerDiagram diagram , DesignerModel . Diagram modelDiagram ) { var viewModel = diagram . ModelElement ; viewModel . ModelXRef . Add ( modelDiagram , diagram , viewModel . EditingContext ) ; using ( var t = diagram . Store . TransactionManager . BeginTransaction ( " " , true ) ) { var shapesToAutoLayout = new List < ViewModelDiagram . ShapeElement > ( ) ; foreach ( var shapeElement in diagram . NestedChildShapes ) { var entityShape = shapeElement as EntityTypeShape ; if ( entityShape != null && entityShape . ModelElement != null ) { var modelEntity = viewModel . ModelXRef . GetExisting ( entityShape . ModelElement ) as ModelEntityType ; if ( modelEntity != null ) { var modelEntityTypeShape = modelDiagram . EntityTypeShapes . FirstOrDefault ( ets => ets . EntityType . Target == modelEntity ) ; if ( modelEntityTypeShape != null ) { viewModel . ModelXRef . Add ( modelEntityTypeShape , entityShape , viewModel . EditingContext ) ; var rectangle = new ViewModelDiagram . RectangleD ( modelEntityTypeShape . PointX . Value , modelEntityTypeShape . PointY . Value , modelEntityTypeShape . Width . Value , 0.0 ) ; entityShape . AbsoluteBounds = rectangle ; entityShape . IsExpanded = modelEntityTypeShape . IsExpanded . Value ; entityShape . FillColor = modelEntityTypeShape . FillColor . Value ; } } if ( viewModel . ModelXRef . GetExisting ( entityShape ) == null ) { shapesToAutoLayout . Add ( entityShape ) ; } continue ; } var associationConnector = shapeElement as AssociationConnector ; if ( associationConnector != null && associationConnector . ModelElement != null ) { var modelAssociation = viewModel . ModelXRef . GetExisting ( associationConnector . ModelElement ) as ModelAssociation ; if ( modelAssociation != null ) { var modelAssociationConnector = modelDiagram . AssociationConnectors . FirstOrDefault ( ac => ac . Association . Target == modelAssociation ) ; if ( modelAssociationConnector != null ) { viewModel . ModelXRef . Add ( modelAssociationConnector , associationConnector , viewModel . EditingContext ) ; TranslateAssociationConnectors ( associationConnector , modelAssociationConnector , shapesToAutoLayout ) ; } } continue ; } var inheritanceConnector = shapeElement as InheritanceConnector ; if ( inheritanceConnector != null && inheritanceConnector . ModelElement != null ) { var entityTypeBase = viewModel . ModelXRef . GetExisting ( inheritanceConnector . ModelElement ) as EntityTypeBaseType ; var modelEntity = entityTypeBase . Parent as ModelEntityType ; if ( modelEntity != null ) { var modelInheritanceConnector = modelDiagram . InheritanceConnectors . FirstOrDefault ( ic => ic . EntityType . Target == modelEntity ) ; if ( modelInheritanceConnector != null ) { viewModel . ModelXRef . Add ( modelInheritanceConnector , inheritanceConnector , viewModel . EditingContext ) ; TranslateInheritanceConnectors ( inheritanceConnector , modelInheritanceConnector , shapesToAutoLayout ) ; } } continue ; } } diagram . AutoLayoutDiagram ( shapesToAutoLayout ) ; diagram . ZoomLevel = modelDiagram . ZoomLevel . Value ; diagram . ShowGrid = modelDiagram . ShowGrid . Value ; diagram . SnapToGrid = modelDiagram . SnapToGrid . Value ; diagram . DisplayNameAndType = modelDiagram . DisplayType . Value ; diagram . DiagramId = modelDiagram . Id . Value ; diagram . Title = modelDiagram . Name . Value ; t . Commit ( ) ; } }
Apply layout information from modelDiagram to DSL Diagram.
Apply layout information from modelDiagram to DSL Diagram .
// list of shapes that don't have corresponding element in model and require auto-layout // try to find object in model for each shape on a diagram // initiate zoom level, grid and scalar property options
diagram
EntityDesignerDiagram
modelDiagram
DesignerModel.Diagram