void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.canvas1 = ((System.Windows.Controls.Canvas)(target)); return; case 2: this.bezierSegment = ((System.Windows.Media.BezierSegment)(target)); return; case 3: this.path1 = ((System.Windows.Shapes.Path)(target)); return; case 4: this.line1 = ((System.Windows.Media.LineGeometry)(target)); return; case 5: this.ellipse1 = ((System.Windows.Media.EllipseGeometry)(target)); return; case 6: this.line2 = ((System.Windows.Media.LineGeometry)(target)); return; case 7: this.ellipse2 = ((System.Windows.Media.EllipseGeometry)(target)); return; } this._contentLoaded = true; }
public void Defaults () { LineGeometry lg = new LineGeometry (); Assert.AreEqual (new Point (0, 0), lg.StartPoint, "StartPoint"); Assert.AreEqual (new Point (0, 0), lg.EndPoint, "EndPoint"); GeometryTest.CheckDefaults (lg); }
public FleetRender( Fleet fleet, bool? lines ) { LineGeometry line; FormattedText text; Geometry textGeom; double x = fleet.SourcePlanet.X + ((fleet.DestinationPlanet.X - fleet.SourcePlanet.X) * ((double)(fleet.TotalTripLength - fleet.TurnsRemaining) / fleet.TotalTripLength)); double y = fleet.SourcePlanet.Y + ((fleet.DestinationPlanet.Y - fleet.SourcePlanet.Y) * ((double)(fleet.TotalTripLength - fleet.TurnsRemaining) / fleet.TotalTripLength)); if (lines ?? false) { line = new LineGeometry(new Point(x, y), new Point(fleet.DestinationPlanet.X, fleet.DestinationPlanet.Y)); m_gg.Children.Add(line); } text = new FormattedText( fleet.ShipCount.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Tahoma"), 0.8, Brushes.Black); textGeom = text.BuildGeometry(new Point(x - text.Width / 2, y - text.Height / 2)); m_gg.Children.Add(textGeom); m_gg.Freeze(); }
//if pencil is selected and brush color is not null (it is not null all the time since before performing //mouseMove we perform mouseDown where we predefine brushColor attribute to colorPicker public void MouseMove(Point newPosition, Canvas canvas1) { if (selected && brushColor!=null) { //Approach 2 //tried to make it this way because once the thickness of line increases it doesn't look good. //instead of being connected lines looks like |||||| especially on turns. //so far this approach doesn't solve the problem. Path linePath = new Path(); linePath.Stroke = new SolidColorBrush(brushColor); linePath.StrokeThickness = brushThickness; linePath.Fill = new SolidColorBrush(brushColor); LineGeometry line = new LineGeometry(); line.StartPoint = new Point(currentPoint.X, currentPoint.Y); line.EndPoint = new Point(newPosition.X, newPosition.Y); linePath.Data = line; //original approach 1 //line.Stroke = new SolidColorBrush(brushColor); ////manipulate lines thickness //line.StrokeThickness = brushThickness; //line.X1 = currentPoint.X; //line.Y1 = currentPoint.Y; //line.X2 = newPosition.X; //line.Y2 = newPosition.Y; //line.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased); canvas1.Children.Add(linePath); currentPoint = newPosition; } }
private void repaintIntervalGroup(ComboBox combo) { PostureType newPostureType = (PostureType)combo.SelectedItem; var visiblePosture = visiblePostures.Find(v => v.Item2 == combo); PostureType oldPostureType = visiblePosture.Item1; RowDefinition rowDef = visiblePosture.Item3; // CLEAR ROW OF INTERVAL GROUP int rowDefIndex = postureGroupsGrid.RowDefinitions.IndexOf(rowDef); //foreach (UIElement path in postureGroupsGrid.Children) for (int i = postureGroupsGrid.Children.Count - 1; i >= 0; i--) { if (Grid.GetRow(postureGroupsGrid.Children[i]) == rowDefIndex) { postureGroupsGrid.Children.RemoveAt(i); } } int visiblePostureIndex = visiblePostures.IndexOf(visiblePosture); visiblePostures.Remove(visiblePosture); visiblePostures.Insert(visiblePostureIndex, new Tuple <PostureType, ComboBox, RowDefinition> (newPostureType, combo, rowDef) ); PostureIntervalGroup postureIntervalGroup = Person.PostureIntervalGroups .FirstOrDefault (g => g.PostureType == newPostureType); if (postureIntervalGroup != null) { //StackPanel pathStackPanel = new StackPanel(); foreach (var interval in postureIntervalGroup.Intervals) { Console.WriteLine("\t[" + interval.StartTime.ToString(@"mm\:ss") + ", " + interval.EndTime.ToString(@"mm\:ss") + "]"); int intervalIniCol = Convert.ToInt32(interval.StartTime.TotalSeconds); int intervalFinCol = Convert.ToInt32(interval.EndTime.TotalSeconds); System.Windows.Shapes.Path path = new System.Windows.Shapes.Path(); path.Stroke = Person.Color;//System.Windows.Media.Brushes.Red; //person.Color; // postureIntervalGroup.postureType.color; // path.StrokeThickness = 10; path.Stretch = System.Windows.Media.Stretch.Fill; Grid.SetRow(path, rowDefIndex); int iniCol = (intervalIniCol - 1) >= 0 ? (intervalIniCol - 1) : 0; Grid.SetColumn(path, iniCol); Grid.SetColumnSpan(path, intervalFinCol - intervalIniCol + 2); System.Windows.Media.LineGeometry line = new System.Windows.Media.LineGeometry(); line.StartPoint = new System.Windows.Point(0d, 0d); line.EndPoint = new System.Windows.Point(1d, 0d); path.Data = line; //postureGroupsGrid. postureGroupsGrid.Children.Add(path); } } }
//draws a line at a relative angle compared to the origin line. public static WPFMEDIA.LineGeometry AngularLine(WPF.Point StartPoint, WPF.Point EndPoint, double Length, double RelativeAngle) { //Get Current Angle Don't need the actual angle, radians is fine. double angle = CurrentAngle(StartPoint, EndPoint); double radians = Math.Atan2(StartPoint.Y - EndPoint.Y, StartPoint.X - EndPoint.X); //Take 90 deg double newAngle = angle + RelativeAngle; //double newRadians = radians + Math.PI / 2; double shiftX = Length * Math.Cos(newAngle * Math.PI / 180); double shiftY = Length * Math.Sin(newAngle * Math.PI / 180); double newEndPointX = StartPoint.X - shiftX; double newEndPointY = StartPoint.Y - shiftY; WPF.Point newEndPoint = new WPF.Point(newEndPointX, newEndPointY); //get the second point //draw line from center of the point. WPFMEDIA.LineGeometry newLine = new System.Windows.Media.LineGeometry(StartPoint, newEndPoint); return newLine; }
public ConnectorView() { linegeo = new LineGeometry(); this.Stroke = Brushes.Black; this.StrokeThickness = 2; }
public void CustomPoints () { LineGeometry lg = new LineGeometry (); lg.StartPoint = new Point (1, 2); lg.EndPoint = new Point (3, 4); Assert.AreEqual (new Rect (1, 2, 2, 2), lg.Bounds, "Bounds"); Assert.IsNull (lg.Transform, "Transform"); }
public void AddLine(double startX, double startY, double endX, double endY, double thickness = 1) { LineGeometry lineGeometry = new LineGeometry(); lineGeometry.StartPoint = new System.Windows.Point(startX, startY); lineGeometry.EndPoint = new System.Windows.Point(endX, endY); Path path = new Path(); path.Stroke = System.Windows.Media.Brushes.Black; path.StrokeThickness = thickness; path.Data = lineGeometry; canvas.Children.Add(path); }
// This method establishes a link between current thumb and target thumb using a predefined line geometry // Note: this is commonly to be used for drawing links with mouse when the line object is predefined outside this class public bool LinkTo(PinButton target, LineGeometry line) { // Save as starting line for current thumb this.StartLines.Add(line); // Save as ending line for target thumb target.EndLines.Add(line); // Ensure both tumbs the latest layout this.UpdateLayout(); target.UpdateLayout(); // Update line position line.StartPoint = new Point(Canvas.GetLeft(this) + this.ActualWidth / 2, Canvas.GetTop(this) + this.ActualHeight / 2); line.EndPoint = new Point(Canvas.GetLeft(target) + target.ActualWidth / 2, Canvas.GetTop(target) + target.ActualHeight / 2); return true; }
private static void DrawLine(Canvas canvas, double startX, double startY, double endX, double endY, Color colour) { SolidColorBrush brush = new SolidColorBrush(); brush.Color = colour; Path path = new Path(); path.Stroke = brush; path.StrokeThickness = 1; LineGeometry line = new LineGeometry(); line.StartPoint = new System.Windows.Point(startX, startY); line.EndPoint = new System.Windows.Point(endX, endY); path.Data = line; canvas.Children.Add(path); }
private void DrawVerticalLines(Point leftTop, Point rightBottom, double step, Path path) { double x = leftTop.X; var geometryGroup = new GeometryGroup(); while (x <= rightBottom.X) { var geom = new LineGeometry(new Point(x, leftTop.Y), new Point(x, rightBottom.Y)); geometryGroup.Children.Add(geom); x += step; } if (path.Data != null) geometryGroup.Children.Add(path.Data); path.Data = geometryGroup; }
private void DrawHorisontalLines(Point leftTop, Point rightBottom, double step, Path path) { double y = leftTop.Y; var geometryGroup = new GeometryGroup(); while (y <= rightBottom.Y) { var geom = new LineGeometry(new Point(leftTop.X, rightBottom.Y - y), new Point(rightBottom.X, rightBottom.Y - y)); geometryGroup.Children.Add(geom); y += step; } if (path.Data != null) geometryGroup.Children.Add(path.Data); path.Data = geometryGroup; }
// This method establishes a link between current thumb and specified thumb. // Returns a line geometry with updated positions to be processed outside. public LineGeometry LinkTo(PinButton target) { // Create new line geometry LineGeometry line = new LineGeometry(); // Save as starting line for current thumb this.StartLines.Add(line); // Save as ending line for target thumb target.EndLines.Add(line); // Ensure both tumbs the latest layout this.UpdateLayout(); target.UpdateLayout(); // Update line position line.StartPoint = new Point(Canvas.GetLeft(this) + this.ActualWidth / 2, ((double.IsNaN(Canvas.GetTop(this))) ? 0 : Canvas.GetTop(this)) + (this.ActualHeight-20)); line.EndPoint = new Point(Canvas.GetLeft(target) + target.ActualWidth / 2, ((double.IsNaN(Canvas.GetTop(target))) ? 0 : Canvas.GetTop(target)) + (target.ActualHeight-20)); // return line for further processing return line; }
public override void MouseMove(Circuit.Coord At) { if (mouse == null) return; mouse.Add(At); List<Circuit.Coord> points = Editor.FindWirePath(mouse); ((PathGeometry)path.Data).Clear(); for (int i = 0; i < points.Count - 1; ++i) { LineGeometry line = new LineGeometry() { StartPoint = Target.ToPoint(points[i]) + new Vector(0.5, -0.5), EndPoint = Target.ToPoint(points[i + 1]) + new Vector(0.5, -0.5) }; ((PathGeometry)path.Data).AddGeometry(line); } }
public static UIElement GetItemContainerAt(this ItemsControl itemsControl, Point position, Orientation searchDirection) { Type itemContainerType = GetItemContainerType(itemsControl); if (itemContainerType != null) { Geometry hitTestGeometry; if (typeof(TreeViewItem).IsAssignableFrom(itemContainerType)) { hitTestGeometry = new LineGeometry(new Point(0, position.Y), new Point(itemsControl.RenderSize.Width, position.Y)); } else { switch (searchDirection) { case Orientation.Horizontal: hitTestGeometry = new LineGeometry(new Point(0, position.Y), new Point(itemsControl.RenderSize.Width, position.Y)); break; case Orientation.Vertical: hitTestGeometry = new LineGeometry(new Point(position.X, 0), new Point(position.X, itemsControl.RenderSize.Height)); break; default: throw new ArgumentException("Invalid value for searchDirection"); } } List<DependencyObject> hits = new List<DependencyObject>(); VisualTreeHelper.HitTest(itemsControl, null, result => { DependencyObject itemContainer = result.VisualHit.GetVisualAncestor(itemContainerType); if (itemContainer != null && !hits.Contains(itemContainer) && ((UIElement)itemContainer).IsVisible == true) hits.Add(itemContainer); return HitTestResultBehavior.Continue; }, new GeometryHitTestParameters(hitTestGeometry)); return GetClosest(itemsControl, hits, position, searchDirection); } return null; }
public void DrawWave(Path form) { var w = (int)form.ActualWidth; var h = (int)form.ActualHeight; var columns = GetColumns(w, h); var group = new System.Windows.Media.GeometryGroup(); var mid = h / 2; for (var i = 0; i < columns.Length; i++) { var start = new Point(i, mid - columns[i] / 2); var end = new Point(i, mid + columns[i] / 2); var line = new System.Windows.Media.LineGeometry(start, end); group.Children.Add(line); } form.Data = group; }
private void CreateDeloneCirclesGeometric() { (gDeloneCircles as GeometryGroup).Children.Clear(); Triple<Circle, DeloneCircle> triple = vd.NextTriple(vd.NullTriple); while (triple != vd.NullTriple) { if (!double.IsInfinity(triple.Delone_Circle.R)) { EllipseGeometry ellipse = new EllipseGeometry(new System.Windows.Point(triple.Delone_Circle.X, triple.Delone_Circle.Y), triple.Delone_Circle.R, triple.Delone_Circle.R); (gDeloneCircles as GeometryGroup).Children.Add(ellipse); } else { LineGeometry line = new LineGeometry(new System.Windows.Point(triple.Delone_Circle.X - 1000 * triple.Delone_Circle.VX, triple.Delone_Circle.Y - 1000 * triple.Delone_Circle.VY), new System.Windows.Point(triple.Delone_Circle.X + 1000 * triple.Delone_Circle.VX, triple.Delone_Circle.Y + 1000 * triple.Delone_Circle.VY)); (gDeloneCircles as GeometryGroup).Children.Add(line); } triple = vd.NextTriple(triple); } }
public Path CreateLineForMinSpanningTreeEdge(DelaunayEdge edge) { if (this.minimumSpanningTreePaths == null) { this.minimumSpanningTreePaths = new Dictionary<DelaunayEdge, Path>(); } if (!this.minimumSpanningTreePaths.ContainsKey(edge)) { LineGeometry geometry = new LineGeometry(new Point(edge.Start.X, edge.Start.Y), new Point(edge.End.X, edge.End.Y)); geometry.Freeze(); Path path = new Path(); path.Data = geometry; path.StrokeThickness = MinimumSpanningTreeTickness; path.Stroke = new SolidColorBrush(Color.FromArgb(120, minimumSpanningTreeEdgeColor.A, minimumSpanningTreeEdgeColor.G, minimumSpanningTreeEdgeColor.B)); this.minimumSpanningTreePaths[edge] = path; } return this.minimumSpanningTreePaths[edge]; }
/// <summary> /// see http://stackoverflow.com/questions/5188877/how-to-have-arrow-symbol-on-a-line-in-c-wpf /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="fillBrush"></param> /// <param name="thickness"></param> /// <returns></returns> public static Shape DrawLinkArrow(Point p1, Point p2, Brush fillBrush, double thickness = 3.0d) { GeometryGroup lineGroup = new GeometryGroup(); double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI; PathGeometry pathGeometry = new PathGeometry(); PathFigure pathFigure = new PathFigure(); Point p = new Point(p1.X + ((p2.X - p1.X) / 1.35), p1.Y + ((p2.Y - p1.Y) / 1.35)); pathFigure.StartPoint = p; Point lpoint = new Point(p.X + 6, p.Y + 15); Point rpoint = new Point(p.X - 6, p.Y + 15); LineSegment seg1 = new LineSegment(); seg1.Point = lpoint; pathFigure.Segments.Add(seg1); LineSegment seg2 = new LineSegment(); seg2.Point = rpoint; pathFigure.Segments.Add(seg2); LineSegment seg3 = new LineSegment(); seg3.Point = p; pathFigure.Segments.Add(seg3); pathGeometry.Figures.Add(pathFigure); RotateTransform transform = new RotateTransform(); transform.Angle = theta + 90; transform.CenterX = p.X; transform.CenterY = p.Y; pathGeometry.Transform = transform; lineGroup.Children.Add(pathGeometry); LineGeometry connectorGeometry = new LineGeometry(); connectorGeometry.StartPoint = p1; connectorGeometry.EndPoint = p2; lineGroup.Children.Add(connectorGeometry); System.Windows.Shapes.Path path = new System.Windows.Shapes.Path(); path.Data = lineGroup; path.StrokeThickness = thickness; path.Stroke = path.Fill = fillBrush; return path; }
public Path CreateEdgeLine(DelaunayEdge edge) { if (this.edgesPaths == null) { this.edgesPaths = new Dictionary<DelaunayEdge, Path>(); } if (!this.edgesPaths.ContainsKey(edge)) { LineGeometry geometry = new LineGeometry(new Point(edge.Start.X, edge.Start.Y), new Point(edge.End.X, edge.End.Y)); geometry.Freeze(); Path path = new Path(); path.Data = geometry; path.StrokeThickness = EdgeTickness; path.Stroke = new SolidColorBrush(EdgeColor); this.edgesPaths[edge] = path; } return this.edgesPaths[edge]; }
/// <summary> /// Draw multiple geometry at one time. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DrawPath_Clicked(object sender, RoutedEventArgs e) { // Create a path Path path = new Path(); path.Stroke = new SolidColorBrush(Colors.BlueViolet); path.StrokeThickness = 3; // Create a line geometry LineGeometry blackLineGeometry = new LineGeometry(); blackLineGeometry.StartPoint = new Point(20, 200); blackLineGeometry.EndPoint = new Point(300, 200); // Create an ellipse geometry EllipseGeometry blackEllipseGeometry = new EllipseGeometry(); blackEllipseGeometry.Center = new Point(80, 150); blackEllipseGeometry.RadiusX = 50; blackEllipseGeometry.RadiusY = 50; // Create a rectangle geometry RectangleGeometry blackRectGeometry = new RectangleGeometry(); Rect rct = new Rect(); rct.X = 80; rct.Y = 167; rct.Width = 150; rct.Height = 30; blackRectGeometry.Rect = rct; // Add all the geometries to a GeometryGroup. GeometryGroup blueGeometryGroup = new GeometryGroup(); blueGeometryGroup.Children.Add(blackLineGeometry); blueGeometryGroup.Children.Add(blackEllipseGeometry); blueGeometryGroup.Children.Add(blackRectGeometry); // Set Path.Data path.Data = blueGeometryGroup; //Add drag drop behavior. path.SetValue(DragDropBehavior.PlacementTarget, this.DrawCanvas); Canvas.SetLeft(path, 0); Canvas.SetTop(path, 0); this.DrawCanvas.Children.Add(path); }
//if eraser is selected and brush color is not null (it is not null all the time since before performing //mouseMove we perform mouseDown where we predefine brushColor attribute to colorPicker public void MouseMove(Point newPosition, Canvas canvas1) { if (selected && brushColor != null) { Path linePath = new Path(); linePath.Stroke = new SolidColorBrush(brushColor); linePath.StrokeThickness = brushThickness; linePath.Fill = new SolidColorBrush(brushColor); LineGeometry line = new LineGeometry(); line.StartPoint = new Point(currentPoint.X, currentPoint.Y); line.EndPoint = new Point(newPosition.X, newPosition.Y); linePath.Data = line; canvas1.Children.Add(linePath); currentPoint = newPosition; } }
public static UIElement GetItemContainerAt(this ItemsControl itemsControl, Point position, Orientation searchDirection) { var itemContainerType = GetItemContainerType(itemsControl); if (itemContainerType != null) { LineGeometry line; switch (searchDirection) { case Orientation.Horizontal: line = new LineGeometry(new Point(0, position.Y), new Point(itemsControl.RenderSize.Width, position.Y)); break; case Orientation.Vertical: line = new LineGeometry(new Point(position.X, 0), new Point(position.X, itemsControl.RenderSize.Height)); break; default: throw new ArgumentException("Invalid value for searchDirection"); } var hits = new List<DependencyObject>(); VisualTreeHelper.HitTest(itemsControl, null, result => { var itemContainer = result.VisualHit.GetVisualAncestor(itemContainerType); if (itemContainer != null) { hits.Add(itemContainer); } return HitTestResultBehavior.Continue; }, new GeometryHitTestParameters(line)); return GetClosest(itemsControl, hits, position, searchDirection); } return null; }
protected override void OnRefresh() { LineDecoration lineDecoration = Visual as LineDecoration; if (lineDecoration != null) { _pathPen = new Pen(new SolidColorBrush(lineDecoration.LineColor), lineDecoration.Thickness); _path = new PathGeometry(); Point startPoint = new Point(lineDecoration.Start.X - lineDecoration.Left, lineDecoration.Start.Y - lineDecoration.Top); Point endPoint = new Point(lineDecoration.End.X - lineDecoration.Left, lineDecoration.End.Y - lineDecoration.Top); if (lineDecoration.Curve) { // Create a vector representing the direction of the line Vector v1 = lineDecoration.End - lineDecoration.Start; double length = v1.Length; // Normalize so it can be used to construct control points v1.Normalize(); // Create a matrix to rotate arm perpendicular Matrix m1 = new Matrix(); m1.Rotate(-90); Point curvePoint1 = (startPoint + (v1 * (length * lineDecoration.CurveStart))) + ((v1 * (length * lineDecoration.CurveDepth)) * m1); Point curvePoint2 = (endPoint - (v1 * (length * lineDecoration.CurveStart))) + ((v1 * (length * lineDecoration.CurveDepth)) * m1); //_path.Figures.Add(QuadraticBezierFromIntersection(startPoint, curvePoint1, endPoint)); _path.Figures.Add(BezierFromIntersection(startPoint,curvePoint1,curvePoint2,endPoint)); } else { LineGeometry line = new LineGeometry(startPoint, endPoint); _path.AddGeometry(line); } } }
public TileUC() { this.InitializeComponent(); brush = new SolidColorBrush(Colors.Green); var c = 32; for (int i = 0; i < c; i++) { var f = Dim / c; var p = f * i; { var geo = new LineGeometry() { StartPoint = new Point(0, p), EndPoint = new Point(Dim - p, Dim) }; var item = new Path(); item.Data = geo; item.Stroke = brush; item.StrokeThickness = .5; item.StrokeEndLineCap = PenLineCap.Square; this.Content.Children.Add(item); } if (i == 0) continue; { var geo = new LineGeometry() { StartPoint = new Point(p, 0), EndPoint = new Point(Dim, Dim - p) }; var item = new Path(); item.Data = geo; item.Stroke = brush; item.StrokeThickness = .5; item.StrokeEndLineCap = PenLineCap.Square; this.Content.Children.Add(item); } } }
void CreateVisuals(ITextViewLine line) { var text = view.TextSnapshot.GetText(line.Start, line.Length); if (hasUsing == false) UpdateUsing(text); var regex = hasUsing == true ? usingColorRegex : colorRegex; var matches = regex.Matches(text); foreach (Match match in matches) { var mode = match.Groups["mode"].Value; Func<Match, Eto.Drawing.Color> translateColor; if (!colorMatching.TryGetValue(mode, out translateColor)) continue; var color = translateColor(match).ToWpf(); if (color.A <= 0) continue; var span = new SnapshotSpan(view.TextSnapshot, line.Start + match.Index, match.Length); var geometry = view.TextViewLines.GetMarkerGeometry(span); if (geometry == null || !view.TextViewModel.IsPointInVisualBuffer(span.Start, PositionAffinity.Successor) || !view.TextViewModel.IsPointInVisualBuffer(span.End, PositionAffinity.Predecessor)) continue; var pen = GetPen(color); var bounds = geometry.Bounds; var underline = new LineGeometry(bounds.BottomLeft, bounds.BottomRight); underline.Freeze(); var drawing = new GeometryDrawing(null, pen, underline); drawing.Freeze(); var drawingImage = new DrawingImage(drawing); drawingImage.Freeze(); var image = new Image(); image.Source = drawingImage; Canvas.SetLeft(image, geometry.Bounds.Left); Canvas.SetTop(image, geometry.Bounds.Bottom - 2); layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null); } }
//Can be more complex later. public static WPFMEDIA.LineGeometry Line(WPF.Point StartPoint, WPF.Point EndPoint) { WPFMEDIA.LineGeometry newLine = new System.Windows.Media.LineGeometry(StartPoint, EndPoint); return newLine; }
TreeViewItem ProcessPlacemark(Placemark placemark) { string name = placemark.Name; StackPanel pan = new StackPanel(); pan.Orientation = System.Windows.Controls.Orientation.Horizontal; Style style = FindStyleByStyleURL(placemark.StyleUrl.OriginalString); if (placemark.Geometry is Point) { Uri uri = null; if (style != null && style.Icon != null && style.Icon.Icon != null && style.Icon.Icon.Href != null) { uri = style.Icon.Icon.Href; } Image image = new Image(); image.Height = 16; image.Source = FindImageByUri(uri); pan.Children.Add(image); } else if (placemark.Geometry is LineString) { GeometryGroup Lines = new GeometryGroup(); Color32 styleColor = new Color32(); if (style != null && style.Line != null && style.Line.Color != null) { styleColor = (Color32)style.Line.Color; } // Line LineGeometry line = new LineGeometry(); line.StartPoint = new System.Windows.Point(0, 5); line.EndPoint = new System.Windows.Point(10, 5); Lines.Children.Add(line); GeometryDrawing MyGeometryDrawing = new GeometryDrawing(); MyGeometryDrawing.Geometry = Lines; MyGeometryDrawing.Brush = new SolidColorBrush(Color.FromArgb(styleColor.Alpha, styleColor.Red, styleColor.Green, styleColor.Blue)); MyGeometryDrawing.Pen = new Pen(MyGeometryDrawing.Brush, 1); DrawingImage drawingImage = new DrawingImage(MyGeometryDrawing); drawingImage.Freeze(); Image image = new Image(); image.Height = 16; image.Width = 16; image.Source = drawingImage; pan.Children.Add(image); } TextBlock textBlock = new TextBlock(); textBlock.Text = name; textBlock.Margin = new System.Windows.Thickness(4, 0, 0, 0); pan.Children.Add(textBlock); KMLFeatureTreeViewItem item = new KMLFeatureTreeViewItem() { Header = pan, Feature = placemark }; return item; }
private void SetTrend(ref System.Windows.Shapes.Path Trend_p, int x_point_count, double[] y_point, double ticknes, Color ColorLine, double max, double min) { double xAxisDelen = 0.0; double yAxisDelen = 0.0; if (max != 0.0 || max - min != 0.0) { yAxisDelen = rchPane.Height / (max - min); } else { yAxisDelen = rchPane.Height; } if (x_point_count <= xLineCount) { if (rchPane.Width != 0) { xAxisDelen = rchPane.Width / (xLineCount + 2); } } else { if (rchPane.Width != 0) { xAxisDelen = rchPane.Width / (x_point_count - 1); } } //Trend_p.Name = name; SolidColorBrush mySolidColorBrush = new SolidColorBrush(); Trend_p.StrokeDashCap = PenLineCap.Round; Trend_p.StrokeEndLineCap = PenLineCap.Round; Trend_p.StrokeStartLineCap = PenLineCap.Round; Trend_p.StrokeLineJoin = PenLineJoin.Round; Trend_p.Stroke = new SolidColorBrush(ColorLine); Trend_p.StrokeThickness = ticknes; mySolidColorBrush = new SolidColorBrush(); mySolidColorBrush.Color = ColorLine; Trend_p.Fill = mySolidColorBrush; GeometryGroup myGeometryGroup = new GeometryGroup(); double y_value = 0.0; double y_value1 = 0.0; for (int i = 1; i < x_point_count; i++) { y_value = y_point[i - 1] < min ? 0.0 : y_point[i - 1] - min; if (y_value > max - min) { y_value = max - min; } y_value1 = y_point[i] < min ? 0.0 : y_point[i] - min; if (y_value1 > max - min) { y_value1 = max - min; } LineGeometry myLineGeometry = new LineGeometry(); myLineGeometry.StartPoint = new Point(yAxisM + (rchPane.Width - (i - 1) * xAxisDelen), topMarning + rchPane.Height - y_value * yAxisDelen); myLineGeometry.EndPoint = new Point(yAxisM + (rchPane.Width - i * xAxisDelen), topMarning + rchPane.Height - y_value1 * yAxisDelen); myGeometryGroup.Children.Add(myLineGeometry); } Trend_p.Data = myGeometryGroup; }
private void SetCanvas() { double xAxisDelen = 0.0; double yAxisDelen = 0.0; int xLineC = 0; int yLineC = 0; yAxisM = this.Height * 0.1; xAxisM = this.Width * 0.02; yLineC = yLineCount - 2; xLineC = xLineCount - 2; double wC = this.Width; double hC = (this.Height - botControl.Height)*0.95; //(botControl.Height == 150.0 ? this.Height - 0.50 * this.Height : this.Height - 0.55 * this.Height); chPane.Height = hC; chPane.Width = wC; rchPane = new Rectangle(); r_sl = new r_slider(); rchPane.StrokeThickness = 2.0; rchPane.Stroke = new SolidColorBrush(colorPaneChart); chPane.Children.Add(rchPane); rchPane.Height = chPane.Height - (chPane.Height * 0.02 + xAxisAfterLine + xAxisM); r_sl.Height = rchPane.Height + 0.0574 * rchPane.Height; r_sl.Width = chPane.Width * 0.3056; rchPane.Width = chPane.Width - yAxisM*1.5; rchPane.SetValue(Canvas.LeftProperty, yAxisM); rchPane.SetValue(Canvas.TopProperty, topMarning); r_sl.SetValue(Canvas.TopProperty, topMarning +rchPane.Height/2 - r_sl.Height/2); r_sl.SetValue(Canvas.LeftProperty, yAxisM + rchPane.Width - r_sl.Width + r_sl.Width * 0.06377 + 2.0); r_sl.SetValue(Canvas.ZIndexProperty, 15); r_sl.Value = 0.0; r_sl.ChangeValue += new r_slider.ChangeValueDelegat(r_sl_ChangeValue); chPane.Children.Add(r_sl); if (rchPane.Height != 0) { yAxisDelen = rchPane.Height / (yLineC + 1.0); } if (rchPane.Width != 0) { xAxisDelen = rchPane.Width / (xLineC + 1.0); } System.Windows.Shapes.Path xAxistPath = new System.Windows.Shapes.Path(); xAxistPath.Stroke = new SolidColorBrush(colorPaneChart); xAxistPath.StrokeThickness = 0.3; SolidColorBrush mySolidColorBrush = new SolidColorBrush(); mySolidColorBrush.Color = colorPaneChart; xAxistPath.Fill = mySolidColorBrush; GeometryGroup myGeometryGroup = new GeometryGroup(); // bool flg = false; for (int i = 0; i < xLineC; i++) { LineGeometry myLineGeometry = new LineGeometry(); myLineGeometry.StartPoint = new Point(yAxisM + (i + 1) * xAxisDelen, topMarning); // if (flg) // { // myLineGeometry.EndPoint = new Point(yAxisM + (i + 1) * xAxisDelen, rchPane.Height + xAxisAfterLine); // flg = false; // } // else // { myLineGeometry.EndPoint = new Point(yAxisM + (i + 1) * xAxisDelen, rchPane.Height + 2.0 * xAxisAfterLine); // flg = true; // } myGeometryGroup.Children.Add(myLineGeometry); } xAxistPath.Data = myGeometryGroup; chPane.Children.Add(xAxistPath); System.Windows.Shapes.Path yAxistPath = new System.Windows.Shapes.Path(); yAxistPath.Stroke = new SolidColorBrush(colorPaneChart); yAxistPath.StrokeThickness = 0.3; mySolidColorBrush = new SolidColorBrush(); mySolidColorBrush.Color = colorPaneChart; yAxistPath.Fill = mySolidColorBrush; myGeometryGroup = new GeometryGroup(); for (int i = 0; i < yLineC; i++) { LineGeometry myLineGeometry = new LineGeometry(); myLineGeometry.StartPoint = new Point(yAxisM - yAxistAfterLine, topMarning + (i + 1) * yAxisDelen); myLineGeometry.EndPoint = new Point(yAxisM + rchPane.Width, topMarning + (i + 1) * yAxisDelen); myGeometryGroup.Children.Add(myLineGeometry); } yAxistPath.Data = myGeometryGroup; chPane.Children.Add(yAxistPath); }
public void drawYGrid(double maxVal) { double d = Math.Abs(maxVal); if (d == 0D) d = 1D; int n = 0; while (d > 10D || d < 1D) { if (d > 10D) { d /= 10D; n++; } else { d *= 10D; n--; } } int m = (int)Math.Ceiling(d) - 1; double exp = Math.Pow(10D, n); double m0 = gridYMax[m] * exp; double inc = gridYInc[m] * exp; graphletYScale = gp.ScaleY / m0; if (mg.typeAxis == AxisType.PosNeg) graphletYScale /= 2D; else { inc /= 2D; if (mg.typeAxis == AxisType.Neg) graphletYScale = -graphletYScale; } if (graphletYScale != oldGraphletYScale) { GeometryGroup gg = new GeometryGroup(); yAxisLabels.Children.Clear(); for (double y = inc; y <= m0; y += inc) { LineGeometry l = new LineGeometry( new Point(0D, -y * graphletYScale), new Point(mg.size1X, -y * graphletYScale)); gg.Children.Add(l); string s = y.ToString("G4"); TextBlock tb = new TextBlock(new Run(s)); tb.Foreground = Brushes.Gray; tb.Width = gp.marginSize; tb.TextAlignment = TextAlignment.Center; tb.FontSize = 10D; if (s.Length > 4) { tb.FontSize = 6D; tb.FontStretch = FontStretches.UltraCondensed; } Canvas.SetBottom(tb, (mg.typeAxis == AxisType.PosNeg ? offset : 0D) + y * graphletYScale - tb.FontSize / 2); Canvas.SetRight(tb, 0D); yAxisLabels.Children.Add(tb); if (mg.typeAxis == AxisType.PosNeg) { LineGeometry l1 = new LineGeometry( new Point(0D, y * graphletYScale), new Point(mg.size1X, y * graphletYScale)); gg.Children.Add(l1); s = (-y).ToString("G4"); TextBlock tb1 = new TextBlock(new Run(s)); tb1.Foreground = Brushes.Gray; tb1.Width = gp.marginSize; tb1.TextAlignment = TextAlignment.Center; tb1.FontSize = 10D; if (s.Length > 4) { tb1.FontSize = 6D; tb1.FontStretch = FontStretches.UltraCondensed; } Canvas.SetBottom(tb1, offset - y * graphletYScale - tb.FontSize / 2); Canvas.SetRight(tb1, 0D); yAxisLabels.Children.Add(tb1); } } yAxisGrid.Data = gg; } }
public void drawXGrid() { double range = mg.xMax - mg.xMin; double inc; if (range > 20D) { int m = (int)Math.Truncate(range + 0.5); if (((m >> 3) << 3) == m) inc = (double)(m >> 3); else if (((m >> 2) << 2) == m) inc = (double)(m >> 2); else if (((m >> 1) << 1) == m) inc = (double)(m >> 1); else inc = (double)range / 4D; } else if (range < 1D) { double d = range; if (d == 0D) d = 1D; int n = 0; while (d < 1D) { d *= 10D; n--; } int m = (int)Math.Ceiling(d) - 1; double exp = Math.Pow(10D, n); inc = gridXInc[m] * exp; } else inc = gridXInc[(int)range - 1]; double scale = mg.ScaleX / range; graphletXScale = scale * mg.finalXScale * (double)mg._decimation; if (graphletXScale != oldGraphletXScale) //need to redraw X axis and grid { GeometryGroup gg = new GeometryGroup(); xAxisLabels.Children.Clear(); for (double x = 0D; x <= range; x += inc) { if (x != 0D) //don't need to draw first one -- it's the axis { LineGeometry l = new LineGeometry( new Point(x * scale, 0D), new Point(x * scale, gp.size1Y)); gg.Children.Add(l); } TextBlock tb = new TextBlock(new Run((x + mg.xMin).ToString("G6"))); tb.Foreground = Brushes.Gray; tb.Width = gp.marginSize; tb.TextAlignment = TextAlignment.Center; tb.FontSize = 10D; Canvas.SetBottom(tb, -gp.marginSize); tb.Padding = new Thickness(0D, 0D, 0D, 2D); Canvas.SetLeft(tb, x * scale + gp.halfMargin); xAxisLabels.Children.Add(tb); } xAxisGrid.Data = gg; } }
public static WMedia.Geometry ToWindows(this Geometry geometry) { WMedia.Geometry wGeometry = null; if (geometry is LineGeometry) { LineGeometry lineGeometry = geometry as LineGeometry; wGeometry = new WMedia.LineGeometry { StartPoint = lineGeometry.StartPoint.ToWindows(), EndPoint = lineGeometry.EndPoint.ToWindows() }; } else if (geometry is RectangleGeometry) { var rect = (geometry as RectangleGeometry).Rect; wGeometry = new WMedia.RectangleGeometry { Rect = new WFoundation.Rect(rect.X, rect.Y, rect.Width, rect.Height) }; } else if (geometry is EllipseGeometry) { EllipseGeometry ellipseGeometry = geometry as EllipseGeometry; wGeometry = new WMedia.EllipseGeometry { Center = ellipseGeometry.Center.ToWindows(), RadiusX = ellipseGeometry.RadiusX, RadiusY = ellipseGeometry.RadiusY }; } else if (geometry is GeometryGroup) { GeometryGroup geometryGroup = geometry as GeometryGroup; wGeometry = new WMedia.GeometryGroup { FillRule = ConvertFillRule(geometryGroup.FillRule) }; foreach (Geometry children in geometryGroup.Children) { WMedia.Geometry winChild = children.ToWindows(); (wGeometry as WMedia.GeometryGroup).Children.Add(winChild); } } else if (geometry is PathGeometry) { PathGeometry pathGeometry = geometry as PathGeometry; WMedia.PathGeometry wPathGeometry = new WMedia.PathGeometry { FillRule = ConvertFillRule(pathGeometry.FillRule) }; foreach (PathFigure xamPathFigure in pathGeometry.Figures) { WMedia.PathFigure wPathFigure = new WMedia.PathFigure { StartPoint = xamPathFigure.StartPoint.ToWindows(), IsFilled = xamPathFigure.IsFilled, IsClosed = xamPathFigure.IsClosed }; wPathGeometry.Figures.Add(wPathFigure); foreach (PathSegment pathSegment in xamPathFigure.Segments) { // LineSegment if (pathSegment is LineSegment) { LineSegment lineSegment = pathSegment as LineSegment; WMedia.LineSegment winSegment = new WMedia.LineSegment { Point = lineSegment.Point.ToWindows() }; wPathFigure.Segments.Add(winSegment); } // PolylineSegment if (pathSegment is PolyLineSegment) { PolyLineSegment polyLineSegment = pathSegment as PolyLineSegment; WMedia.PolyLineSegment wSegment = new WMedia.PolyLineSegment(); foreach (var point in polyLineSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // BezierSegment if (pathSegment is BezierSegment) { BezierSegment bezierSegment = pathSegment as BezierSegment; WMedia.BezierSegment wSegment = new WMedia.BezierSegment { Point1 = bezierSegment.Point1.ToWindows(), Point2 = bezierSegment.Point2.ToWindows(), Point3 = bezierSegment.Point3.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyBezierSegment else if (pathSegment is PolyBezierSegment) { PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; WMedia.PolyBezierSegment wSegment = new WMedia.PolyBezierSegment(); foreach (var point in polyBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // QuadraticBezierSegment if (pathSegment is QuadraticBezierSegment) { QuadraticBezierSegment quadraticBezierSegment = pathSegment as QuadraticBezierSegment; WMedia.QuadraticBezierSegment wSegment = new WMedia.QuadraticBezierSegment { Point1 = quadraticBezierSegment.Point1.ToWindows(), Point2 = quadraticBezierSegment.Point2.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyQuadraticBezierSegment else if (pathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment polyQuadraticBezierSegment = pathSegment as PolyQuadraticBezierSegment; WMedia.PolyQuadraticBezierSegment wSegment = new WMedia.PolyQuadraticBezierSegment(); foreach (var point in polyQuadraticBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // ArcSegment else if (pathSegment is ArcSegment) { ArcSegment arcSegment = pathSegment as ArcSegment; WMedia.ArcSegment wSegment = new WMedia.ArcSegment { Size = new WFoundation.Size(arcSegment.Size.Width, arcSegment.Size.Height), RotationAngle = arcSegment.RotationAngle, IsLargeArc = arcSegment.IsLargeArc, SweepDirection = arcSegment.SweepDirection == SweepDirection.Clockwise ? WMedia.SweepDirection.Clockwise : WMedia.SweepDirection.Counterclockwise, Point = arcSegment.Point.ToWindows() }; wPathFigure.Segments.Add(wSegment); } } } wGeometry = wPathGeometry; } return(wGeometry); }