/// <summary> /// Обработка команд от панели и главного меню /// </summary> /// <param name="document"></param> /// <param name="id"></param> protected override void OnCommand(Document document, int id) { switch ((Commands)id) { default: base.OnCommand(document, id); break; case Commands.Create: break; case Commands.Start: //Команда создания объекта NFUtils.Doc = document; NFTask task = NFUtils.GetGeometry(); NFForm wndw = new NFForm(task); //Form1(task); wndw.Activate(); wndw.Show(); break; case Commands.Out: NFResults.Start(); break; } }
protected static void Process(StreamReader filestream) { Document Doc = TFlex.Application.ActiveDocument; NFUtils.Doc = Doc; Page p = new Page(Doc); p.Name = "NFResult"; p.FontStyle.Italic = true; int contour_count = 0; string line = ""; NFPolyline Poly = new NFPolyline(); double y_offset = 0; do { line = filestream.ReadLine(); var split = line.Split(' ').ToList(); bool processing = false; double?firstX = null; double?firstY = null; if (line != null && split.Count == 2) { processing = true; contour_count++; NFUtils.Msg("Contour: " + contour_count); do { line = filestream.ReadLine(); split = line.Split(' ').ToList(); if (split.Count > 1) { if (split.Count == 3) { int bulge; int.TryParse(split[2], out bulge); NFUtils.Msg(line); double x, y; double.TryParse(split[0].Replace('.', ','), out x); double.TryParse(split[1].Replace('.', ','), out y); if (contour_count == 1) { y_offset = Math.Max(y_offset, y); } else { y = y_offset - y; } if (firstX == null) { firstX = x; firstY = y; } Poly.AddPoint(x, y); } if (split.Count == 5) { NFUtils.Msg($"ARC: {line}"); double x, y, radius, ang1, ang2; double.TryParse(split[0].Replace('.', ','), out x); double.TryParse(split[1].Replace('.', ','), out y); double.TryParse(split[2].Replace('.', ','), out radius); double.TryParse(split[3].Replace('.', ','), out ang1); double.TryParse(split[4].Replace('.', ','), out ang2); radius = radius / 2; double x1 = Math.Cos(-ang1 / 180 * Math.PI) * radius + x + radius; double y1 = Math.Sin(-ang1 / 180 * Math.PI) * radius + y + radius; double x2 = Math.Cos((-ang1 - ang2 / 2) / 180 * Math.PI) * radius + x + radius; double y2 = Math.Sin((-ang1 - ang2 / 2) / 180 * Math.PI) * radius + y + radius; double x3 = Math.Cos((-ang1 - ang2) / 180 * Math.PI) * radius + x + radius; double y3 = Math.Sin((-ang1 - ang2) / 180 * Math.PI) * radius + y + radius; y1 = y_offset - y1; y2 = y_offset - y2; y3 = y_offset - y3; FreeNode fn1 = new FreeNode(Doc, x1, y1); FreeNode fn2 = new FreeNode(Doc, x2, y2); FreeNode fn3 = new FreeNode(Doc, x3, y3); if (firstX == null) { firstX = x1; firstY = y1; } if (Poly.count > 0) { Poly.AddPoint(x1, y1); Poly.Draw(Doc, p); Poly = new NFPolyline(); } Poly.AddPoint(x3, y3); ThreePointArcOutline Arc = new ThreePointArcOutline(Doc, fn1, fn2, fn3); Arc.Page = p; } } } while (line != null & split.Count > 1); } if (processing & Poly.count > 0) { NFUtils.Msg("INIT POLYLINE"); Poly.AddPoint(firstX ?? 0, firstY ?? 0); Poly.Draw(Doc, p); Poly = new NFPolyline(); } if (filestream.EndOfStream) { break; } } while (true); }
private void listView1_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { string areaName = listView1.SelectedItems[0].Text; SelectedIndex = listView1.SelectedItems[0].Index; SelectedItem = task.Items[SelectedIndex]; //Отрисовка превьюшки детали Document Doc = TFlex.Application.ActiveDocument; SelectedArea = Doc.GetObjectByName(areaName) as Area; TFlex.Drawing.Rectangle bound = SelectedArea.BoundRect; double Scale = 159 / Math.Max(bound.Width, bound.Height); Bitmap img = new Bitmap(160, 160); Graphics graph = Graphics.FromImage(img); Pen pen = new Pen(Brushes.White); graph.DrawRectangle(pen, new Rectangle(0, 0, 159, 159)); pen = new Pen(Brushes.Black); pen.Width = 1; for (int cc = 0; cc < SelectedArea.ContourCount; cc++) { Contour cont = SelectedArea.GetContour(cc); foreach (var segm in cont) { switch (segm.GeometryType) { case ObjectGeometryType.Line: LineGeometry line = segm.Geometry as LineGeometry; if (line != null) { graph.DrawLine(pen, (float)((line.X1 - bound.Left) * Scale), (float)((bound.Top - line.Y1) * Scale), (float)((line.X2 - bound.Left) * Scale), (float)((bound.Top - line.Y2) * Scale)); } break; case ObjectGeometryType.Circle: CircleGeometry circle = segm.Geometry as CircleGeometry; if (circle == null) { break; } double radius = (circle.Radius * Scale); int xc = (int)((circle.CenterX - bound.Left) * Scale); int yc = (int)((bound.Top - circle.CenterY) * Scale); graph.DrawEllipse(pen, new Rectangle((int)(xc - radius), (int)(yc - radius), (int)radius * 2, (int)radius * 2)); break; case ObjectGeometryType.CircleArc: CircleArcGeometry cgeom = segm.Geometry as CircleArcGeometry; if (cgeom == null) { break; } int xc1 = (int)((cgeom.CenterX - bound.Left) * Scale); int yc1 = (int)((bound.Top - cgeom.CenterY) * Scale); radius = (cgeom.Radius * Scale); var angles = NFUtils.GetArcAngle(cgeom); double ang = angles.Item1 * 180 / Math.PI; double ang1 = angles.Item2 * 180 / Math.PI - 90; graph.DrawArc(pen, (float)(xc1 - radius), (float)(yc1 - radius), (float)(radius * 2), (float)(radius * 2), (float)ang1, (float)ang); break; default: PolylineGeometry geom = segm.Geometry as PolylineGeometry; if (geom == null) { break; } for (int i = 1; i < geom.Count; i++) { int x1 = (int)((geom.GetX(i) - bound.Left) * Scale); int y1 = (int)((bound.Top - geom.GetY(i)) * Scale); int x2 = (int)((geom.GetX(i - 1) - bound.Left) * Scale); int y2 = (int)((bound.Top - geom.GetY(i - 1)) * Scale); graph.DrawLine(pen, (float)x1, (float)y1, (float)x2, (float)y2); } break; } } } pictureBox1.Image = img; //Задание параметров форме label10.Text = $"Размеры детали = {(int) bound.Width} x {(int) bound.Height}"; label9.Text = $"Количество контуров: {SelectedArea.ContourCount}"; selectComboNum(ref comboBox2, SelectedItem.Rotation); selectComboNum(ref comboBox1, SelectedItem.Reflection); selectComboNum(ref comboBox1, SelectedItem.Reflection); textBox4.Text = SelectedItem.Count.ToString(); } }