예제 #1
0
        /// <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.Start:    //Команда создания объекта
                NFGetGeom.Doc = document;

                NFTask task = NFGetGeom.GetGeometry();
                Form1  Wndw = new Form1(task);
                Wndw.Activate();
                Wndw.Show();
                break;

            case Commands.Out:
                NFResults.Start();
                break;
            }
        }
예제 #2
0
        protected static void Process(StreamReader filestream)
        {
            int i = 0;
            //filestream.ReadLine(); filestream.ReadLine();
            Document Doc = TFlex.Application.ActiveDocument;

            NFGetGeom.Doc = Doc;

            Page p = new Page(Doc);

            p.Name             = "NFResult";
            p.FontStyle.Italic = true;

            int    contour_count = 0;
            string line          = "";

            string[]   split;
            NFPolyline Poly = new NFPolyline();

            double y_offset = 0;



            do
            {
                line  = filestream.ReadLine();
                split = line.Split(' ');
                bool   processing = false;
                double first_x    = -1.337;
                double first_y    = -1.337;

                if (line != null && split.Length == 2)
                {
                    processing = true;
                    contour_count++;
                    NFGetGeom.Msg("Contour: " + contour_count);

                    do
                    {
                        line  = filestream.ReadLine();
                        split = line.Split(' ');

                        if (split.Length > 1)
                        {
                            if (split.Length == 3)
                            {
                                int bulge = 0;
                                Int32.TryParse(split[2].ToString(), out bulge);
                                NFGetGeom.Msg(line);

                                double x = 0, y = 0;
                                Double.TryParse(split[0].ToString().Replace('.', ','), out x);
                                Double.TryParse(split[1].ToString().Replace('.', ','), out y);

                                if (contour_count == 1)
                                {
                                    y_offset = Math.Max(y_offset, y);
                                }
                                else
                                {
                                    y = y_offset - y;
                                }

                                if (first_x == -1.337)
                                {
                                    first_x = x;
                                    first_y = y;
                                }
                                Poly.AddPoint(x, y);
                            }

                            if (split.Length == 5)
                            {
                                NFGetGeom.Msg("ARC: " + line);
                                double x = 0, y = 0, radius = 0, ang1 = 0, ang2 = 0;
                                Double.TryParse(split[0].ToString().Replace('.', ','), out x);
                                Double.TryParse(split[1].ToString().Replace('.', ','), out y);
                                Double.TryParse(split[2].ToString().Replace('.', ','), out radius);
                                Double.TryParse(split[3].ToString().Replace('.', ','), out ang1);
                                Double.TryParse(split[4].ToString().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 (first_x == -1.337)
                                {
                                    first_x = x1;
                                    first_y = 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.Length > 1);
                }

                if (processing & Poly.count > 0)
                {
                    NFGetGeom.Msg("INIT POLYLINE");
                    Poly.AddPoint(first_x, first_y);
                    Poly.Draw(Doc, p);
                    Poly = new NFPolyline();
                }
                if (filestream.EndOfStream)
                {
                    break;
                }
            } while (true);
        }
예제 #3
0
파일: Form1.cs 프로젝트: ukoloff/TFlexNF
        private void listView1_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems != null && listView1.SelectedItems.Count > 0)
            {
                string areaName = listView1.SelectedItems[0].Text;
                num  = listView1.SelectedItems[0].Index;
                Item = task.GetItem(num);

                //Отрисовка превьюшки детали
                Document Doc = TFlex.Application.ActiveDocument;
                select = Doc.GetObjectByName(areaName) as Area;
                TFlex.Drawing.Rectangle bound = select.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 < select.ContourCount; cc++)
                {
                    Contour cont = select.GetContour(cc);
                    for (int sc = 0; sc < cont.SegmentCount; sc++)
                    {
                        ContourSegment segm = cont.GetSegment(sc);
                        switch (segm.GeometryType)
                        {
                        case ObjectGeometryType.Line:
                            LineGeometry line = segm.Geometry as LineGeometry;
                            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;
                            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;
                            int xc1 = (int)((cgeom.CenterX - bound.Left) * Scale);
                            int yc1 = (int)((bound.Top - cgeom.CenterY) * Scale);
                            radius = (cgeom.Radius * Scale);
                            double[] angles = NFGetGeom.getArcAngle(cgeom, segm.IsCounterclockwise);
                            double   ang    = angles[0] * 180 / Math.PI;
                            double   ang1   = angles[1] * 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)
                            {
                                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)(159 / Scale);
                label9.Text  = "Количество контуров: " + select.ContourCount;

                selectComboNum(ref comboBox2, Item.Rotation);

                selectComboNum(ref comboBox1, Item.Reflection);
                selectComboNum(ref comboBox1, Item.Reflection);

                textBox4.Text = Item.Count.ToString();
            }
        }