Exemple #1
0
        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))
            {
                // list of shapes that don't have corresponding element in model and require auto-layout
                var shapesToAutoLayout = new List <ViewModelDiagram.ShapeElement>();

                // try to find object in model for each shape on a diagram
                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);

                // initiate zoom level, grid and scalar property options
                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();
            }
        }
        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))
            {
                // list of shapes that don't have corresponding element in model and require auto-layout
                var shapesToAutoLayout = new List<ViewModelDiagram.ShapeElement>();

                // try to find object in model for each shape on a diagram
                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);

                // initiate zoom level, grid and scalar property options
                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();
            }
        }
Exemple #3
0
        internal static void TranslateDiagramObject(
            EntityDesignerViewModel viewModel, ModelDiagram.BaseDiagramObject modelDiagramObject,
            bool updateShapeElements, IList <ViewModelDiagram.ShapeElement> shapesToAutoLayout)
        {
            Debug.Assert(modelDiagramObject is EFObject, "Why did you define a DiagramEFObject that is not an EFObject?");

            var modelEntityTypeShape = modelDiagramObject as DesignerModel.EntityTypeShape;

            // the view model could have gotten deleted as a result of OnEFObjectDeleted() so don't attempt to translate the diagram EFObject.
            if (modelEntityTypeShape != null &&
                modelEntityTypeShape.IsDisposed != true &&
                modelEntityTypeShape.EntityType.Target != null &&
                modelEntityTypeShape.EntityType.Target.IsDisposed != true)
            {
                TranslateDiagramObjectHelper(
                    viewModel, modelDiagramObject, modelEntityTypeShape.EntityType.Target, updateShapeElements,
                    shapeElement =>
                {
                    var viewEntityTypeShape = shapeElement as EntityTypeShape;
                    var rectangle           = new ViewModelDiagram.RectangleD(
                        modelEntityTypeShape.PointX.Value
                        , modelEntityTypeShape.PointY.Value, modelEntityTypeShape.Width.Value, 0.0);
                    viewEntityTypeShape.AbsoluteBounds = rectangle;
                    viewEntityTypeShape.IsExpanded     = modelEntityTypeShape.IsExpanded.Value;
                    if (!shapesToAutoLayout.Contains(viewEntityTypeShape))
                    {
                        shapesToAutoLayout.Add(viewEntityTypeShape);
                    }

                    // Loop through all the shape's connectors and add the connector to list to be autolayout if the connector is not manually routed.
                    foreach (var linkShape in viewEntityTypeShape.Link)
                    {
                        if (linkShape.ManuallyRouted == false &&
                            shapesToAutoLayout.Contains(linkShape) == false)
                        {
                            shapesToAutoLayout.Add(linkShape);
                        }
                    }
                });

                var dslEntityTypeShape = viewModel.ModelXRef.GetExisting(modelEntityTypeShape) as EntityTypeShape;
                // dslEntityTypeShape is null if the entity-type is deleted, in that case skip sync FillColor property.
                if (dslEntityTypeShape != null)
                {
                    dslEntityTypeShape.FillColor = modelEntityTypeShape.FillColor.Value;
                }
            }
            // the view model could have gotten deleted as a result of OnEFObjectDeleted() so don't attempt to translate the diagram EFObject.
            var modelAssociationConnectorShape = modelDiagramObject as DesignerModel.AssociationConnector;

            if (modelAssociationConnectorShape != null &&
                modelAssociationConnectorShape.IsDisposed != true &&
                modelAssociationConnectorShape.Association.Target != null &&
                modelAssociationConnectorShape.Association.Target.IsDisposed != true)
            {
                TranslateDiagramObjectHelper(
                    viewModel, modelDiagramObject, modelAssociationConnectorShape.Association.Target, true,
                    shapeElement => TranslateAssociationConnectors(
                        shapeElement as AssociationConnector, modelAssociationConnectorShape, shapesToAutoLayout));
            }

            // the view model could have gotten deleted as a result of OnEFObjectDeleted() so don't attempt to translate the diagram EFObject.
            var modelInheritanceConnectorShape = modelDiagramObject as DesignerModel.InheritanceConnector;

            if (modelInheritanceConnectorShape != null &&
                modelInheritanceConnectorShape.IsDisposed != true &&
                modelInheritanceConnectorShape.EntityType.Target != null &&
                modelInheritanceConnectorShape.EntityType.Target.IsDisposed != true)
            {
                var cet = modelInheritanceConnectorShape.EntityType.Target as ConceptualEntityType;
                if (cet != null &&
                    cet.BaseType != null &&
                    cet.BaseType.RefName != null)
                {
                    TranslateDiagramObjectHelper(
                        viewModel, modelDiagramObject, cet.BaseType, true,
                        shapeElement => TranslateInheritanceConnectors(
                            shapeElement as InheritanceConnector, modelInheritanceConnectorShape, shapesToAutoLayout));
                }
            }
        }
        internal static void TranslateDiagramObject(
            EntityDesignerViewModel viewModel, ModelDiagram.BaseDiagramObject modelDiagramObject,
            bool updateShapeElements, IList<ViewModelDiagram.ShapeElement> shapesToAutoLayout)
        {
            Debug.Assert(modelDiagramObject is EFObject, "Why did you define a DiagramEFObject that is not an EFObject?");

            var modelEntityTypeShape = modelDiagramObject as DesignerModel.EntityTypeShape;

            // the view model could have gotten deleted as a result of OnEFObjectDeleted() so don't attempt to translate the diagram EFObject.
            if (modelEntityTypeShape != null
                && modelEntityTypeShape.IsDisposed != true
                && modelEntityTypeShape.EntityType.Target != null
                && modelEntityTypeShape.EntityType.Target.IsDisposed != true)
            {
                TranslateDiagramObjectHelper(
                    viewModel, modelDiagramObject, modelEntityTypeShape.EntityType.Target, updateShapeElements,
                    shapeElement =>
                        {
                            var viewEntityTypeShape = shapeElement as EntityTypeShape;
                            var rectangle = new ViewModelDiagram.RectangleD(
                                modelEntityTypeShape.PointX.Value
                                , modelEntityTypeShape.PointY.Value, modelEntityTypeShape.Width.Value, 0.0);
                            viewEntityTypeShape.AbsoluteBounds = rectangle;
                            viewEntityTypeShape.IsExpanded = modelEntityTypeShape.IsExpanded.Value;
                            if (!shapesToAutoLayout.Contains(viewEntityTypeShape))
                            {
                                shapesToAutoLayout.Add(viewEntityTypeShape);
                            }

                            // Loop through all the shape's connectors and add the connector to list to be autolayout if the connector is not manually routed.
                            foreach (var linkShape in viewEntityTypeShape.Link)
                            {
                                if (linkShape.ManuallyRouted == false
                                    && shapesToAutoLayout.Contains(linkShape) == false)
                                {
                                    shapesToAutoLayout.Add(linkShape);
                                }
                            }
                        });

                var dslEntityTypeShape = viewModel.ModelXRef.GetExisting(modelEntityTypeShape) as EntityTypeShape;
                // dslEntityTypeShape is null if the entity-type is deleted, in that case skip sync FillColor property.
                if (dslEntityTypeShape != null)
                {
                    dslEntityTypeShape.FillColor = modelEntityTypeShape.FillColor.Value;
                }
            }
            // the view model could have gotten deleted as a result of OnEFObjectDeleted() so don't attempt to translate the diagram EFObject.
            var modelAssociationConnectorShape = modelDiagramObject as DesignerModel.AssociationConnector;
            if (modelAssociationConnectorShape != null
                && modelAssociationConnectorShape.IsDisposed != true
                && modelAssociationConnectorShape.Association.Target != null
                && modelAssociationConnectorShape.Association.Target.IsDisposed != true)
            {
                TranslateDiagramObjectHelper(
                    viewModel, modelDiagramObject, modelAssociationConnectorShape.Association.Target, true,
                    shapeElement => TranslateAssociationConnectors(
                        shapeElement as AssociationConnector, modelAssociationConnectorShape, shapesToAutoLayout));
            }

            // the view model could have gotten deleted as a result of OnEFObjectDeleted() so don't attempt to translate the diagram EFObject.
            var modelInheritanceConnectorShape = modelDiagramObject as DesignerModel.InheritanceConnector;
            if (modelInheritanceConnectorShape != null
                && modelInheritanceConnectorShape.IsDisposed != true
                && modelInheritanceConnectorShape.EntityType.Target != null
                && modelInheritanceConnectorShape.EntityType.Target.IsDisposed != true)
            {
                var cet = modelInheritanceConnectorShape.EntityType.Target as ConceptualEntityType;
                if (cet != null
                    && cet.BaseType != null
                    && cet.BaseType.RefName != null)
                {
                    TranslateDiagramObjectHelper(
                        viewModel, modelDiagramObject, cet.BaseType, true,
                        shapeElement => TranslateInheritanceConnectors(
                            shapeElement as InheritanceConnector, modelInheritanceConnectorShape, shapesToAutoLayout));
                }
            }
        }