public override void AddToCanvas() { Diagram.TheCanvas.Children.Add(LineEndings); Diagram.TheCanvas.Children.Add(Line); if (Vertex.Get(@"BaseEdge:\Meta:") == MinusZero.Instance.Empty) { return; } /* foreach (DiagramItemBase i in Diagram.Items) * if (i.Vertex.Get(@"BaseEdge:\To:") == Vertex.Get(@"BaseEdge:\Meta:")) * MetaDiagramItem = i;*/ if (Diagram.GetItemsDictionary().ContainsKey(Vertex.Get(@"BaseEdge:\Meta:"))) { MetaDiagramItem = Diagram.GetItemsDictionary()[Vertex.Get(@"BaseEdge:\Meta:")].FirstOrDefault(); } if (MetaDiagramItem != null) { Diagram.TheCanvas.Children.Add(MetaLine); MetaDiagramItem.AddAsToMetaLine(this); } else { Diagram.TheCanvas.Children.Add(Label); } }
public virtual Point GetLineAnchorLocation(DiagramItemBase toItem, Point toPoint, int toItemDiagramLinesCount, int toItemDiagramLinesNumber, bool isSelfStart) { Point p = new Point(); p.X = Canvas.GetLeft(this) + this.ActualWidth / 2; p.Y = Canvas.GetTop(this) + this.ActualHeight / 2; return(p); }
public void AddDiagramLineVertex(IEdge edge, IVertex diagramLineDefinition, DiagramItemBase toItem) { IVertex r = MinusZero.Instance.Root; ((EasyVertex)Vertex).CanFireChangeEvent = false; IVertex l = VertexOperations.AddInstance(Vertex, diagramLineDefinition.Get("DiagramLineClass:"), r.Get(@"System\Meta\Visualiser\DiagramInternal\DiagramItemBase\DiagramLine")); GraphUtil.CreateOrReplaceEdge(l, r.Get(@"System\Meta\Visualiser\DiagramInternal\DiagramLineBase\ToDiagramItem"), toItem.Vertex); GraphUtil.CreateOrReplaceEdge(l, r.Get(@"System\Meta\Visualiser\DiagramInternal\DiagramLineBase\Definition"), diagramLineDefinition); Edge.CreateEdgeAndCreateOrReplaceEdgeByMeta(l, r.Get(@"System\Meta\ZeroTypes\HasBaseEdge\BaseEdge"), edge); AddDiagramLineObject(toItem, l); ((EasyVertex)Vertex).CanFireChangeEvent = true; }
public void AddDiagramLineObject(DiagramItemBase toItem, IVertex l) { DiagramLineBase newline = (DiagramLineBase)PlatformClass.CreatePlatformObject(l); newline.Diagram = this.Diagram; if (newline.Vertex.Get(@"Definition:\DiagramLineVertex:") != null) { Diagram.AddEdgesFromDefintion(newline.Vertex, newline.Vertex.Get(@"Definition:\DiagramLineVertex:")); } newline.FromDiagramItem = this; newline.ToDiagramItem = toItem; newline.AddToCanvas(); AddToDiagramLines(newline); toItem.DiagramToLines.Add(newline); UpdateDiagramLines(toItem); }
public override Point GetLineAnchorLocation(DiagramItemBase toItem, Point toPoint, int toItemDiagramLinesCount, int toItemDiagramLinesNumber, bool isSelfStart) { Point p = new Point(); Point p2 = new Point(); Point pTo = new Point(); Line2D firstLineSelf; if (toItem != null) { pTo.X = Canvas.GetLeft(toItem) + toItem.ActualWidth / 2; pTo.Y = Canvas.GetTop(toItem) + toItem.ActualHeight / 2; } else { pTo = toPoint; } double tX = Canvas.GetLeft(this) + this.ActualWidth / 2; double tY = Canvas.GetTop(this) + this.ActualHeight / 2; double testX = pTo.X - tX; double testY = pTo.Y - tY; if (testX == 0) { testX = 0.001; } if (testY == 0) { testY = 0.001; } double ovalX = Canvas.GetLeft(this) + this.Width / 2; double ovalY = Canvas.GetTop(this) + this.Height / 2; double ovalR2 = this.Width / 2; double ovalR1 = this.Height / 2; Oval o = new Oval(ovalX, ovalY, ovalR1, ovalR2); if (toItemDiagramLinesCount > 1) { if (toItem == this) { if (isSelfStart) { p.X = Canvas.GetLeft(this) + ((((double)toItemDiagramLinesNumber) / 2 + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p.Y = tY - this.ActualHeight / 2; p2.X = Canvas.GetLeft(this) + ((((double)toItemDiagramLinesNumber) / 2 + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p2.Y = tY - this.ActualHeight; firstLineSelf = Geometry2D.GetLine2DFromPoints(p, p2); return(Geometry2D.GetOvalLineCross(firstLineSelf, o)[0]); } else { p.X = tX + this.ActualWidth / 2; p.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - ((double)toItemDiagramLinesNumber) / 2)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); p2.X = tX + this.ActualWidth; p2.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - ((double)toItemDiagramLinesNumber) / 2)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); firstLineSelf = Geometry2D.GetLine2DFromPoints(p, p2); return(Geometry2D.GetOvalLineCross(firstLineSelf, o)[1]); } } Point pFrom = new Point(); pFrom.X = tX; if (testY <= 0) { pFrom.Y = Canvas.GetTop(this) + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight / 2); } else { pFrom.Y = tY + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight / 2); } Line2D firstLine = Geometry2D.GetLine2DFromPoints(pTo, pFrom); // we have two: // - line from pTo to pFrom (firstLine) // - oval if (testY <= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } if (testY <= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } } else { if (toItem == this) { if (isSelfStart) { p.X = tX; p.Y = tY - this.ActualHeight / 2; return(p); } else { p.X = tX + this.ActualWidth / 2; p.Y = tY; return(p); } } Point pFrom = new Point(); pFrom.X = tX; pFrom.Y = tY; Line2D firstLine = Geometry2D.GetLine2DFromPoints(pTo, pFrom); if (testY <= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } if (testY <= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } } return(p); }
public override Point GetLineAnchorLocation(DiagramItemBase toItem, Point toPoint, int toItemDiagramLinesCount, int toItemDiagramLinesNumber, bool isSelfStart) { Point p = new Point(); Point p2 = new Point(); Point pTo = new Point(); Point pRhombus1 = new Point(); Point pRhombus2 = new Point(); Line2D secondLine, firstLineSelf; if (toItem != null) { pTo.X = Canvas.GetLeft(toItem) + toItem.ActualWidth / 2; pTo.Y = Canvas.GetTop(toItem) + toItem.ActualHeight / 2; } else { pTo = toPoint; } double tX = Canvas.GetLeft(this) + this.ActualWidth / 2; double tY = Canvas.GetTop(this) + this.ActualHeight / 2; double testX = pTo.X - tX; double testY = pTo.Y - tY; if (testX == 0) { testX = 0.001; } if (testY == 0) { testY = 0.001; } if (toItemDiagramLinesCount > 1) { if (toItem == this) { if (isSelfStart) { p.X = Canvas.GetLeft(this) + ((((double)toItemDiagramLinesNumber) / 2 + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p.Y = tY - this.ActualHeight / 2; p2.X = Canvas.GetLeft(this) + ((((double)toItemDiagramLinesNumber) / 2 + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p2.Y = tY - this.ActualHeight; firstLineSelf = Geometry2D.GetLine2DFromPoints(p, p2); pRhombus1.X = Canvas.GetLeft(this); pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this); } else { p.X = tX + this.ActualWidth / 2; p.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - ((double)toItemDiagramLinesNumber) / 2)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); p2.X = tX + this.ActualWidth; p2.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - ((double)toItemDiagramLinesNumber) / 2)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); firstLineSelf = Geometry2D.GetLine2DFromPoints(p, p2); pRhombus1.X = Canvas.GetLeft(this) + this.ActualWidth; pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this) + this.ActualHeight; } secondLine = Geometry2D.GetLine2DFromPoints(pRhombus1, pRhombus2); return(Geometry2D.FindLineCross(firstLineSelf, secondLine)); } Point pFrom = new Point(); pFrom.X = tX; if (testY <= 0) { pFrom.Y = Canvas.GetTop(this) + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight / 2); } else { pFrom.Y = tY + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight / 2); } Line2D firstLine = Geometry2D.GetLine2DFromPoints(pTo, pFrom); // we have two lines: // - from pTo to pFrom (firstLine) // - from pRhombus1 to pRhombus2 (secondLine - depending on the rhombus side) if (testY <= 0 && testX <= 0) { pRhombus1.X = Canvas.GetLeft(this); pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this); } if (testY <= 0 && testX >= 0) { pRhombus1.X = Canvas.GetLeft(this) + this.ActualWidth; pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this); } if (testY >= 0 && testX >= 0) { pRhombus1.X = Canvas.GetLeft(this) + this.ActualWidth; pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this) + this.ActualHeight; } if (testY >= 0 && testX <= 0) { pRhombus1.X = Canvas.GetLeft(this); pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this) + this.ActualHeight; } secondLine = Geometry2D.GetLine2DFromPoints(pRhombus1, pRhombus2); return(Geometry2D.FindLineCross(firstLine, secondLine)); } else { if (toItem == this) { if (isSelfStart) { p.X = tX; p.Y = tY - this.ActualHeight / 2; return(p); } else { p.X = tX + this.ActualWidth / 2; p.Y = tY; return(p); } } Point pFrom = new Point(); pFrom.X = tX; pFrom.Y = tY; Line2D firstLine = Geometry2D.GetLine2DFromPoints(pTo, pFrom); pRhombus1 = new Point(); pRhombus2 = new Point(); // we have two lines: // - from pTo to pFrom (firstLine) // - from pRhombus1 to pRhombus2 (secondLine - depending on the rhombus side) if (testY <= 0 && testX <= 0) { pRhombus1.X = Canvas.GetLeft(this); pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this); } if (testY <= 0 && testX >= 0) { pRhombus1.X = Canvas.GetLeft(this) + this.ActualWidth; pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this); } if (testY >= 0 && testX >= 0) { pRhombus1.X = Canvas.GetLeft(this) + this.ActualWidth; pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this) + this.ActualHeight; } if (testY >= 0 && testX <= 0) { pRhombus1.X = Canvas.GetLeft(this); pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this) + this.ActualHeight; } secondLine = Geometry2D.GetLine2DFromPoints(pRhombus1, pRhombus2); return(Geometry2D.FindLineCross(firstLine, secondLine)); } return(p); }
public override Point GetLineAnchorLocation(DiagramItemBase toItem, Point toPoint, int toItemDiagramLinesCount, int toItemDiagramLinesNumber, bool isSelfStart) { Point p = new Point(); Point pTo = new Point(); if (toItem != null) { pTo.X = Canvas.GetLeft(toItem) + toItem.ActualWidth / 2; pTo.Y = Canvas.GetTop(toItem) + toItem.ActualHeight / 2; } else { pTo = toPoint; } double tX = Canvas.GetLeft(this) + this.ActualWidth / 2; double tY = Canvas.GetTop(this) + this.ActualHeight / 2; double testX = pTo.X - tX; double testY = pTo.Y - tY; if (testX == 0) { testX = 0.001; } if (testY == 0) { testY = 0.001; } if (toItemDiagramLinesCount > 1) { if (toItem == this) { if (isSelfStart) { p.X = Canvas.GetLeft(this) + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p.Y = tY - this.ActualHeight / 2; return(p); } else { p.X = tX + this.ActualWidth / 2; p.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - toItemDiagramLinesNumber)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); return(p); } } if (testY <= 0 && Math.Abs(testX * this.ActualHeight) <= Math.Abs(testY * this.ActualWidth)) { p.X = Canvas.GetLeft(this) + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p.Y = tY - this.ActualHeight / 2; } if (testY > 0 && Math.Abs(testX * this.ActualHeight) <= Math.Abs(testY * this.ActualWidth)) { p.X = Canvas.GetLeft(this) + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p.Y = tY + this.ActualHeight / 2; } if (testX >= 0 && Math.Abs(testX * this.ActualHeight) >= Math.Abs(testY * this.ActualWidth)) { p.X = tX + this.ActualWidth / 2; p.Y = Canvas.GetTop(this) + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); } if (testX <= 0 && Math.Abs(testX * this.ActualHeight) >= Math.Abs(testY * this.ActualWidth)) { p.X = tX - this.ActualWidth / 2; p.Y = Canvas.GetTop(this) + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); } } else { if (toItem == this) { if (isSelfStart) { p.X = tX; p.Y = tY - this.ActualHeight / 2; return(p); } else { p.X = tX + this.ActualWidth / 2; p.Y = tY; return(p); } } if (testY <= 0 && Math.Abs(testX * this.ActualHeight) <= Math.Abs(testY * this.ActualWidth)) { p.X = tX - (this.ActualHeight / 2 * testX / testY); p.Y = tY - this.ActualHeight / 2; } if (testY > 0 && Math.Abs(testX * this.ActualHeight) <= Math.Abs(testY * this.ActualWidth)) { p.X = tX + (this.ActualHeight / 2 * testX / testY); p.Y = tY + this.ActualHeight / 2; } if (testX >= 0 && Math.Abs(testX * this.ActualHeight) >= Math.Abs(testY * this.ActualWidth)) { p.X = tX + this.ActualWidth / 2; p.Y = tY + (this.ActualWidth / 2 * testY / testX); } if (testX <= 0 && Math.Abs(testX * this.ActualHeight) >= Math.Abs(testY * this.ActualWidth)) { p.X = tX - this.ActualWidth / 2; p.Y = tY - (this.ActualWidth / 2 * testY / testX); } } return(p); }
protected void UpdateDiagramLines(DiagramItemBase toItem) { List <DiagramLineBase> sameToItemLines = new List <DiagramLineBase>(); if (GetDiagramLinesToDiagramItemDictionary().ContainsKey(toItem.Vertex)) { foreach (DiagramLineBase l in GetDiagramLinesToDiagramItemDictionary()[toItem.Vertex]) { sameToItemLines.Add(l); } } /*foreach (DiagramLineBase l in DiagramLines) // OOO * if (l.Vertex.Get("ToDiagramItem:") == toItem.Vertex) * sameToItemLines.Add(l);*/ List <DiagramLineBase> sameFromItemLinesTo = new List <DiagramLineBase>(); if (toItem.GetDiagramLinesToDiagramItemDictionary().ContainsKey(this.Vertex)) { foreach (DiagramLineBase l in toItem.GetDiagramLinesToDiagramItemDictionary()[this.Vertex]) { sameFromItemLinesTo.Add(l); } } /*foreach (DiagramLineBase l in toItem.DiagramLines) // OOO * if (l.Vertex.Get("ToDiagramItem:") == this.Vertex) * sameFromItemLinesTo.Add(l);*/ int allCnt = sameToItemLines.Count() + sameFromItemLinesTo.Count(); int cnt = 0; if (toItem == this) { allCnt = allCnt / 2; } foreach (DiagramLineBase l in sameToItemLines) { Point start = GetLineAnchorLocation(toItem, new Point(), allCnt, cnt, toItem == this); Point end = toItem.GetLineAnchorLocation(this, new Point(), allCnt, cnt, false); if (toItem == this) { l.SetPosition(start.X, start.Y, end.X, end.Y, true, Canvas.GetLeft(this) + this.ActualWidth + 25 * (allCnt - cnt), Canvas.GetTop(this) - 25 * ((allCnt - cnt))); } else { l.SetPosition(start.X, start.Y, end.X, end.Y, false, 0, 0); } cnt++; } foreach (DiagramLineBase l in sameFromItemLinesTo) { Point end = GetLineAnchorLocation(toItem, new Point(), allCnt, cnt, false); Point start = toItem.GetLineAnchorLocation(this, new Point(), allCnt, cnt, false); if (toItem != this) { l.SetPosition(start.X, start.Y, end.X, end.Y, false, 0, 0); } cnt++; } }
public virtual void DoCreateDiagramLine(DiagramItemBase toItem) { IVertex toEdge = toItem.Vertex.Get("BaseEdge:"); IVertex r = m0.MinusZero.Instance.Root; IVertex v = m0.MinusZero.Instance.CreateTempVertex(); foreach (IEdge def in Vertex.GetAll(@"Definition:\DiagramLineDefinition:")) { bool CreateEdgeOnly = false; if (GraphUtil.GetValueAndCompareStrings(def.To.Get("CreateEdgeOnly:"), "True")) { CreateEdgeOnly = true; } foreach (IEdge e in Vertex.GetAll(@"BaseEdge:\To:\" + def.To.Get("EdgeTestQuery:"))) { bool canAdd = true; if (def.To.Get("ToDiagramItemTestQuery:") != null && toItem.Vertex.Get((string)def.To.Get("ToDiagramItemTestQuery:").Value) == null) { canAdd = false; } if (e.To.Get(@"$EdgeTarget:") != null && !GeneralUtil.CompareStrings(e.To.Get(@"$EdgeTarget:").Value, "Vertex") && // Vertexes do not have $Is:Vertex toEdge.Get(@"To:\$Is:" + (string)e.To.Get(@"$EdgeTarget:").Value) == null) { canAdd = false; } if (CreateEdgeOnly == false && e.To.Get(@"$VertexTarget:") != null && toEdge.Get(@"To:\$Is:" + (string)e.To.Get(@"$VertexTarget:").Value) == null) { canAdd = false; } if (canAdd) { AddNewLineOption(v, def, e); } } if (GeneralUtil.CompareStrings(def.To.Value, "Edge"))// Vertex\Edge { foreach (IEdge e in r.Get(@"System\Meta\Base\Vertex")) { AddNewLineOption(v, def, e); } } if (GeneralUtil.CompareStrings(def.To.Get("EdgeTestQuery:"), "$EdgeTarget")) // $EdgeTarget is not present as there is no inheritance from Vertex { AddNewLineOption(v, def, GraphUtil.FindEdgeByToVertex(r.Get(@"System\Meta\Base\Vertex"), "$EdgeTarget")); } } if (v.Count() == 0) { MinusZero.Instance.DefaultShow.ShowInfo("There is no diagram line definition matching selected source and target items."); } IVertex info = m0.MinusZero.Instance.CreateTempVertex(); info.Value = "choose diagram line:"; Point mousePosition = UIWpf.GetMousePosition(); IVertex a = MinusZero.Instance.DefaultShow.SelectDialog(info, v, mousePosition); if (a != null) { IVertex test = VertexOperations.TestIfNewEdgeValid(Vertex.Get(@"BaseEdge:\To:"), a.Get("OptionEdge:"), toEdge.Get("To:")); if (test == null) { bool?ForceShowEditForm = null; // ForceShowEditForm if (a.Get(@"OptionDiagramLineDefinition:\ForceShowEditForm:") != null) { if (GeneralUtil.CompareStrings(a.Get(@"OptionDiagramLineDefinition:\ForceShowEditForm:"), "True")) { ForceShowEditForm = true; } if (GeneralUtil.CompareStrings(a.Get(@"OptionDiagramLineDefinition:\ForceShowEditForm:"), "False")) { ForceShowEditForm = false; } } bool CreateEdgeOnly = false; // CreateEdgeOnly if (GraphUtil.GetValueAndCompareStrings(a.Get(@"OptionDiagramLineDefinition:\CreateEdgeOnly:"), "True")) { CreateEdgeOnly = true; } CanAutomaticallyAddEdges = false; // for VertexChange IEdge edge = VertexOperations.AddEdgeOrVertexByMeta(Vertex.Get(@"BaseEdge:\To:"), a.Get("OptionEdge:"), toEdge.Get("To:"), mousePosition, CreateEdgeOnly, ForceShowEditForm); CanAutomaticallyAddEdges = true; AddDiagramLineVertex(edge, a.Get(@"OptionDiagramLineDefinition:"), toItem); } else { MinusZero.Instance.DefaultShow.ShowInfo("Adding new diagram line \"" + a.Value + "\" is not possible.\n\n" + test.Value); } } }