public bool?SaveLayout() { if (Layout == null) { return(false); } SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Filter = "GCode files (*.nc)|*.nc|All files (*.*)|*.*"; saveDlg.FilterIndex = 1; saveDlg.RestoreDirectory = true; Nullable <bool> result = saveDlg.ShowDialog(); if (result == true) { Point gcodeOrigin = new Point(0, 0); // get and process parameters GCodeParameters parameters = Application.Current.FindResource("GCodeSetup") as GCodeParameters; if (parameters.OriginTypes[parameters.Origin] == "Panels Bottom Left") { double minX = Double.MaxValue; double maxY = Double.MinValue; foreach (Panel panel in Layout.Panels) { double x, y; PointCollection points = panel.Points; GeometryOperations.TopLeft(points, out x, out y); minX = Math.Min(minX, x); maxY = Math.Max(maxY, y); } gcodeOrigin = new Point(minX, maxY); } else if (parameters.OriginTypes[parameters.Origin] == "Sheet Bottom Left") { gcodeOrigin = new Point(0, 0); } else if (parameters.OriginTypes[parameters.Origin] == "Sheet Center") { gcodeOrigin = new Point(Layout.SheetWidth / 2, Layout.SheetHeight / 2); } // Do the actual output Open(saveDlg.FileName); foreach (Panel panel in Layout.Panels) { Write(panel, gcodeOrigin); } Close(); return(true); } return(result); }
public void Rotate(double x, double y, double z) { double[,] rotate; rotate = GeometryOperations.CreateRotateMatrix(x, y, z); UpdateWithMatrix(rotate); RepositionToZero(); }
private void Center() { Point center = GeometryOperations.ComputeMidPoint(m_panelPoints); if (center.X != 0 || center.Y != 0) { GeometryOperations.TranslateShape(m_panelPoints, -center.X, -center.Y); } m_origin.X -= center.X; m_origin.Y -= center.Y; }
private void Write(Panel panel, Point origin) { double offset = parameters.CutterDiameter / 2; PointCollection points = panel.Points.Clone(); //GeometryOperations.TranslateShape(points, panel.Origin.X, panel.Origin.Y); Boolean first = true; Point firstPoint = new Point(0, 0); // Get the tool path, which is an offset from the panel points PointCollection path; if (offset != 0) { path = GeometryOperations.ParallelShape(points, offset, parameters.OffsetInside); } else { path = points; } double currentDepth = 0; while (currentDepth < parameters.MaterialThickness) { currentDepth += parameters.DepthPerCut; if (currentDepth > parameters.MaterialThickness) { currentDepth = parameters.MaterialThickness + parameters.CutthroughDepth; } foreach (Point p in path) { Point spot = new Point(p.X - origin.X, -(p.Y - origin.Y)); if (first) { firstPoint = spot; gCodeFile.WriteLine("G01 Z0.25 F{0}", parameters.PlungeSpeed); // Lift cutter gCodeFile.WriteLine("G00 X{0} Y{1}", spot.X, spot.Y); // Go to start point gCodeFile.WriteLine("G01 Z-{0} F{1}", currentDepth, parameters.PlungeSpeed); // cut into surface gCodeFile.WriteLine("G01 X{0} Y{1} F{2}", spot.X, spot.Y, parameters.CutSpeed); // set cutspeed first = false; } else { gCodeFile.WriteLine("G01 X{0} Y{1}", spot.X, spot.Y); } } first = true; } gCodeFile.WriteLine("G01 X{0} Y{1}", firstPoint.X, firstPoint.Y); gCodeFile.WriteLine("G01 Z0.25 F{0}", parameters.PlungeSpeed); // Lift cutter }
public static PointCollection Tongues(Point start, Point end, int numTongues, double depth) { const int NUM_POINTS = 180; double verticalDir; double horizontalDir = 1; Point current; PointCollection splitter = new PointCollection(); double panelHeight = Math.Abs(start.Y - end.Y); double radius = panelHeight / (numTongues + 1) / 2; if (start.Y > end.Y) { verticalDir = -1; } else { verticalDir = 1; } splitter.Add(start); GeometryOperations.CreateArc(splitter, radius, new Point(start.X + horizontalDir * radius, start.Y), startHalfAngle(verticalDir), endHalfAngle(verticalDir), NUM_POINTS / 2); current = new Point(start.X + horizontalDir * (depth / 2 - radius), start.Y + verticalDir * radius); splitter.Add(current); horizontalDir *= -1; for (int ii = 0; ii < numTongues - 1; ii++) { GeometryOperations.CreateArc(splitter, radius, new Point(current.X, current.Y + verticalDir * radius), startFullAngle(verticalDir), endFullAngle(horizontalDir, verticalDir), NUM_POINTS); current.Y += verticalDir * 2 * radius; //splitter.Add(current); //******************* current.X += horizontalDir * (depth - 2 * radius); //splitter.Add(current); horizontalDir *= -1; } GeometryOperations.CreateArc(splitter, radius, new Point(current.X, current.Y + verticalDir * radius), startFullAngle(verticalDir), endFullAngle(horizontalDir, verticalDir), NUM_POINTS); current.Y += verticalDir * 2 * radius; splitter.Add(current); //******************* current.X = end.X - horizontalDir * radius; //splitter.Add(current); GeometryOperations.CreateArc(splitter, radius, new Point(end.X - horizontalDir * radius, end.Y), startFinalAngle(verticalDir), endFinalAngle(horizontalDir, verticalDir), NUM_POINTS / 2); splitter.Add(end); //******************** return(splitter); }
static public PointCollection ParallelShape(PointCollection points, double offset, bool inside = false) { double leftAngle = 0, rightAngle = 0; GeometryOperations.ComputeAngles(points, ref leftAngle, ref rightAngle); bool doLeft = false; if (leftAngle < rightAngle && inside) { doLeft = true; } else if (leftAngle > rightAngle && !inside) { doLeft = true; } if (!doLeft) { offset = -offset; } PointCollection result = new PointCollection(); // Prime the pipeline with the last two non-duplicated points Point p1 = points[points.Count - 2]; Point p2 = points[points.Count - 3]; Point l1a = new Point(); Point l1b = new Point(); Point l2a = new Point(); Point l2b = new Point(); Point newPoint = new Point(); foreach (Point p in points) { if (!Double.IsNaN(p1.X)) { GeometryOperations.OffsetLine(p2, p1, offset, ref l1a, ref l1b); GeometryOperations.OffsetLine(p1, p, offset, ref l2a, ref l2b); newPoint = GeometryOperations.Intersection(l1a, l1b, l2a, l2b); result.Add(newPoint); } p2 = p1; p1 = p; } return(result); }
private void AddAllClick(object sender, RoutedEventArgs e) { double x = 10; double y = 10; double x_size = 0; double y_size = 0; foreach (Panel p in m_panels) { Panel panel = (Panel)p.Clone(); panel.Origin = new Point(x, y); GeometryOperations.ComputeSize(panel.Points, out x_size, out y_size); y += y_size * 1.1; LayoutControl.AddPanel(panel); } }
private void ShiftTo(double x, double y) { double min_x, min_y; GeometryOperations.ComputeMin(m_panelPoints, out min_x, out min_y); x -= min_x; y -= min_y; x += m_origin.X; y += m_origin.Y; if (x != 0 || y != 0) { Shift(x, y); } }
public void InsertBulkhead(double Z) { int num_chines = Bulkheads[0].NumChines; if (num_chines % 2 == 1) { num_chines = num_chines / 2 + 1; } else { num_chines /= 2; } // get points for new bulkhead // First, create chines for base hull List <Point3DCollection> chines = PrepareChines(m_BaseHull, POINTS_PER_CHINE); Point3DCollection points = new Point3DCollection(); for (int ii = num_chines - 1; ii >= 0; ii--) { Point3D point = GeometryOperations.InterpolateFromZ(chines[ii], Z); points.Add(point); } // figure out where it goes int index = 0; for (int ii = 0; ii < m_BaseHull.Bulkheads.Count; ii++) { if (m_BaseHull.Bulkheads[ii].Points[0].Z > Z) { index = ii; break; } } m_BaseHull.Bulkheads.Insert(index, new Bulkhead(points, Bulkhead.BulkheadType.VERTICAL)); m_BaseHull.Notify("HullData"); }
protected void Panelize(Point3DCollection chine1, Point3DCollection chine2) { double r1, r2; Point intersection_a1, intersection_a2; Point intersection_b1, intersection_b2; PointCollection edge2 = new PointCollection(); m_panelPoints = new PointCollection(); // See if we start at a point or an edge: if ((chine1[0] - chine2[0]).Length < MIN_EDGE_LENGTH) { // Not implemented yet throw new Exception(); //// Start both edges at (0,0) //m_panelPoints.Add(new Point(0, 0)); //edge2.Add(new Point(0, 0)); //// Compute next point, and place it on the x axis //// advance edge1 by one point //r1 = (chine1[0] - chine1[1]).Length; //m_panelPoints.Add(new Point(r1, 0)); //// advance edge2 by one point //r1 = (chine2[0] - chine2[1]).Length; //r2 = (chine1[0] - chine2[1]).Length; //Geometry.Intersection(edge2[edge2.Count - 1], r1, m_panelPoints[m_panelPoints.Count - 1], r2, out intersection_b1, out intersection_b2); //if (intersection_b1.X >= intersection_b2.X) // edge2.Add(intersection_b1); //else // edge2.Add(intersection_b2); } else { // Make the edge the first segment in edge2 m_panelPoints.Add(new Point(0, 0)); edge2.Add(new Point(0, 0)); r1 = (chine1[0] - chine2[0]).Length; edge2.Add(new Point(0, -r1)); // Compute next point, and favor positive X direction // advance edge1 by one point r1 = (chine1[0] - chine1[1]).Length; r2 = (chine2[0] - chine1[1]).Length; GeometryOperations.Intersection(m_panelPoints[m_panelPoints.Count - 1], r1, edge2[edge2.Count - 1], r2, out intersection_a1, out intersection_a2); // advance edge2 by one point r1 = (chine2[0] - chine2[1]).Length; r2 = (chine1[0] - chine2[1]).Length; GeometryOperations.Intersection(edge2[edge2.Count - 1], r1, m_panelPoints[m_panelPoints.Count - 1], r2, out intersection_b1, out intersection_b2); if (intersection_a1.X >= intersection_a2.X) { m_panelPoints.Add(intersection_a1); } else { m_panelPoints.Add(intersection_a2); } if (intersection_b1.X >= intersection_b2.X) { edge2.Add(intersection_b1); } else { edge2.Add(intersection_b2); } } for (int ii = 2; ii < chine1.Count; ii++) { // advance edge1 by one point r1 = (chine1[ii - 1] - chine1[ii]).Length; r2 = (chine2[ii - 1] - chine1[ii]).Length; GeometryOperations.Intersection(m_panelPoints[m_panelPoints.Count - 1], r1, edge2[edge2.Count - 1], r2, out intersection_a1, out intersection_a2); // advance edge2 by one point r1 = (chine2[ii - 1] - chine2[ii]).Length; r2 = (chine1[ii - 1] - chine2[ii]).Length; GeometryOperations.Intersection(edge2[edge2.Count - 1], r1, m_panelPoints[m_panelPoints.Count - 1], r2, out intersection_b1, out intersection_b2); Vector v_1 = m_panelPoints[m_panelPoints.Count - 1] - m_panelPoints[m_panelPoints.Count - 2]; Vector v_1a = intersection_a1 - m_panelPoints[m_panelPoints.Count - 1]; Vector v_1b = intersection_a2 - m_panelPoints[m_panelPoints.Count - 1]; Vector v_2 = edge2[edge2.Count - 1] - edge2[edge2.Count - 2]; Vector v_2a = intersection_b1 - edge2[edge2.Count - 1]; Vector v_2b = intersection_b2 - edge2[edge2.Count - 1]; double a1 = Math.Abs(Vector.AngleBetween(v_1, v_1a)); double a2 = Math.Abs(Vector.AngleBetween(v_1, v_1b)); double b1 = Math.Abs(Vector.AngleBetween(v_2, v_2a)); double b2 = Math.Abs(Vector.AngleBetween(v_2, v_2b)); if (a1 < a2) { m_panelPoints.Add(intersection_a1); } else { m_panelPoints.Add(intersection_a2); } if (b1 < b2) { edge2.Add(intersection_b1); } else { edge2.Add(intersection_b2); } } // NOTE: Should check for closed tail? for (int ii = edge2.Count - 1; ii >= 0; ii--) { m_panelPoints.Add(edge2[ii]); } }
private void Shift(double x, double y) { GeometryOperations.TranslateShape(m_panelPoints, x, y); }
protected void Panelize(Point3DCollection chine1, Point3DCollection chine2) { double r1, r2; Point intersection_a1, intersection_a2; Point intersection_b1, intersection_b2; PointCollection edge2 = new PointCollection(); m_panelPoints = new PointCollection(); bool pointy_bow = (chine1[0] - chine2[0]).Length < MIN_EDGE_LENGTH; bool pointy_stern = (chine1[chine1.Count - 1] - chine2[chine1.Count - 1]).Length < MIN_EDGE_LENGTH; if (pointy_bow) { m_panelPoints.Add(new Point(0, 0)); edge2.Add(new Point(0, 0)); r1 = (chine1[0] - chine1[1]).Length; m_panelPoints.Add(new Point(r1 * Math.Cos(Math.PI / 4), r1 * Math.Sin(Math.PI / 4))); } else { // Start at origin m_panelPoints.Add(new Point(0, 0)); edge2.Add(new Point(0, 0)); // Make the edge the first segment in edge2 r1 = (chine1[0] - chine2[0]).Length; edge2.Add(new Point(0, -r1)); // Compute next point, and favor positive X direction // advance edge1 by one point r1 = (chine1[0] - chine1[1]).Length; r2 = (chine2[0] - chine1[1]).Length; GeometryOperations.Intersection(m_panelPoints[m_panelPoints.Count - 1], r1, edge2[edge2.Count - 1], r2, out intersection_a1, out intersection_a2); if (intersection_a1.X >= intersection_a2.X) { m_panelPoints.Add(intersection_a1); } else { m_panelPoints.Add(intersection_a2); } } // Add next point to edge2 r1 = (chine2[0] - chine2[1]).Length; r2 = (chine1[1] - chine2[1]).Length; GeometryOperations.Intersection(edge2[edge2.Count - 1], r1, m_panelPoints[m_panelPoints.Count - 1], r2, out intersection_b1, out intersection_b2); if (intersection_b1.X >= intersection_b2.X) { edge2.Add(intersection_b1); } else { edge2.Add(intersection_b2); } // Complete the rest of the points int last_point; if (pointy_stern) { last_point = chine1.Count - 2; } else { last_point = chine1.Count - 1; } for (int ii = 1; ii < last_point; ii++) { r1 = (chine1[ii] - chine1[ii + 1]).Length; r2 = (chine2[ii] - chine1[ii + 1]).Length; GeometryOperations.Intersection(m_panelPoints[m_panelPoints.Count - 1], r1, edge2[edge2.Count - 1], r2, out intersection_a1, out intersection_a2); Vector v_1 = m_panelPoints[m_panelPoints.Count - 1] - m_panelPoints[m_panelPoints.Count - 2]; Vector v_1a = intersection_a1 - m_panelPoints[m_panelPoints.Count - 1]; Vector v_1b = intersection_a2 - m_panelPoints[m_panelPoints.Count - 1]; double a1 = Math.Abs(Vector.AngleBetween(v_1, v_1a)); double a2 = Math.Abs(Vector.AngleBetween(v_1, v_1b)); if (a1 < a2) { m_panelPoints.Add(intersection_a1); } else { m_panelPoints.Add(intersection_a2); } // advance edge2 by one point r1 = (chine2[ii] - chine2[ii + 1]).Length; r2 = (chine1[ii + 1] - chine2[ii + 1]).Length; GeometryOperations.Intersection(edge2[edge2.Count - 1], r1, m_panelPoints[m_panelPoints.Count - 1], r2, out intersection_b1, out intersection_b2); Vector v_2 = edge2[edge2.Count - 1] - edge2[edge2.Count - 2]; Vector v_2a = intersection_b1 - edge2[edge2.Count - 1]; Vector v_2b = intersection_b2 - edge2[edge2.Count - 1]; double b1 = Math.Abs(Vector.AngleBetween(v_2, v_2a)); double b2 = Math.Abs(Vector.AngleBetween(v_2, v_2b)); if (b1 < b2) { edge2.Add(intersection_b1); } else { edge2.Add(intersection_b2); } } if (pointy_stern) { r1 = (chine1[chine1.Count - 2] - chine1[chine1.Count - 1]).Length; r2 = (chine2[chine2.Count - 2] - chine2[chine2.Count - 1]).Length; GeometryOperations.Intersection(m_panelPoints[m_panelPoints.Count - 1], r1, edge2[edge2.Count - 1], r2, out intersection_a1, out intersection_a2); Vector v_1 = m_panelPoints[m_panelPoints.Count - 1] - m_panelPoints[m_panelPoints.Count - 2]; Vector v_1a = intersection_a1 - m_panelPoints[m_panelPoints.Count - 1]; Vector v_1b = intersection_a2 - m_panelPoints[m_panelPoints.Count - 1]; double a1 = Math.Abs(Vector.AngleBetween(v_1, v_1a)); double a2 = Math.Abs(Vector.AngleBetween(v_1, v_1b)); if (a1 < a2) { m_panelPoints.Add(intersection_a1); } else { m_panelPoints.Add(intersection_a2); } // Don't need to add point to edge2 because it is the same (pointy) point and it would be a duplicate } // Copy edge2 input m_panelPoints for (int ii = edge2.Count - 1; ii >= 0; ii--) { m_panelPoints.Add(edge2[ii]); } }