Exemplo n.º 1
0
        private static void TranslateDiagramObjectHelper(
            EntityDesignerViewModel viewModel, ModelDiagram.BaseDiagramObject modelDiagramEFObject,
            EFObject modelObjectToFindViewModel, bool updateShapeElements, UpdateShapeInfoCallback updateShapeInfoCallback)
        {
            var      diagram         = viewModel.GetDiagram();
            EFObject diagramEFObject = modelDiagramEFObject;

            Debug.Assert(diagram != null, "Where is the DSL diagram?");
            Debug.Assert(diagramEFObject != null, "Where is the EFObject corresponding to the diagram?");

            if (diagram != null &&
                diagramEFObject != null)
            {
                var shapeElement = viewModel.ModelXRef.GetExisting(diagramEFObject) as ViewModelDiagram.ShapeElement;
                if (shapeElement == null)
                {
                    // find the view model associated with the model EFObject
                    var viewModelElement = viewModel.ModelXRef.GetExisting(modelObjectToFindViewModel);
                    Debug.Assert(viewModelElement != null, "Where is the view model for the model object?");

                    if (viewModelElement != null)
                    {
                        // get the shape element fromm the view model
                        shapeElement = diagram.FindShape(viewModelElement);
                        Debug.Assert(shapeElement != null, "Where is the DSL ShapeElement for the view model?");

                        if (shapeElement != null)
                        {
                            // associate the designer model EFObject with the shape element
                            if ((viewModel.ModelXRef.GetExisting(diagramEFObject) == null) &&
                                (viewModel.ModelXRef.GetExisting(shapeElement) == null))
                            {
                                viewModel.ModelXRef.Add(diagramEFObject, shapeElement, viewModel.EditingContext);
                            }
                        }
                    }
                }

                // update the shape information for the element
                if (updateShapeElements && shapeElement != null)
                {
                    updateShapeInfoCallback(shapeElement);
                }
            }
        }
Exemplo n.º 2
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));
                }
            }
        }
        private static string GetDiagramMoniker(BaseDiagramObject diagramObject)
        {
            var diagramName = (diagramObject.Diagram != null ? diagramObject.Diagram.Name : String.Empty);
            if (diagramObject is InheritanceConnector)
            {
                var entityType = diagramObject.ModelItem as ConceptualEntityType;

                Debug.Assert(entityType != null, "Inheritance connector should point to an instance of conceptual entity type.");
                if (entityType != null)
                {
                    Debug.Assert(entityType.SafeBaseType != null, "This entity type should be a derived type.");

                    if (entityType.SafeBaseType != null)
                    {
                        return diagramName + " : " + entityType.SafeBaseType.ToPrettyString() + " : " + entityType.ToPrettyString();
                    }
                }
                return string.Empty;
            }
            else if (diagramObject.ModelItem == null)
            {
                return diagramName + " : " + diagramObject.ToPrettyString();
            }
            else
            {
                return diagramName + " : " + diagramObject.ModelItem.ToPrettyString();
            }
        }