/// <override></override>
        public override Shape Clone()
        {
            Shape result = new RectangularLine(Type, (Template)null);

            result.CopyFrom(this);
            return(result);
        }
        internal static Shape CreateInstance(ShapeType shapeType, Template template)
        {
            Shape result = new RectangularLine(shapeType, template);

            return(result);
        }
        private LabelDirection GetLabelDirectionByRelationshipEntities(RectangularLine fk, IEnumerable<TableModel> tablesContainer)
        {
            List<EntitySymbol> ents = GetEntitiesByRelationship(fk);
            var TablesEntities = tablesContainer.Where(t => ents.Select(ta => ta.Tag).Contains(t.Name)).ToList();

            TableModel ManyEntity = TablesEntities.FirstOrDefault(k => k.MetaData.ForeignKeys.Any(l => l.IsParent && TablesEntities.Select(i => i.Name).Contains(l.Reference.TableName)));
            TableModel OneEntity = TablesEntities.FirstOrDefault(k => k.MetaData.ForeignKeys.Any(l => !l.IsParent && TablesEntities.Select(i => i.Name).Contains(l.Reference.TableName)));
            
            //Workaround for inverse foreign keys that couldn't be retrieved
            if (OneEntity == null)
                OneEntity = TablesEntities.Single(t => t.Name != ManyEntity.Name);

            var OneEntityX = OneEntity.ShapePlacementInfo.Location.X;
            var ManyEntityX = ManyEntity.ShapePlacementInfo.Location.X;

            if (OneEntityX < ManyEntityX)
                return LabelDirection.Left;

            if (ManyEntityX < OneEntityX)
                return LabelDirection.Right;

            return LabelDirection.Left;
        }
 private List<EntitySymbol> GetEntitiesByRelationship(RectangularLine selectedEntity)
 {
     var shapes = GetAllEntities();
     var tagLength = selectedEntity.Tag.ToString().Length;
     return shapes.Where(t => selectedEntity.Tag.ToString().Substring(0, tagLength - 1).Split('|').Contains(t.Tag.ToString())).ToList();
 }
        private Point GetLineApproximateMiddleConnectionPoint(RectangularLine fk)
        {
            var rect = fk.GetBoundingRectangle(true);
            int startX = rect.X;
            int startY = rect.Y;
            int endX = startX + rect.Width;
            int endY = startY + rect.Height;
            Point intersectPointY = new Point();

            for (int y = startY; y <= endY; y++)
            {
                Point p = new Point((startX + endX)/2, y);
                if (!fk.ContainsPoint(p.X, p.Y)) continue;

                intersectPointY = p;
                break;
            }

            return intersectPointY;
        }
 public DbRelationship GetDBRelByRelationshipLine(RectangularLine line, List<TableModel> tablesContainer)
 {
     var split = line.Tag.ToString().TrimEnd('R').Split('|');
     var rel = GetRelationshipByTables(tablesContainer, split[0], split[1]);
     return rel;
 }
        private void DrawRelationshipLabel(Tuple<string, string> kvpLink, RectangularLine fk, List<TableModel> tablesContainer, bool addToRepository)
        {
            //Get a point in the middle of the line and create there a control point
            Point fkMiddlePoint = GetLineApproximateMiddleConnectionPoint(fk);
            var retPoint = fk.AddConnectionPoint(fkMiddlePoint.X, fkMiddlePoint.Y);

            //If i have a Parent-Children kind of association (say, a tree representation in the DB model), 
            //the graphic would go boom so i just ignore it
            if (kvpLink.Item1 == kvpLink.Item2)
                return;

            var rel = GetRelationshipByTables(tablesContainer, kvpLink.Item1, kvpLink.Item2);
            var direction = GetLabelDirectionByRelationshipEntities(fk, tablesContainer);

            Label lbl = (Label) LblShape.CreateInstance();
            if (!rel.Generate)
            {
                lbl.CharacterStyle = (ICharacterStyle) Project.Design.FindStyleByName("LabelStyleNotGen", typeof (CharacterStyle));
                fk.LineStyle = (ILineStyle) Project.Design.FindStyleByName("RelNotGenerated", typeof (LineStyle));
            }
            else
            {
                lbl.CharacterStyle = (ICharacterStyle) Project.Design.FindStyleByName("LabelStyle", typeof (CharacterStyle));
                fk.LineStyle = (ILineStyle) Project.Design.FindStyleByName("RelGenerated", typeof (LineStyle));
            }

            if (rel.RelType == DbRelationshipType.OneToOne)
                lbl.Text = "<-1...1->";
            else
            {
                if (direction == LabelDirection.Right)
                    lbl.Text = "--N...1->";
                else if (direction == LabelDirection.Left)
                    lbl.Text = "<-1...N-";
            }
            lbl.Tag = String.Format("{0}|{1}L", kvpLink.Item1, kvpLink.Item2);
            lbl.CharacterStyle = Project.Design.CharacterStyles["LabelStyle"];
            
            lbl.Connect(lbl.GetControlPointIds(ControlPointCapabilities.Glue).ToList()[0], fk, retPoint);
            TableDiagram.Shapes.Add(lbl, Project.Repository.ObtainNewBottomZOrder(TableDiagram));

            if (addToRepository)
                Repository.Insert((Shape) lbl, TableDiagram);
        }
Beispiel #8
0
 internal static Shape CreateInstance(ShapeType shapeType, Template template)
 {
     Shape result = new RectangularLine(shapeType, template);
     return result;
 }
Beispiel #9
0
 /// <override></override>
 public override Shape Clone()
 {
     Shape result = new RectangularLine(Type, (Template)null);
     result.CopyFrom(this);
     return result;
 }