void AddArrow(Edge drawingEdge, StreamGeometryContext context, Point start, Point end, double lineWidthOfAttachedNode) { Point dir = end - start; double dl = dir.Length; double scaling = (dl < 12? 1 : 12 / dl) / _scale; Point new_start = end - (end - start) * scaling; //take into account the widths double delta = Math.Min(dl / 2, drawingEdge.Attr.LineWidth + lineWidthOfAttachedNode / 2); //dir *= (dl - delta) / dl; end = start + dir; dir = dir.Rotate(Math.PI / 2); Point s = dir * HalfArrowAngleTan * scaling; context.BeginFigure(CommonX.WpfPoint(start), true, true); context.LineTo(CommonX.WpfPoint(new_start), true, true); if (_category == "References") { double r = dl * scaling / 2; context.ArcTo(CommonX.WpfPoint(end), new Size(r, r), 0, true, SweepDirection.Clockwise, true, true); context.ArcTo(CommonX.WpfPoint(new_start), new Size(r, r), 0, true, SweepDirection.Clockwise, true, true); } else { context.LineTo(CommonX.WpfPoint(new_start + s), true, true); context.LineTo(CommonX.WpfPoint(end), true, true); context.LineTo(CommonX.WpfPoint(new_start - s), true, true); context.LineTo(CommonX.WpfPoint(new_start), true, true); } }
internal static void DrawDiamondArrow(PathGeometry pg, MsaglPoint start, MsaglPoint end) { MsaglPoint dir = end - start; MsaglPoint h = dir; dir /= dir.Length; var s = new MsaglPoint(-dir.Y, dir.X); PathFigure pf = new PathFigure(); pf.StartPoint = WinPoint(start - dir); pf.Segments.Add(new WinLineSegment() { Point = WinPoint(start + (h / 2) + s * (h.Length / 3)) }); pf.Segments.Add(new WinLineSegment() { Point = WinPoint(end) }); pf.Segments.Add(new WinLineSegment() { Point = WinPoint(start + (h / 2) - s * (h.Length / 3)) }); pf.IsClosed = true; pg.Figures.Add(pf); }
const double arrowAngle = 25.0; //degrees internal static void DrawArrow(PathGeometry pg, MsaglPoint start, MsaglPoint end, double thickness, ArrowStyle arrowStyle, bool fill) { switch (arrowStyle) { case ArrowStyle.NonSpecified: case ArrowStyle.Normal: DrawNormalArrow(pg, start, end, thickness, fill); break; case ArrowStyle.Tee: DrawTeeArrow(pg, start, end, fill); break; case ArrowStyle.Diamond: DrawDiamondArrow(pg, start, end); break; case ArrowStyle.ODiamond: DrawODiamondArrow(pg, start, end); break; case ArrowStyle.Generalization: DrawGeneralizationArrow(pg, start, end); break; default: throw new InvalidOperationException(); } }
internal static void DrawNormalArrow(PathGeometry pg, MsaglPoint start, MsaglPoint end, double thickness, bool fill) { MsaglPoint dir = end - start; MsaglPoint h = dir; dir /= dir.Length; // compensate for line thickness end -= dir * thickness / ((double)Math.Tan(arrowAngle * (Math.PI / 180.0))); var s = new MsaglPoint(-dir.Y, dir.X); s *= h.Length * ((double)Math.Tan(arrowAngle * 0.5 * (Math.PI / 180.0))); PathFigure pf = new PathFigure() { IsFilled = fill, IsClosed = true }; pf.StartPoint = WinPoint(start + s); pf.Segments.Add(new WinLineSegment() { Point = WinPoint(end) }); pf.Segments.Add(new WinLineSegment() { Point = WinPoint(start - s) }); pg.Figures.Add(pf); /*pf = new PathFigure(); * pf.StartPoint = WinPoint(start); * pf.Segments.Add(new System.Windows.Media.LineSegment() { Point = WinPoint(end) }); * pg.Figures.Add(pf);*/ }
Geometry CreateGeometryFromMsaglCurve(ICurve iCurve) { var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure { IsClosed = true, IsFilled = true }; Point c = Node.Attr.GeometryNode.Center; //we need to move the center to the origin, because the node position is later shifted to the center pathFigure.StartPoint = CommonX.WpfPoint(iCurve.Start - c); var curve = iCurve as Curve; if (curve != null) { AddCurve(pathFigure, c, curve); } else { var rect = iCurve as RoundedRect; if (rect != null) { AddCurve(pathFigure, c, rect.Curve); } else { throw new Exception(); } } pathGeometry.Figures.Add(pathFigure); return(pathGeometry); }
private static ICurve CreateLabelAndBoundary(NavigationPoint navigationPoint, Microsoft.Msagl.Drawing.Node node) { node.Attr.LabelMargin *= 2; node.Label.IsVisible = false; var y = (navigationPoint.Latitude - airfield.Latitude) * 200000; var x = (navigationPoint.Longitude - airfield.Longitude) * 200000; var positionalPoint = new Microsoft.Msagl.Core.Geometry.Point(x, y); switch (navigationPoint) { case Runway _: node.Attr.Color = Color.Green; return(CurveFactory.CreateCircle(50, positionalPoint)); case Junction _: node.Attr.Shape = Shape.Hexagon; node.Attr.Color = Color.Blue; return(CurveFactory.CreateHexagon(100, 30, positionalPoint)); case ParkingSpot _: node.Attr.Color = Color.Orange; return(CurveFactory.CreateOctagon(100, 30, positionalPoint)); case WayPoint _: node.Attr.Color = Color.Purple; return(CurveFactory.CreateRectangle(100, 30, positionalPoint)); } return(CurveFactory.CreateCircle(5, positionalPoint)); }
private void GraphEditor_MouseUp(object sender, MsaglMouseEventArgs e) { if (e.RightButtonIsPressed) { return; } var point = new GeometryPoint(e.X, e.Y); object obj = gViewer.GetObjectAt((int)point.X, (int)point.Y); if (obj is DNode && SelectedEntities.Count > 0) { Submodel displayedModel = null; if (this.Viewer.Tag != null && this.Viewer.Tag is Submodel) { displayedModel = this.Viewer.Tag as Submodel; } if (displayedModel != null && displayedModel.Model != null) { displayedModel.Model.CaptureCoordinates(); } } }
private Rectangle CreateDescription(Point origin, out Visual visual) { if (_vsGraphNodeInfo != null) { DrawingVisual desc = new DrawingVisual(); DrawingContext context = desc.RenderOpen(); string properties = ""; foreach (KeyValuePair <GraphProperty, object> kvp in _vsGraphNodeInfo.Properties) { string name = kvp.Key.ToString(); bool value = (kvp.Value is bool && ((bool)kvp.Value) == true); if (name.StartsWith("CodeSchemaProperty_Is") && value) { properties += (properties.Length > 0 ? " : " : "") + name.Replace("CodeSchemaProperty_Is", ""); } } FormattedText fText = new FormattedText(properties, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Calibri"), _fontSize * 0.8, Brushes.Black); fText.SetFontStyle(FontStyles.Italic); fText.TextAlignment = TextAlignment.Center; context.DrawText(fText, CommonX.WpfPoint(origin)); context.Close(); _textMeasurer.FontSize = _fontSize * 0.8; _textMeasurer.Text = properties; Size size = CommonX.Measure(_textMeasurer); visual = desc; return(new Rectangle(origin.X - size.Width / 2, origin.Y, origin.X + size.Width / 2, origin.Y + size.Height)); } visual = null; return(new Rectangle()); }
public static void InsertSite(Site siteBeforeInsertion, GPoint point) { //creating the new site Site first = siteBeforeInsertion; Site second = first.Next; var s = new Site(first, point, second); }
static void AddCurve(PathFigure pathFigure, Curve curve) { foreach (ICurve seg in curve.Segments) { var ls = seg as LineSegment; if (ls != null) { pathFigure.Segments.Add(new Windows.UI.Xaml.Media.LineSegment { Point = Common.UwpPoint(ls.End) }); } else { var ellipse = seg as Ellipse; if (ellipse != null) { pathFigure.Segments.Add(new ArcSegment { Point = Common.UwpPoint(ellipse.End), Size = new Size(ellipse.AxisA.Length, ellipse.AxisB.Length), RotationAngle = Point.Angle(new Point(1, 0), ellipse.AxisA), //ellipse.ParEnd - ellipse.ParEnd >= Math.PI, SweepDirection = !ellipse.OrientedCounterclockwise() ? SweepDirection.Counterclockwise : SweepDirection.Clockwise }); } } } }
// For tee arrows, "fill" indicates whether the line should continue up to the node's boundary. static void DrawTeeArrow(PathGeometry pg, MsaglPoint start, MsaglPoint end, bool fill) { MsaglPoint dir = end - start; MsaglPoint h = dir; dir /= dir.Length; if (fill) { PathFigure pf = new PathFigure(); pf.StartPoint = WinPoint(start); pf.Segments.Add(new WinLineSegment() { Point = WinPoint(end) }); pg.Figures.Add(pf); } var s = new MsaglPoint(-dir.Y, dir.X); s *= 2 * h.Length * ((float)Math.Tan(arrowAngle * 0.5f * (Math.PI / 180.0))); s += s.Normalize(); PathFigure pf2 = new PathFigure(); pf2.StartPoint = WinPoint(start + s); pf2.Segments.Add(new WinLineSegment() { Point = WinPoint(start - s) }); pg.Figures.Add(pf2); }
private const double ArrowAngle = 30.0; //degrees private static void CreateWideEdgeArrow(StreamGeometryContext context, GeometryPoint start, GeometryPoint end, double pathStrokeThickness) { GeometryPoint dir = end - start; GeometryPoint h = dir; double dl = dir.Length; if (dl < 0.001) { return; } dir /= dl; var s = new GeometryPoint(-dir.Y, dir.X); double w = 0.5 * pathStrokeThickness; GeometryPoint s0 = w * s; s *= h.Length * HalfArrowAngleTan; s += s0; double rad = w / HalfArrowAngleCos; context.BeginFigure((start + s).ToWpf(), true, true); context.LineTo((start - s).ToWpf(), true, false); context.LineTo((end - s0).ToWpf(), true, false); context.ArcTo((end + s0).ToWpf(), new Size(rad, rad), Math.PI - ArrowAngle, false, SweepDirection.Clockwise, true, false); }
static void DrawArrow(Cairo.Color pen, Cairo.Context graphics, Point start, Point end) { float arrowAngle = 30; Point dir = end - start; Point h = dir; dir /= dir.Length; Point s = new(-dir.Y, dir.X); s *= h.Length * ((float)Math.Tan(arrowAngle * 0.5f * (Math.PI / 180.0))); var points = new Cairo.Point[] { MsaglPointToDrawingPoint(start + s), MsaglPointToDrawingPoint(end), MsaglPointToDrawingPoint(start - s) }; //graphics.FillPolygon(pen.Brush, points); graphics.SetSourceColor(pen); var first = points.First(); graphics.MoveTo(first.X, first.Y); foreach (var point in points.Skip(1)) { graphics.LineTo(point.X, point.Y); } graphics.LineTo(first.X, first.Y); graphics.Fill(); }
static void AddCurve(PathFigure pathFigure, Curve curve) { foreach (ICurve seg in curve.Segments) { var ls = seg as LineSegment; if (ls != null) { pathFigure.Segments.Add(new System.Windows.Media.LineSegment(Common.WpfPoint(ls.End), true)); } else { var ellipse = seg as Ellipse; if (ellipse != null) { pathFigure.Segments.Add(new ArcSegment(Common.WpfPoint(ellipse.End), new Size(ellipse.AxisA.Length, ellipse.AxisB.Length), Point.Angle(new Point(1, 0), ellipse.AxisA), ellipse.ParEnd - ellipse.ParEnd >= Math.PI, !ellipse.OrientedCounterclockwise() ? SweepDirection.Counterclockwise : SweepDirection.Clockwise, true)); } } } }
private bool HitDetect(MSAGLPoint point) { ICurve curve = Edge.Curve; MSAGLPoint closest = Curve.ClosestPoint(curve, point); double length = (point - closest).Length; return(length < 8); }
static bool WithinEpsilon(ICurve bc, double start, double end) { int n = 3; //hack !!!! double d = (end - start) / n; P2 s = bc[start]; P2 e = bc[end]; return(DistToSegm(bc[start + d], s, e) < epsilon && DistToSegm(bc[start + d * (n - 1)], s, e) < epsilon); }
internal static double DistToSegm(P2 p, P2 s, P2 e) { P2 l = e - s; double len = l.Length; if (len < epsilon) return (p - (0.5f*(s + e))).Length; var perp = new P2(-l.Y, l.X); perp /= len; return Math.Abs((p - s)*perp); }
//when we check for inclusion we expand the box by slack internal Geometry Hit(MsaglPoint p, double slack, EntityFilterDelegate filter) { if (filter != null && this.geometry != null) { if (filter(geometry.dObject) == false) { return(null); } } if (left == null) { if (Box.Contains(p, slack)) { Line line = geometry as Line; if (line != null) { if (Tessellator.DistToSegm(p, line.start, line.end) < slack + line.LineWidth / 2) { return(line); } return(null); } else if (Box.Contains(p)) { return(geometry); } return(null); } else { return(null); } } if (left.Box.Contains(p, slack)) { Geometry g = left.Hit(p, slack, filter); if (g != null) { return(g); } } if (right.Box.Contains(p, slack)) { Geometry g = right.Hit(p, slack, filter); if (g != null) { return(g); } } return(null); }
private void btnSearch_Click(object sender, EventArgs e) { HashSet <DrawingNode> closeNodes = new HashSet <DrawingNode>(); foreach (DrawingNode node in viewer.Graph.Nodes) { if (node.LabelText.ToUpper().Contains(tbSearch.Text.ToUpper())) { //P2 nPoint = node.Pos; P2 nCenterPoint = viewer.Graph.FindGeometryNode(node.Id).Center; //viewer.MapSourceRectangleToScreenRectangle closeNodes.Add(node); // Found Node DrawingNode tNode = node; //while (tNode != null) //{ // if (tNode.OutEdges.Count() > 0) // { // foreach (DrawingEdge item in tNode.OutEdges) // { // closeNodes.Add(item.TargetNode); // tNode = item.TargetNode; // Could stack or queue.. // } // } // else // { // tNode = null; // } //} //tNode = node; //while (tNode != null) //{ if (tNode.InEdges.Count() > 0) { foreach (DrawingEdge item in tNode.InEdges) { closeNodes.Add(item.SourceNode); tNode = item.SourceNode; // Could stack or queue.. } } else { tNode = null; } //} //Point np = viewer.ShowGroup(closeNodes.ToArray()); //viewer.CenterToGroup(closeNodes.ToArray()); //viewer.CenterToPoint(nCenterPoint); //viewer.Scree //viewer.PerformAutoScale(); } } viewer.Focus(); // Set Focus back to viewer }
internal static double DistToSegm(MsaglPoint p, MsaglPoint s, MsaglPoint e) { MsaglPoint l = e - s; double len = l.Length; if (len < Tessellator.epsilon) return (p - (0.5f * (s + e))).Length; MsaglPoint perp = new MsaglPoint(-l.Y, l.X); perp /= len; return Math.Abs((p - s) * perp); }
Rectangle CreateRectForRubberEdge() { var rect = new BBox(rubberLineStart, RubberLineEnd); double w = gViewer.LineThicknessForEditing; var del = new P2(-w, w); rect.Add(rect.LeftTop + del); rect.Add(rect.RightBottom - del); return(GViewer.CreateScreenRectFromTwoCornersInTheSource(rect.LeftTop, rect.RightBottom)); }
/// <summary> /// Inserts a new node at the selected point, using the node type with the specified name. /// </summary> /// <param name="center">The location of the node on the graph</param> /// <param name="nodetype">The name of the node type</param> /// <param name="id">The id for the node</param> /// <returns>The new node</returns> internal virtual DrawingNode InsertNode(Point center, string nodetype, string id) { foreach (NodeTypeEntry nte in m_NodeTypes) { if (nte.Name == nodetype) { return(InsertNode(center, nte, id)); } } return(null); }
private static void CreateEdgeArrow(StreamGeometryContext context, GeometryPoint start, GeometryPoint end, double pathStrokeThickness) { if (pathStrokeThickness > 1) { CreateWideEdgeArrow(context, start, end, pathStrokeThickness); } else { CreateThinEdgeArrow(context, start, end, pathStrokeThickness); } }
private void MainForm_MouseDown(object sender, MsaglMouseEventArgs e) { if (e.RightButtonIsPressed && e.LeftButtonIsPressed && !e.Handled) { m_MouseRightButtonDownPoint = (gViewer).ScreenToSource(e); } if (gViewer.ObjectUnderMouseCursor is DrawingObject drawing) { this.propertyGrid1.SelectedObject = Source; } }
internal static void DrawLine(PathGeometry pg, MsaglPoint start, MsaglPoint end) { PathFigure pf = new PathFigure() { StartPoint = WinPoint(start) }; pf.Segments.Add(new WinLineSegment() { Point = WinPoint(end) }); pg.Figures.Add(pf); }
public static SmoothedPolyline SmoothedPolylineTranslate(SmoothedPolyline smoothedPolyline, Vector deltaVec) { GPoint delta = new GPoint(deltaVec.X, deltaVec.Y); SmoothedPolyline sm = smoothedPolyline.Clone(); for (Microsoft.Msagl.Core.Geometry.Site s = sm.HeadSite, s0 = sm.HeadSite; s != null; s = s.Next, s0 = s0.Next) { s.Point = s0.Point + delta; } return(sm); }
void Form1_MouseDown(object sender, MsaglMouseEventArgs e) { /*if (e.RightButtonIsPressed && this.gViewer.DrawingLayoutEditor.SelectedEdge != null && this.gViewer.ObjectUnderMouseCursor == this.gViewer.DrawingLayoutEditor.SelectedEdge) * ProcessRightClickOnSelectedEdge(e); * else*/ if (e.RightButtonIsPressed && !e.Handled) { m_MouseRightButtonDownPoint = (gViewer).ScreenToSource(e); //ContextMenu cm = BuildContextMenu(m_MouseRightButtonDownPoint); //cm.Show(this, new System.Drawing.Point(e.X, e.Y)); } }
internal static double DistToSegm(P2 p, P2 s, P2 e) { P2 l = e - s; double len = l.Length; if (len < epsilon) { return((p - (0.5f * (s + e))).Length); } var perp = new P2(-l.Y, l.X); perp /= len; return(Math.Abs((p - s) * perp)); }
private static Path CreateEdgeRailArrowhead(Rail rail, Arrowhead arrowhead, GeometryPoint curveAttachmentPoint, byte edgeTransparency, double pathStrokeThickness) { var streamGeometry = new StreamGeometry(); using (StreamGeometryContext context = streamGeometry.Open()) CreateEdgeArrow(context, curveAttachmentPoint, arrowhead.TipPosition, pathStrokeThickness); var path = new Path { Data = streamGeometry, }; return(path); }
internal static double DistToSegm(MsaglPoint p, MsaglPoint s, MsaglPoint e) { MsaglPoint l = e - s; double len = l.Length; if (len < Tessellator.epsilon) { return((p - (0.5f * (s + e))).Length); } MsaglPoint perp = new MsaglPoint(-l.Y, l.X); perp /= len; return(Math.Abs((p - s) * perp)); }
/* * void FlipCollapsePath() { * var size = GetCollapseBorderSymbolSize(); * var center = GetCollapseButtonCenter(size); * * if (collapsePathFlipped) { * collapsePathFlipped = false; * collapseSymbolPath.RenderTransform = null; * } * else { * collapsePathFlipped = true; * collapseSymbolPath.RenderTransform = new RotateTransform(180, center.X, center.Y); * } * } */ Geometry CreateCollapseSymbolPath(Point center, double width) { var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure { StartPoint = Common.WpfPoint(center + new Point(-width, width)) }; pathFigure.Segments.Add(new System.Windows.Media.LineSegment(Common.WpfPoint(center), true)); pathFigure.Segments.Add( new System.Windows.Media.LineSegment(Common.WpfPoint(center + new Point(width, width)), true)); pathGeometry.Figures.Add(pathFigure); return(pathGeometry); }
//when we check for inclusion we expand the box by slack internal Geometry Hit(P2 p, double slack, EntityFilterDelegate filter, List<Geometry> subgraphCandidates) { if (filter != null && geometry != null) if (filter(geometry.dObject) == false) return null; if (left == null) if (Box.Contains(p, slack)) { Line line = geometry as Line; if (line != null) { if (Tessellator.DistToSegm(p, line.start, line.end) < slack + line.LineWidth/2) return line; return null; } if (Box.Contains(p)) { var subg = geometry.dObject.DrawingObject as Subgraph; if (subg != null) subgraphCandidates.Add(geometry); else return geometry; } return null; } else return null; if (left.Box.Contains(p, slack)) { Geometry g = left.Hit(p, slack, filter, subgraphCandidates); if (g != null) { return g; } } if (right.Box.Contains(p, slack)) { Geometry g = right.Hit(p, slack, filter, subgraphCandidates); if (g != null) return g; } return null; }
private static void AddUnderlyingPolylineTessellation(List <ObjectWithBox> list, DEdge edge, double radiusForUnderlyingPolylineCorners) { MsaglPoint rad = new MsaglPoint(radiusForUnderlyingPolylineCorners, radiusForUnderlyingPolylineCorners); IEnumerator <MsaglPoint> en = edge.DrawingEdge.GeometryEdge.UnderlyingPolyline.GetEnumerator(); en.MoveNext(); MsaglPoint p = en.Current; list.Add(new Geometry(edge, new MsaglRectangle(p + rad, p - rad))); while (en.MoveNext()) { list.Add(new Line(edge, p, p = en.Current, edge.DrawingEdge.Attr.LineWidth)); list.Add(new Geometry(edge, new MsaglRectangle(p + rad, p - rad))); } }
private void DrawArrow(Edge e, Pen pen, Graphics graphics, P start, P end) { PointF[] points; float arrowAngle = 30; P dir = end - start; P h = dir; dir /= dir.Length; P s = new P(-dir.Y, dir.X); s *= h.Length * ((float)Math.Tan(arrowAngle * 0.5f * (Math.PI / 180.0))); points = new PointF[] { MsaglPointToDrawingPoint(start + s), MsaglPointToDrawingPoint(end), MsaglPointToDrawingPoint(start - s) }; graphics.FillPolygon(pen.Brush, points); }
//when we check for inclusion we expand the box by slack internal Geometry Hit(MsaglPoint p, double slack, EntityFilterDelegate filter) { if (filter != null && this.geometry != null) if (filter(geometry.dObject) == false) return null; if (left == null) if (Box.Contains(p, slack)) { Line line = geometry as Line; if (line != null) { if (Tessellator.DistToSegm(p, line.start, line.end) < slack + line.LineWidth / 2) return line; return null; } else if (Box.Contains(p)) return geometry; return null; } else return null; if (left.Box.Contains(p, slack)) { Geometry g = left.Hit(p, slack, filter); if (g != null) { return g; } } if (right.Box.Contains(p, slack)) { Geometry g = right.Hit(p, slack, filter); if (g != null) return g; } return null; }
public Form1() { InitializeComponent(); Node n0 = new Node( CurveFactory.CreateEllipse(10, 10, new Microsoft.Msagl.Core.Geometry.Point()),"a"); Microsoft.Msagl.Core.Geometry.Point n1Center = new Microsoft.Msagl.Core.Geometry.Point(20, 0); Node n1 = new Node( CurveFactory.CreateEllipse(10, 10, n1Center),"b"); n1.Center = n1Center; Microsoft.Msagl.Core.Geometry.Point n2Center = new Microsoft.Msagl.Core.Geometry.Point(5, 3); Node n2 = new Node( CurveFactory.CreateEllipse(10, 10, n2Center),"c"); n2.Center = n2Center; Microsoft.Msagl.Core.Geometry.Point n3Center = new Microsoft.Msagl.Core.Geometry.Point(8, -1); Node n3 = new Node( CurveFactory.CreateEllipse(10, 10, n3Center),"d"); n3.Center = n3Center; Microsoft.Msagl.Core.Geometry.Point n4Center = new Microsoft.Msagl.Core.Geometry.Point(6, -4); Node n4 = new Node( CurveFactory.CreateEllipse(10, 10, n4Center),"e"); n4.Center = n4Center; Microsoft.Msagl.Core.Geometry.Point n5Center = new Microsoft.Msagl.Core.Geometry.Point(19, -3); Node n5 = new Node( CurveFactory.CreateEllipse(10, 10, n5Center),"f"); n5.Center = n5Center; IncrementalLabeler il = new IncrementalLabeler(6, false, -1); #if MYDEBUG Microsoft.Msagl.GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions(); #endif il.AddNode(n0); il.AddNode(n1); il.Layout(); il.AddNode(n2); il.AddNode(n3); il.Layout(); GeometryGraph graph = LocationLabeler.PositionLabels(new[] { n0, n1, n2, n3, n4, n5 }, 5, false, -1); // var g=GeometryGraph.CreateFromFile("c:/tmp/graph"); // ChangeShapes(g); // var graph = LocationLabeler.PositionLabels( g.Nodes , 6, false, -6); }
void ProcessGexf(string fileName) { int line, column; string msg; Graph dgraph = GexfParser.Parse(fileName, out line, out column, out msg); if (dgraph != null) { SetLayoutSettings(dgraph); var origin = new Microsoft.Msagl.Core.Geometry.Point(0, 0); bool layoutExist = dgraph.GeometryGraph != null && dgraph.GeometryGraph.Nodes.All(n => n.BoundaryCurve != null) && dgraph.GeometryGraph.Nodes.Any(n => n.Center != origin); _graphViewer.NeedToCalculateLayout = !layoutExist; _graphViewer.Graph = dgraph; _graphViewer.NeedToCalculateLayout = true; } else MessageBox.Show(msg + String.Format(" line {0} column {1}", line, column)); }
static PointF PointF(Point point) { return new PointF((float)point.X, (float)point.Y); }
static void DrawArrow(Pen pen, Graphics graphics, Point start, Point end) { float arrowAngle = 30; Point dir = end - start; Point h = dir; dir /= dir.Length; Point s = new Point(-dir.Y, dir.X); s *= h.Length * ((float)Math.Tan(arrowAngle * 0.5f * (Math.PI / 180.0))); var points = new PointF[] { MsaglPointToDrawingPoint(start + s), MsaglPointToDrawingPoint(end), MsaglPointToDrawingPoint(start - s) }; graphics.FillPolygon(pen.Brush, points); }
void EndDragging(WinPoint p, MsaglPoint gp) { PanningStartOffset = null; if (MouseMode == DraggingMode.WindowZoom && DragWindowStart != null) DoWindowZoom(DragWindowStart.Value, gp); DragWindowStart = null; DrawDragWindow(gp); if (RouteEdgesAfterDragging && DrawingLayoutEditor.CurrentUndoAction is ObjectDragUndoRedoAction) { //RouteSelectedEdges((int)Graph.LayoutAlgorithmSettings.NodeSeparation); var settings = new EdgeRoutingSettings() { EdgeRoutingMode = Core.Routing.EdgeRoutingMode.Spline }; DoEdgeRouting(Graph.GeometryGraph, settings, Graph.LayoutAlgorithmSettings.NodeSeparation); } }
public static System.Drawing.Point MsaglPointToDrawingPoint(Point point) { return new System.Drawing.Point((int)point.X, (int)point.Y); }
void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e) { foreach (NodeTypeEntry nte in m_NodeTypes) if (nte.Button == e.Button) { var center = new Point(); var random = new Random(1); var rect1 = gViewer.ClientRectangle; //gViewer.Graph.GeometryGraph.BoundingBox; var rect2 = gViewer.Graph.BoundingBox; Point p = gViewer.ScreenToSource(rect1.Location); Point p2 = gViewer.ScreenToSource(rect1.Location + rect1.Size); if (p.X < rect2.Left) p.X = rect2.Left; if (p2.X > rect2.Right) p2.X = rect2.Right; if (p.Y > rect2.Top) p.Y = rect2.Top; if (p2.Y < rect2.Bottom) p2.Y = rect2.Bottom; var rect = new Microsoft.Msagl.Core.Geometry.Rectangle(p, p2); center.X = rect.Left + random.NextDouble()*rect.Width; center.Y = rect.Bottom + random.NextDouble()*rect.Height; } }
private void DoWindowZoom(MsaglPoint start, MsaglPoint end) { double width = Math.Abs(start.X - end.X); double height = Math.Abs(start.Y - end.Y); double zoom = Math.Min(MainScrollViewer.ViewportWidth / width, MainScrollViewer.ViewportHeight / height); if (zoom > 5.0) return; Zoom = zoom; MainScrollViewer.UpdateLayout(); WinPoint p = MainCanvas.RenderTransform.Transform(new WinPoint(start.X, start.Y)); MainScrollViewer.ScrollToHorizontalOffset(p.X); MainScrollViewer.ScrollToVerticalOffset(p.Y); }
/// <summary> /// Builds the context menu for when the user right-clicks on the graph. /// </summary> /// <param name="point">The point where the user clicked</param> /// <returns>The context menu to be displayed</returns> protected virtual ContextMenu BuildContextMenu(Point point) { var cm = new ContextMenu(); MenuItem mi; mi = new MenuItem(); mi.MeasureItem += mi_MeasureItem; mi.DrawItem += mi_DrawItem; mi.Text = "Pridať hranu"; mi.Click += hrana; cm.MenuItems.Add(mi); mi = new MenuItem(); mi.Text = "-"; cm.MenuItems.Add(mi); mi.MeasureItem += mi_MeasureItem; mi.DrawItem += mi_DrawItem; mi.Text = "Pridať koncept"; mi.Click += InsertNode; cm.MenuItems.Add(mi); mi = new MenuItem(); mi.Text = "Vymazať"; mi.Click += deleteSelected_Click; cm.MenuItems.Add(mi); if (gViewer.SelectedObject != null) { mi = new MenuItem(); mi.Text = "Informácie"; mi.Click += NodeInfo; cm.MenuItems.Add(mi); } mi = new MenuItem(); mi.Text = "Prepočítať koncepty"; mi.Click += Recalculate; cm.MenuItems.Add(mi); mi = new MenuItem(); mi.Text = "Resetovať"; mi.Click += redoLayout_Click; cm.MenuItems.Add(mi); return cm; }
void DoDragging(WinPoint p, MsaglPoint gp) { if (PanningStartOffset.HasValue && MouseMode == DraggingMode.Pan) DoPanning(p); else if (MouseMode == DraggingMode.WindowZoom || MouseMode == DraggingMode.LayoutEdit) DrawDragWindow(gp); }
public FrameworkElement CreateFrameworkElementForRailArrowhead(Rail rail, Arrowhead arrowhead, Point curveAttachmentPoint, byte edgeTransparency) { var streamGeometry = new StreamGeometry(); using (StreamGeometryContext context = streamGeometry.Open()) { AddArrow(context, curveAttachmentPoint, arrowhead.TipPosition, PathStrokeThickness); //arrowhead.BasePoint = curveAttachmentPoint; } var path=new Path { Data = streamGeometry, Tag = this }; SetPathStrokeToRailPath(rail, path); return path; }
public DNode AddNodeAtLocation(MsaglPoint p) { return AddNodeAtLocation(p, false); }
public static void AddArrow(StreamGeometryContext context,Point start,Point end, double thickness) { if(thickness > 1) { Point dir = end - start; Point h = dir; double dl = dir.Length; if(dl < 0.001) return; dir /= dl; var s = new Point(-dir.Y,dir.X); double w = 0.5 * thickness; Point s0 = w * s; s *= h.Length * HalfArrowAngleTan; s += s0; double rad = w / HalfArrowAngleCos; context.BeginFigure(Common.WpfPoint(start + s),true,true); context.LineTo(Common.WpfPoint(start - s),true,false); context.LineTo(Common.WpfPoint(end - s0),true,false); context.ArcTo(Common.WpfPoint(end + s0),new Size(rad,rad), Math.PI - ArrowAngle,false,SweepDirection.Clockwise,true,false); } else { Point dir = end - start; double dl = dir.Length; //take into account the widths double delta = Math.Min(dl / 2, thickness + thickness / 2); dir *= (dl - delta) / dl; end = start + dir; dir = dir.Rotate(Math.PI / 2); Point s = dir * HalfArrowAngleTan; context.BeginFigure(Common.WpfPoint(start + s),true,true); context.LineTo(Common.WpfPoint(end),true,true); context.LineTo(Common.WpfPoint(start - s),true,true); } }
public DNode AddNodeAtLocation(MsaglPoint p, string id) { return AddNodeAtLocation(p, id, false); }
public DNode AddNodeAtLocation(MsaglPoint p, bool registerForUndo) { return AddNodeAtLocation(p, null, registerForUndo); }
void StartDragging(WinPoint p, MsaglPoint gp) { if (MouseMode == DraggingMode.Pan) PanningStartOffset = new WinPoint() { X = MainScrollViewer.HorizontalOffset, Y = MainScrollViewer.VerticalOffset }; else if (MouseMode == DraggingMode.WindowZoom || (LayoutEditingEnabled && ObjectUnderMouseCursor == null && DrawingLayoutEditor.SelectedEdge == null)) DragWindowStart = gp; }
public GeneratingPopupEventArgs(ListBox listBox, MsaglPoint mousePos) : base() { ListBox = listBox; MousePos = mousePos; }
void UpdateObjectUnderCursor(MsaglPoint graphPos) { /* var o = GetObjectAtPosition(graphPos); if (o != ObjectUnderMouseCursor) { var old = ObjectUnderMouseCursor; ObjectUnderMouseCursor = o; if (ObjectUnderMouseCursorChanged != null) ObjectUnderMouseCursorChanged(this, new ObjectUnderMouseCursorChangedEventArgs(old, ObjectUnderMouseCursor)); }*/ }
public void SetSourcePortForEdgeRouting(MsaglPoint portLocation) { // I think this is to add the visual hint of the source port location. }
internal static PointF PointF(Point p) { return new PointF((float) p.X, (float) p.Y); }
void DrawDragWindow(MsaglPoint gp) { if (DragWindowStart == null) MainCanvas.Children.Remove(DragWindow); else { if (DragWindow == null) { var dc = new DoubleCollection(); dc.Add(1.0); dc.Add(1.0); DragWindow = new Path() { Stroke = BlackBrush, StrokeDashArray = dc }; Canvas.SetZIndex(DragWindow, 32000); } PathGeometry pg = new PathGeometry(); PathFigure pf = new PathFigure() { IsClosed = true }; pf.StartPoint = new WinPoint(DragWindowStart.Value.X, DragWindowStart.Value.Y); pf.Segments.Add(new System.Windows.Media.LineSegment() { Point = new WinPoint(DragWindowStart.Value.X, gp.Y) }); pf.Segments.Add(new System.Windows.Media.LineSegment() { Point = new WinPoint(gp.X, gp.Y) }); pf.Segments.Add(new System.Windows.Media.LineSegment() { Point = new WinPoint(gp.X, DragWindowStart.Value.Y) }); pg.Figures.Add(pf); DragWindow.Data = pg; if (!MainCanvas.Children.Contains(DragWindow)) MainCanvas.Children.Add(DragWindow); } }
void Form1_MouseDown(object sender, MsaglMouseEventArgs e) { /*if (e.RightButtonIsPressed && this.gViewer.DrawingLayoutEditor.SelectedEdge != null && this.gViewer.ObjectUnderMouseCursor == this.gViewer.DrawingLayoutEditor.SelectedEdge) ProcessRightClickOnSelectedEdge(e); else*/ if (e.RightButtonIsPressed && !e.Handled) { m_MouseRightButtonDownPoint = (gViewer).ScreenToSource(e); ContextMenu cm = BuildContextMenu(m_MouseRightButtonDownPoint); cm.Show(this, new System.Drawing.Point(e.X, e.Y)); } }
public void SetTargetPortForEdgeRouting(MsaglPoint portLocation) { // I think this is to add the visual hint of the target port location. }
private void CenterBoundingBox(MsaglPoint c) { MsaglPoint diff = Graph.GeometryGraph.BoundingBox.Center - c; MsaglPoint np = Graph.GeometryGraph.BoundingBox.Center; if (diff.X > 0.0) np.X = Graph.GeometryGraph.BoundingBox.Left - diff.X * 2.0; else if (diff.X < 0.0) np.X = Graph.GeometryGraph.BoundingBox.Right - diff.X * 2.0; if (diff.Y > 0.0) np.Y = Graph.GeometryGraph.BoundingBox.Bottom - diff.Y * 2.0; else if (diff.Y < 0.0) np.Y = Graph.GeometryGraph.BoundingBox.Top - diff.Y * 2.0; Graph.GeometryGraph.BoundingBox.Add(np); foreach (var el in Entities.Concat(m_CrossEdges)) { var go = (el as DObject).GeometryObject; if (go != null) go.BoundingBox.Add(np); } //var bb = Graph.GeometryGraph.BoundingBox; //bb.Add(np); //Graph.GeometryGraph.BoundingBox = bb; UpdateWidthAndHeight(); }
public DNode AddNodeAtLocation(MsaglPoint p, string id, bool registerForUndo) { DrawingNode node = new DrawingNode(id == null ? GetNewNodeID() : id); node.Attr.Shape = Drawing.Shape.Ellipse; GeometryNode geometryNode = new GeometryNode() { GeometryParent = Graph.GeometryGraph }; // NEWMSAGL: geometry nodes no longer have an id? node.GeometryNode = geometryNode; geometryNode.UserData = node; DNode dNode = CreateNode(node) as DNode; geometryNode.Center = p; AddNode(dNode, registerForUndo); if (registerForUndo) { DrawingLayoutEditor.RegisterNodeAdditionForUndo(dNode); var bounds = Graph.GeometryGraph.BoundingBox; bounds.Add(node.BoundingBox.LeftTop); bounds.Add(node.BoundingBox.RightBottom); Graph.GeometryGraph.BoundingBox = bounds; DrawingLayoutEditor.CurrentUndoAction.GraphBoundingBoxAfter = Graph.BoundingBox; } if (UpdateGraphBoundingBoxPreservingCenter()) Invalidate(); if (MouseMode == DraggingMode.EdgeInsertion) { DrawingLayoutEditor.ForgetEdgeDragging(); DrawingLayoutEditor.PrepareForEdgeDragging(); } return dNode; }