public void PerformLayout() { /*------------------------------------------------------ * Determine the coordinates for each node in a tree. * Input: Pointer to the apex node of the tree * Assumption: The x & y coordinates of the apex node * are already correct, since the tree underneath it * will be positioned with respect to those coordinates. * Returns: TRUE if no errors, otherwise returns FALSE. *----------------------------------------------------*/ this._max_level_height = new Dictionary <int, double>(); this._max_level_width = new Dictionary <int, double>(); this._previous_level_node = new Dictionary <int, Node <T> >(); this.first_walk(this._root, 0); //adjust the root_offset // NOTE: in the original code this was a case statement on Options.Direction that did the same thing for each direction this._root_offset = this.Options.TopAdjustment + this._root.Position; this.second_walk(this._root, 0, new VisioAutomation.Geometry.Point(0, 0)); this._max_level_height = null; this._max_level_width = null; this._previous_level_node = null; this.correct_tree_bounding_box(); }
public IVisio.Shape DrawLine(double x0, double y0, double x1, double y1) { var p0 = new VisioAutomation.Geometry.Point(x0, y0); var p1 = new VisioAutomation.Geometry.Point(x1, y1); return(this.DrawLine(p0, p1)); }
public static BezierCurve FromEllipse(VisioAutomation.Geometry.Point center, VisioAutomation.Geometry.Size radius) { var pt1 = new VisioAutomation.Geometry.Point(0, radius.Height); // top var pt2 = new VisioAutomation.Geometry.Point(radius.Width, 0); // right var pt3 = new VisioAutomation.Geometry.Point(0, -radius.Height); // bottom var pt4 = new VisioAutomation.Geometry.Point(-radius.Width, 0); // left double dx = radius.Width * 4.0 * (System.Math.Sqrt(2) - 1) / 3; double dy = radius.Height * 4.0 * (System.Math.Sqrt(2) - 1) / 3; var curve_control_points = new [] { pt1, pt1.Add(dx, 0), pt2.Add(0, dy), pt2, pt2.Add(0, -dy), pt3.Add(dx, 0), pt3, pt3.Add(-dx, 0), pt4.Add(0, -dy), pt4, pt4.Add(0, dy), pt1.Add(-dx, 0), pt1 } .Select(p => p + center).ToArray(); var curve_Degree = 3; var curve = new BezierCurve(curve_control_points, curve_Degree); return(curve); }
public void Page_Draw_DoughnutSlices() { var app = this.GetVisioApplication(); var doc = this.GetNewDoc(); var page = app.ActivePage; int n = 36; double start_angle = 0.0; double radius = 1.0; double cx = 0.0; double cy = 2.0; double angle_step = System.Math.PI * 2.0 / (n - 1); foreach (double end_angle in Enumerable.Range(0, n).Select(i => i * angle_step)) { var center = new VA.Geometry.Point(cx, cy); var slice = new VA.Models.Charting.PieSlice(center, start_angle, end_angle, radius - 0.2, radius); slice.Render(page); cx += 2.5; } var bordersize = new VA.Geometry.Size(1, 1); page.ResizeToFitContents(bordersize); doc.Close(true); }
public IVisio.Shape AddShape(TextBlock block) { // Remember this Block this.Blocks.Add(block); // Calculate the Correct Full Rectangle var ll = new VisioAutomation.Geometry.Point(this.InsertionPoint.X, this.InsertionPoint.Y - block.Size.Height); var tr = new VisioAutomation.Geometry.Point(this.InsertionPoint.X + block.Size.Width, this.InsertionPoint.Y); var rect = new VisioAutomation.Geometry.Rectangle(ll, tr); // Draw the Shape var newshape = this._page.DrawRectangle(rect); block.VisioShape = newshape; block.VisioShapeID = newshape.ID; block.Rectangle = rect; // Handle Text If Needed if (block.Text != null) { newshape.Text = block.Text; } this._adjust_insertion_point(block.Size); return(newshape); }
public Geometry.LineSegment GetConnectionLine(ParentChildConnection <Node <T> > connection) { var parent_rect = connection.Parent.Rect; var child_rect = connection.Child.Rect; double parent_x, parent_y; double child_x, child_y; if (TreeLayout <T> .IsVertical(this.Options.Direction)) { parent_x = parent_rect.Center.X; child_x = child_rect.Center.X; parent_y = TreeLayout <T> ._get_side(parent_rect, this.Options.Direction); child_y = TreeLayout <T> ._get_side(child_rect, TreeLayout <T> .GetOpposite(this.Options.Direction)); } else { var parent_dir = this.Options.Direction; var child_dir = TreeLayout <T> .GetOpposite(parent_dir); parent_x = TreeLayout <T> ._get_side(parent_rect, parent_dir); child_x = TreeLayout <T> ._get_side(child_rect, child_dir); parent_y = parent_rect.Center.Y; child_y = child_rect.Center.Y; } var parent_attach_point = new VisioAutomation.Geometry.Point(parent_x, parent_y); var child_attach_point = new VisioAutomation.Geometry.Point(child_x, child_y); return(new Geometry.LineSegment(parent_attach_point, child_attach_point)); }
public void Scripting_Draw_PieChart() { var pagesize = new VA.Geometry.Size(4, 4); var center = new VA.Geometry.Point(2, 2); double radius = 1.0; var chart = new VisioAutomation.Models.Charting.PieChart(center, radius); chart.DataPoints.Add(1.0); chart.DataPoints.Add(2.0); chart.DataPoints.Add(3.0); chart.DataPoints.Add(4.0); // Create the Page var client = this.GetScriptingClient(); client.Document.New(); client.Page.New(pagesize, false); // Draw the chart client.Draw.PieChart(chart); // Cleanup client.Document.Close(true); }
public static void Nurbs2() { // Draw a simple NURBS // Example from Graham Wideman's book var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); var points = new[] { new VA.Geometry.Point(0.2500, 0.2500), new VA.Geometry.Point(0.2500, 0.7500), new VA.Geometry.Point(0.4063, 0.8125), new VA.Geometry.Point(0.5625, 0.3750), new VA.Geometry.Point(0.5538, 0.8125), new VA.Geometry.Point(0.7600, 0.7500), new VA.Geometry.Point(0.7600, 0.2500) }; var origin = new VA.Geometry.Point(4, 4); var scale = new VA.Geometry.Size(4, 4); var controlpoints = points.Select(x => (x * scale) + origin).ToList(); var knots = new double[] { 0, 0, 0, 0, 25, 50, 75, 100, 100, 100, 100 }; var degree = 3; var Weights = controlpoints.Select(i => 1.0).ToList(); var s0 = page.DrawNurbs(controlpoints, knots, Weights, degree); s0.Text = "Generic NURBS shape"; }
public static void Nurbs1() { // Draw a simple NURBS // Example from this page:http://www.robthebloke.org/opengl_programming.html var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); var points = new[] { new VA.Geometry.Point(10, 10), new VA.Geometry.Point(5, 10), new VA.Geometry.Point(-5, 5), new VA.Geometry.Point(-10, 5), new VA.Geometry.Point(-4, 10), new VA.Geometry.Point(-4, 5), new VA.Geometry.Point(-8, 1) }; var origin = new VA.Geometry.Point(4, 4); var scale = new VA.Geometry.Size(1.0 / 4.0, 1.0 / 4.0); var controlpoints = points.Select(x => (x * scale) + origin).ToList(); var knots = new double[] { 0, 0, 0, 0, 1, 2, 3, 4, 4, 4, 4 }; var degree = 3; var weights = controlpoints.Select(i => 1.0).ToList(); var s0 = page.DrawNurbs(controlpoints, knots, weights, degree); s0.Text = "Generic NURBS shape"; }
public static BezierSegment[] FromArc(double startangle, double endangle) { if (endangle < startangle) { throw new System.ArgumentOutOfRangeException(nameof(endangle), "endangle must be >= startangle"); } double min_angle = 0; double max_angle = System.Math.PI * 2; double total_angle = endangle - startangle; if (total_angle == min_angle) { var arr = new BezierSegment[1]; double cos_theta = System.Math.Cos(startangle); double sin_theta = System.Math.Sin(startangle); var p0 = new VisioAutomation.Geometry.Point(cos_theta, -sin_theta); var p1 = BezierSegment._rotate_around_origin(p0, startangle); arr[0] = new BezierSegment(p1, p1, p1, p1); } if (total_angle > max_angle) { endangle = startangle + max_angle; } var bez_arr = BezierSegment.subdivide_arc_nicely(startangle, endangle) .Select(a => BezierSegment.get_bezier_points_for_small_arc(a.Begin, a.End)) .ToArray(); return(bez_arr); }
public IVisio.Shape DrawLine(VisioScripting.TargetPage targetpage, double x0, double y0, double x1, double y1) { var p0 = new VisioAutomation.Geometry.Point(x0, y0); var p1 = new VisioAutomation.Geometry.Point(x1, y1); return(this.DrawLine(targetpage, p0, p1)); }
public void Chart_Bar1() { var doc = this.GetNewDoc(); var app = doc.Application; var page = app.ActivePage; var center = new VA.Geometry.Point(4, 5); double radius = 1.0; var values = new[] { 1.0, 2.0 }; var slices = VACHART.PieSlice.GetSlicesFromValues(center, radius, values); var shapes = new IVisio.Shape[values.Length]; for (int i = 0; i < values.Length; i++) { var slice = slices[i]; var shape = slice.Render(page); shapes[i] = shape; var culture = System.Globalization.CultureInfo.InvariantCulture; shape.Text = values[i].ToString(culture); } var shapeids = shapes.Select(s => s.ID).ToList(); var xfrms = VA.Shapes.ShapeXFormCells.GetCells(page, shapeids, VA.ShapeSheet.CellValueType.Formula); Assert.AreEqual("4.25 in", xfrms[0].PinX.Value); Assert.AreEqual("5.5 in", xfrms[0].PinY.Value); Assert.AreEqual("4 in", xfrms[1].PinX.Value); Assert.AreEqual("4.9330127018922 in", xfrms[1].PinY.Value); doc.Close(true); }
private static VisioAutomation.Geometry.Point _rotate_around_origin(VisioAutomation.Geometry.Point p1, double theta) { double nx = (System.Math.Cos(theta) * p1.X) - (System.Math.Sin(theta) * p1.Y); double ny = (System.Math.Sin(theta) * p1.X) + (System.Math.Cos(theta) * p1.Y); return(new VisioAutomation.Geometry.Point(nx, ny)); }
public Shape Drop(string master, string stencil, VisioAutomation.Geometry.Point pos) { var m = new Shape(master, stencil, pos); this.Add(m); return(m); }
public Shape Drop(IVisio.Master master, VisioAutomation.Geometry.Point pos) { var m = new Shape(master, pos); this.Add(m); return(m); }
private static VisioAutomation.Geometry.Point _get_pin_position_for_corner(Models.ShapeXFormData input_xfrm, VisioAutomation.Geometry.Point new_lower_left, Models.SnapCornerPosition corner) { var size = new VisioAutomation.Geometry.Size(input_xfrm.XFormWidth, input_xfrm.XFormHeight); var locpin = new VisioAutomation.Geometry.Point(input_xfrm.XFormLocPinX, input_xfrm.XFormLocPinY); switch (corner) { case VisioScripting.Models.SnapCornerPosition.LowerLeft: { return(new_lower_left.Add(locpin.X, locpin.Y)); } case VisioScripting.Models.SnapCornerPosition.UpperRight: { return(new_lower_left.Subtract(size.Width, size.Height).Add(locpin.X, locpin.Y)); } case VisioScripting.Models.SnapCornerPosition.LowerRight: { return(new_lower_left.Subtract(size.Width, 0).Add(locpin.X, locpin.Y)); } case VisioScripting.Models.SnapCornerPosition.UpperLeft: { return(new_lower_left.Subtract(0, size.Height).Add(locpin.X, locpin.Y)); } default: { throw new System.ArgumentOutOfRangeException(nameof(corner), "Unsupported corner"); } } }
public Line DrawLine(VisioAutomation.Geometry.Point p0, VisioAutomation.Geometry.Point p1) { var line = new Line(p0, p1); this.Add(line); return(line); }
public Rectangle DrawRectangle(VisioAutomation.Geometry.Point p0, VisioAutomation.Geometry.Point p1) { var rectangle = new Rectangle(p0, p1); this.Add(rectangle); return(rectangle); }
public void Page_Draw_RoundedRectangle() { var page1 = this.GetNewPage(); var rect = new VA.Geometry.Rectangle(1, 1, 3, 2); // draw an inital framing rectangle so the coordinates are easy to calculate var s0 = page1.DrawRectangle(rect); double width = rect.Width; double height = rect.Height; double delta = 1.0 / 8.0; var o = new VA.Geometry.Point(0, 0); var a = new VA.Geometry.Point(o.X + delta, o.Y); var b = new VA.Geometry.Point(o.X, o.Y + delta); var c = new VA.Geometry.Point(o.X, o.Y + height - delta); var d = new VA.Geometry.Point(o.X + delta, o.Y + height); var e = new VA.Geometry.Point(o.X + width - delta, o.Y + height); var f = new VA.Geometry.Point(o.X + width, o.Y + height - delta); var g = new VA.Geometry.Point(o.X + width, o.Y + delta); var h = new VA.Geometry.Point(o.X + width - delta, o.Y); var bottom_left_curve = s0.DrawQuarterArc(a, b, IVisio.VisArcSweepFlags.visArcSweepFlagConcave); var left_side = s0.DrawLine(b, c); var top_left_curve = s0.DrawQuarterArc(c, d, IVisio.VisArcSweepFlags.visArcSweepFlagConvex); var top_side = s0.DrawLine(d, e); var top_right_curve = s0.DrawQuarterArc(e, f, IVisio.VisArcSweepFlags.visArcSweepFlagConcave); var right_side = s0.DrawLine(f, g); var bottom_right_curve = s0.DrawQuarterArc(g, h, IVisio.VisArcSweepFlags.visArcSweepFlagConvex); var bottom_side = s0.DrawLine(h, a); // delete the framing rectangle s0.DeleteSection((short)IVisio.VisSectionIndices.visSectionFirstComponent); page1.Delete(0); }
private void _draw_connectors(RenderContext context) { var connector_nodes = this._shapes.OfType <Connector>().ToList(); // if no dynamic connectors then do nothing if (connector_nodes.Count < 1) { return; } // Drop the number of connectors needed somewhere on the page var masters = connector_nodes.Select(i => i.Master.VisioMaster).ToArray(); var origin = new VisioAutomation.Geometry.Point(-2, -2); var points = Enumerable.Range(0, connector_nodes.Count) .Select(i => origin + new VisioAutomation.Geometry.Point(1.10, 0)) .ToList(); var connector_shapeids = context.VisioPage.DropManyU(masters, points); var page_shapes = context.VisioPage.Shapes; // Perform the connection for (int i = 0; i < connector_shapeids.Length; i++) { var connector_shapeid = connector_shapeids[i]; var vis_connector = page_shapes.ItemFromID[connector_shapeid]; var dyncon_shape = connector_nodes[i]; var from_shape = context.GetShape(dyncon_shape.From.VisioShapeID); var to_shape = context.GetShape(dyncon_shape.To.VisioShapeID); ConnectorHelper.ConnectShapes(from_shape, to_shape, vis_connector); dyncon_shape.VisioShape = vis_connector; dyncon_shape.VisioShapeID = connector_shapeids[i]; } }
public VisioAutomation.Geometry.Point[] GetConnectionPolyline(ParentChildConnection <Node <T> > connection) { var lineseg = this.GetConnectionLine(connection); VisioAutomation.Geometry.Point m0, m1; var parent_attach_point = lineseg.Start; var child_attach_point = lineseg.End; var dif = lineseg.End - lineseg.Start; var a = (this.Options.LevelSeparation / 2.0); var b = (this.Options.LevelSeparation / 2.0); if (TreeLayout <T> .IsVertical(this.Options.Direction)) { if (this.Options.Direction == LayoutDirection.Up) { b = -b; } m0 = new VisioAutomation.Geometry.Point(lineseg.Start.X, lineseg.End.Y + b); m1 = new VisioAutomation.Geometry.Point(lineseg.End.X, lineseg.End.Y + b); } else { if (this.Options.Direction == LayoutDirection.Left) { a = -a; } m0 = new VisioAutomation.Geometry.Point(lineseg.End.X - a, lineseg.Start.Y); m1 = new VisioAutomation.Geometry.Point(lineseg.End.X - a, lineseg.End.Y); } return(new[] { lineseg.Start, m0, m1, lineseg.End }); }
private static BezierSegment get_bezier_points_for_small_arc(double start_angle, double end_angle) { const double right_angle = System.Math.PI / 2; double total_angle = end_angle - start_angle; if (total_angle > right_angle) { throw new System.ArgumentOutOfRangeException(nameof(end_angle), "angle formed by start and end must <= right angle (pi/2)"); } double theta = (end_angle - start_angle) / 2; double cos_theta = System.Math.Cos(theta); double sin_theta = System.Math.Sin(theta); var p0 = new VisioAutomation.Geometry.Point(cos_theta, -sin_theta); var p1 = new VisioAutomation.Geometry.Point((4 - cos_theta) / 3.0, ((1 - cos_theta) * (cos_theta - 3.0)) / (3 * sin_theta)); var p2 = new VisioAutomation.Geometry.Point(p1.X, -p1.Y); var p3 = new VisioAutomation.Geometry.Point(p0.X, -p0.Y); var arc_bezier = new[] { p0, p1, p2, p3 } .Select(p => BezierSegment._rotate_around_origin(p, theta + start_angle)) .ToArray(); return(new BezierSegment(arc_bezier)); }
public void Scripting_Draw_Grid() { var origin = new VisioAutomation.Geometry.Point(0, 4); var pagesize = new VisioAutomation.Geometry.Size(4, 4); var cellsize = new VisioAutomation.Geometry.Size(0.5, 0.25); int cols = 3; int rows = 6; // Create the Page var client = this.GetScriptingClient(); client.Document.New(); client.Page.New(pagesize, false); // Find the stencil and master var stencildoc = client.Document.OpenStencil("basic_u.vss"); var master = client.Master.Get("Rectangle", stencildoc); // Draw the grid var page = client.Page.Get(); var grid = new GRID.GridLayout(cols, rows, cellsize, master); grid.Origin = origin; grid.Render(page); // Verify int total_shapes_expected = cols * rows; var shapes = page.Shapes.ToEnumerable().ToList(); int total_shapes_actual = shapes.Count; Assert.AreEqual(total_shapes_expected, total_shapes_actual); // Cleanup client.Document.Close(true); }
public static VA.Geometry.Point GetPointAtRadius(VA.Geometry.Point origin, double angle, double radius) { var new_point = new VA.Geometry.Point(radius * System.Math.Cos(angle), radius * System.Math.Sin(angle)); new_point = origin + new_point; return(new_point); }
public VisioAutomation.Geometry.Rectangle GetRectangle() { var pin = new VisioAutomation.Geometry.Point(this.XFormPinX, this.XFormPinY); var locpin = new VisioAutomation.Geometry.Point(this.XFormLocPinX, this.XFormLocPinY); var size = new VisioAutomation.Geometry.Size(this.XFormWidth, this.XFormHeight); return(new VisioAutomation.Geometry.Rectangle(pin - locpin, size)); }
public IVisio.Shape DropMaster(TargetPage targetpage, IVisio.Master master, VisioAutomation.Geometry.Point p) { targetpage = targetpage.ResolveToPage(this._client); var shape = targetpage.Page.Drop(master, p.X, p.Y); return(shape); }
public BezierSegment(VisioAutomation.Geometry.Point start, VisioAutomation.Geometry.Point handle1, VisioAutomation.Geometry.Point handle2, VisioAutomation.Geometry.Point end) : this() { this.Start = start; this.Handle1 = handle1; this.Handle2 = handle2; this.End = end; }
public void Page_Draw_Line() { var page1 = this.GetNewPage(); var p0 = new VA.Geometry.Point(0, 0); var p1 = new VA.Geometry.Point(3, 2); var s0 = page1.DrawLine(p0, p1); page1.Delete(0); }
protected override void ProcessRecord() { var center = new VisioAutomation.Geometry.Point(this.X0, this.Y0); var chart = new VisioAutomation.Models.Charting.PieChart(center, this.Radius); chart.InnerRadius = this.InnerRadius; chart.DataPoints = new VisioAutomation.Models.Charting.DataPointList(this.Values, this.Labels); this.WriteObject(chart); }
public IVisio.Shape DropMasterOnActivePage(IVisio.Master master, VisioAutomation.Geometry.Point p) { var cmdtarget = this._client.GetCommandTargetPage(); var page = cmdtarget.ActivePage; var shape = page.Drop(master, p.X, p.Y); return(shape); }