protected override void OnPaint(GUI.PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;

            graphics.SmoothingMode   = SmoothingMode.AntiAlias;
            graphics.PixelOffsetMode = PixelOffsetMode.None;


            PolygonElement polygon = m_PolygonElement;

            if (!polygon.IsModified)
            {
                //TEST return;
            }

            polygon.close(m_CloseCheckBox.IsChecked);
            PolylineGeometry poly = new PolylineGeometry(polygon.Polygon, true, m_CloseCheckBox.IsChecked);

            BSplineGeometry bspline = new BSplineGeometry(poly);

            bspline.InterpolationStep = 1.0 / m_PointsNumberSlider.Value;

            SinglePathTransform tcurve = new SinglePathTransform();

            tcurve.PreserveXScale = m_PreserveXScaleCheckBox.IsChecked;
            if (m_FixedLenCheckBox.IsChecked)
            {
                tcurve.BaseLength = 1120;
            }
            tcurve.AddPath(bspline);

            GeometryTransformer ftrans = new GeometryTransformer(GetCurveTransformedTextGeometry(tcurve.TotalLength).Item1, tcurve);

            if (m_FillCheckBox.IsChecked)
            {
                Brush brush = m_TextBrush;

                //  Irrlicht Renderer can't render smoothed gradients now
                if (graphics.RenderSystemName.Contains(Graphics.RSN_Irrlicht))
                {
                    if (m_TextBrush_Irrlicht == null)
                    {
                        m_TextBrush_Irrlicht = new SolidColorBrush(Color.Yellow);
                    }

                    brush = m_TextBrush_Irrlicht;
                }

                graphics.FillGeometry(brush, ftrans);
            }
            if (m_OutlineCheckBox.IsChecked)
            {
                graphics.DrawGeometry(m_FillCheckBox.IsChecked ? Color.Red : Color.White, ftrans, m_OutlineThicknessSlider.Value);
            }

            graphics.DrawGeometry(m_BSplinePen, bspline);


            base.OnPaint(e);
        }
Ejemplo n.º 2
0
        public void TestSerialization()
        {
            var polyline = new PolylineGeometry { Points = new []{new Point(1.5, 2), new Point(3, 4.2), new Point(4.5, 6.4), } };

            var writer = new StringWriter();
            _serializer.Serialize(writer, polyline);
            var reader = new StringReader(writer.ToString());

            Assert.AreEqual(polyline, _serializer.Deserialize(reader));
        }
Ejemplo n.º 3
0
        private void A_DrawEraseEvent(ActionEventArgs gs)
        {
            PolylineGeometry polyline = this.action.Geometry as PolylineGeometry;

            if (polyline.Lines.Count > 0)
            {
                var last = polyline.Lines[polyline.Lines.Count - 1];
                sublineGeometry.Start = last.Start;
                sublineGeometry.End   = last.End;
                sublineGeometry.Update();
                this.Tip.SetText(sublineGeometry.TextValue, sublineGeometry.TextPosition, sublineGeometry.TextAngle);
            }
        }
Ejemplo n.º 4
0
        [OvldGenCallTarget] public static void Polyline([OvldDefault(nameof(BlendMode))] ShapesBlendMode blendMode,
                                                        PolylinePath path,
                                                        [OvldDefault("false")] bool closed,
                                                        [OvldDefault(nameof(PolylineGeometry))] PolylineGeometry geometry,
                                                        [OvldDefault(nameof(PolylineJoins))] PolylineJoins joins,
                                                        [OvldDefault(nameof(LineThickness))] float thickness,
                                                        [OvldDefault(nameof(LineThicknessSpace))] ThicknessSpace thicknessSpace,
                                                        [OvldDefault(nameof(Color))] Color color)
        {
            if (path.EnsureMeshIsReadyToRender(closed, joins, out Mesh mesh) == false)
            {
                return;                 // no points defined in the mesh
            }
            switch (path.Count)
            {
            case 0:
                Debug.LogWarning("Tried to draw polyline with no points");
                return;

            case 1:
                Debug.LogWarning("Tried to draw polyline with only one point");
                return;
            }

            Material matPolyLine = ShapesMaterialUtils.GetPolylineMat(joins)[blendMode];

            ApplyGlobalProperties(matPolyLine);
            matPolyLine.SetFloat(ShapesMaterialUtils.propThickness, thickness);
            matPolyLine.SetFloat(ShapesMaterialUtils.propThicknessSpace, (int)thicknessSpace);
            matPolyLine.SetColor(ShapesMaterialUtils.propColor, color);
            matPolyLine.SetInt(ShapesMaterialUtils.propAlignment, (int)geometry);
            matPolyLine.SetInt(ShapesMaterialUtils.propScaleMode, (int)ScaleMode);
            if (joins == PolylineJoins.Miter)
            {
                DrawMesh(Vector3.zero, Quaternion.identity, mesh, matPolyLine);
            }
            else
            {
                Material matPolyLineJoins = ShapesMaterialUtils.GetPolylineJoinsMat(joins)[blendMode];
                ApplyGlobalProperties(matPolyLineJoins);
                matPolyLineJoins.SetFloat(ShapesMaterialUtils.propThickness, thickness);
                matPolyLineJoins.SetFloat(ShapesMaterialUtils.propThicknessSpace, (int)thicknessSpace);
                matPolyLineJoins.SetColor(ShapesMaterialUtils.propColor, color);
                matPolyLineJoins.SetInt(ShapesMaterialUtils.propAlignment, (int)geometry);
                matPolyLineJoins.SetInt(ShapesMaterialUtils.propScaleMode, (int)ScaleMode);
                DrawTwoSubmeshes(Vector3.zero, Quaternion.identity, mesh, matPolyLine, matPolyLineJoins);
            }
        }
Ejemplo n.º 5
0
        [OvldGenCallTarget] static void Polyline_Internal(PolylinePath path,
                                                          [OvldDefault("false")] bool closed,
                                                          [OvldDefault(nameof(PolylineGeometry))] PolylineGeometry geometry,
                                                          [OvldDefault(nameof(PolylineJoins))] PolylineJoins joins,
                                                          [OvldDefault(nameof(Thickness))] float thickness,
                                                          [OvldDefault(nameof(ThicknessSpace))] ThicknessSpace thicknessSpace,
                                                          [OvldDefault(nameof(Color))] Color color)
        {
            if (path.EnsureMeshIsReadyToRender(closed, joins, out Mesh mesh) == false)
            {
                return;                 // no points defined in the mesh
            }
            switch (path.Count)
            {
            case 0:
                Debug.LogWarning("Tried to draw polyline with no points");
                return;

            case 1:
                Debug.LogWarning("Tried to draw polyline with only one point");
                return;
            }

            void ApplyToMpb(MpbPolyline2D mpb)
            {
                mpb.thickness.Add(thickness);
                mpb.thicknessSpace.Add((int)thicknessSpace);
                mpb.color.Add(color.ColorSpaceAdjusted());
                mpb.alignment.Add((int)geometry);
                mpb.scaleMode.Add((int)ScaleMode);
            }

            if (DrawCommand.IsAddingDrawCommandsToBuffer)              // mark as used by this command to prevent destroy in dispose
            {
                path.RegisterToCommandBuffer(DrawCommand.CurrentWritingCommandBuffer);
            }

            using (new IMDrawer(mpbPolyline, ShapesMaterialUtils.GetPolylineMat(joins)[Draw.BlendMode], mesh, 0))
                ApplyToMpb(mpbPolyline);

            if (joins.HasJoinMesh())
            {
                using (new IMDrawer(mpbPolylineJoins, ShapesMaterialUtils.GetPolylineJoinsMat(joins)[Draw.BlendMode], mesh, 1))
                    ApplyToMpb(mpbPolylineJoins);
            }
        }
Ejemplo n.º 6
0
        [OvldGenCallTarget] static void Polyline([OvldDefault(nameof(BlendMode))] ShapesBlendMode blendMode,
                                                 PolylinePath path,
                                                 [OvldDefault("false")] bool closed,
                                                 [OvldDefault(nameof(PolylineGeometry))] PolylineGeometry geometry,
                                                 [OvldDefault(nameof(PolylineJoins))] PolylineJoins joins,
                                                 [OvldDefault(nameof(LineThickness))] float thickness,
                                                 [OvldDefault(nameof(LineThicknessSpace))] ThicknessSpace thicknessSpace,
                                                 [OvldDefault(nameof(Color))] Color color)
        {
            if (path.EnsureMeshIsReadyToRender(closed, joins, out Mesh mesh) == false)
            {
                return;                 // no points defined in the mesh
            }
            switch (path.Count)
            {
            case 0:
                Debug.LogWarning("Tried to draw polyline with no points");
                return;

            case 1:
                Debug.LogWarning("Tried to draw polyline with only one point");
                return;
            }

            void ApplyToMpb(MpbPolyline mpb)
            {
                mpb.thickness.Add(thickness);
                mpb.thicknessSpace.Add((int)thicknessSpace);
                mpb.color.Add(color);
                mpb.alignment.Add((int)geometry);
                mpb.scaleMode.Add((int)ScaleMode);
            }

            using (new IMDrawer(mpbPolyline, ShapesMaterialUtils.GetPolylineMat(joins)[blendMode], mesh, 0))
                ApplyToMpb(mpbPolyline);

            if (joins.HasJoinMesh())
            {
                using (new IMDrawer(mpbPolylineJoins, ShapesMaterialUtils.GetPolylineJoinsMat(joins)[blendMode], mesh, 1))
                    ApplyToMpb(mpbPolylineJoins);
            }
        }
Ejemplo n.º 7
0
            protected override void OnPaint(GUI.PaintEventArgs e)
            {
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;


                PolygonElement polygon = m_PolygonElement;

                polygon.close(m_CloseCheckBox.IsChecked);

                PolylineGeometry poly = new PolylineGeometry(polygon.Polygon, true, m_CloseCheckBox.IsChecked);

                BSplineGeometry bspline = new BSplineGeometry(poly);

                bspline.InterpolationStep = 1.0 / m_PointsNumberSlider.Value;


                e.Graphics.DrawGeometry(m_BSplinePen, bspline);


                base.OnPaint(e);
            }
Ejemplo n.º 8
0
        public void Draw(Document Doc, Page p)
        {
            Array.Resize <double>(ref xr, count);
            Array.Resize <double>(ref yr, count);
            PolylineGeometry cpoly;

            unsafe
            {
                double *xs = stackalloc double[count + 1];
                double *ys = stackalloc double[count + 1];

                for (int i = 0; i < count; i++)
                {
                    xs[i] = xr[i];
                    ys[i] = yr[i];
                }

                cpoly = new PolylineGeometry(count, xs, ys);
                PolylineOutline nes = new PolylineOutline(Doc, cpoly);
                nes.Page = p;
            }
        }
Ejemplo n.º 9
0
        protected override void OnPaint(GUI.PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;

            graphics.SmoothingMode   = SmoothingMode.AntiAlias;
            graphics.PixelOffsetMode = PixelOffsetMode.None;


            //  Polygon1
            PolygonElement polygon1 = m_PolygonElement1;

            PolylineGeometry path1 = new PolylineGeometry(polygon1.Polygon, true, false);

            BSplineGeometry bspline1 = new BSplineGeometry(path1);

            bspline1.InterpolationStep = 1.0 / m_PointsNumberSlider.Value;


            //  Polygon2
            PolygonElement polygon2 = m_PolygonElement2;

            PolylineGeometry path2 = new PolylineGeometry(polygon2.Polygon, true, false);

            BSplineGeometry bspline2 = new BSplineGeometry(path2);

            bspline1.InterpolationStep = 1.0 / m_PointsNumberSlider.Value;


            DoublePathTransform tcurve = new DoublePathTransform();

            tcurve.PreserveXScale = m_PreserveXScaleCheckBox.IsChecked;
            if (m_FixedLenCheckBox.IsChecked)
            {
                tcurve.BaseLength = 1140.0;
            }
            tcurve.AddPaths(bspline1, bspline2);

            Tuple <Geometry, double> geometry = GetCurveTransformedTextGeometry(tcurve.TotalLength1);

            tcurve.BaseHeight = FontAscentInPixels + geometry.Item2 + 3;

            GeometryTransformer ftrans = new GeometryTransformer(geometry.Item1, tcurve);

            if (m_FillCheckBox.IsChecked)
            {
                Brush brush = m_TextBrush;

                //  Irrlicht Renderer can't render smoothed gradients now
                if (graphics.RenderSystemName.Contains(Graphics.RSN_Irrlicht))
                {
                    if (m_TextBrush_Irrlicht == null)
                    {
                        m_TextBrush_Irrlicht = new SolidColorBrush(Color.LawnGreen);
                    }

                    brush = m_TextBrush_Irrlicht;
                }

                graphics.FillGeometry(brush, ftrans);
            }
            if (m_OutlineCheckBox.IsChecked)
            {
                graphics.DrawGeometry(Color.White, ftrans, m_OutlineThicknessSlider.Value);
            }


            graphics.DrawGeometry(m_BSplinePen, bspline1);
            graphics.DrawGeometry(m_BSplinePen, bspline2);


            base.OnPaint(e);
        }
Ejemplo n.º 10
0
        public static NFTask GetGeometry()
        {
            Msg("[Nesting Factory] Starting collect geometry...");

            ICollection <Area> EO       = Doc.GetAreas();
            IEnumerator <Area> GeomEnum = EO.GetEnumerator();

            GeomEnum.MoveNext();

            NFTask task = new NFTask();

            for (int area_num = 0; area_num < EO.Count; area_num++)
            {
                Area area = GeomEnum.Current;
                GeomEnum.MoveNext();
                Rectangle BoundBox = area.BoundRect;
                double    bound_x  = BoundBox.Left;
                double    bound_y  = BoundBox.Top;


                NFItem item = new NFItem(area.ObjectId.ToString());

                for (int num_contour = 0; num_contour < area.ContourCount; num_contour++)
                {
                    Contour   contour = area.GetContour(num_contour);
                    NFContour cont    = new NFContour();

                    for (int num_segment = 0; num_segment < contour.SegmentCount; num_segment++)
                    {
                        ContourSegment csegment = contour.GetSegment(num_segment);

                        switch (csegment.GeometryType)
                        {
                        case ObjectGeometryType.Line:
                            LineGeometry linegeom = csegment.Geometry as LineGeometry;
                            cont.AddPoint(new NFPoint(linegeom.X1 - bound_x, bound_y - linegeom.Y1, 0));
                            cont.AddPoint(new NFPoint(linegeom.X2 - bound_x, bound_y - linegeom.Y2, 0));
                            break;

                        /*case ObjectGeometryType.Polyline:
                         *
                         *  PolylineGeometry polygeom = csegment.Geometry as PolylineGeometry;
                         *  CircleArcGeometry[] cArcs = polygeom.GetCircleArcApproximation(2);
                         *
                         *  for (int i = 0; i < cArcs.GetLength(0); i++)
                         *  {
                         *      cArcToDoubles(cArcs[i], ref cont, BoundBox);
                         *  }
                         *  break;*/
                        case ObjectGeometryType.CircleArc:

                            CircleArcGeometry cgeom = csegment.Geometry as CircleArcGeometry;
                            cArcToDoubles(cgeom, ref cont, BoundBox, csegment.IsCounterclockwise);

                            break;

                        case ObjectGeometryType.Circle:
                            CircleGeometry cirgeom = csegment.Geometry as CircleGeometry;
                            cont.AddPoint(new NFPoint(cirgeom.CenterX + cirgeom.Radius - bound_x, bound_y - cirgeom.CenterY, 1));
                            cont.AddPoint(new NFPoint(cirgeom.CenterX - cirgeom.Radius - bound_x, bound_y - cirgeom.CenterY, 1));
                            break;

                        default:
                            PolylineGeometry polygeom = csegment.Geometry as PolylineGeometry;
                            int v_count = polygeom.Count;
                            for (int i = 0; i < v_count; i++)
                            {
                                if (v_count < 50 || i % (csegment.GeometryType == ObjectGeometryType.Ellipse ? 5 : 1) == 0 || i == v_count)
                                {
                                    cont.AddPoint(new NFPoint(polygeom.GetX(i) - bound_x, bound_y - polygeom.GetY(i), 0));
                                }
                            }
                            break;
                        }
                    }
                    item.AddContour(cont);
                }
                task.AddItem(item);
            }
            Msg("[Nesting Factory] Geometry collected");
            return(task);
        }
Ejemplo n.º 11
0
        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();
            }
        }
Ejemplo n.º 12
0
        public override void OnFrameworkInitializationCompleted()
        {
            if (this.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
            {
                JsonParser parser = new JsonParser();
                parser.populateWorldObjects(World.Instance, $"AutomatedCar.Assets.test_world.json");

                var world = World.Instance;

                StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly()
                                                       .GetManifestResourceStream($"AutomatedCar.Assets.worldobject_polygons.json"));
                string  json_text            = reader.ReadToEnd();
                dynamic stuff                = JObject.Parse(json_text);
                List <Avalonia.Point> points = new List <Avalonia.Point>();
                foreach (var i in stuff["objects"][0]["polys"][0]["points"])
                {
                    points.Add(new Avalonia.Point(i[0].ToObject <int>(), i[1].ToObject <int>()));
                }

                PolylineGeometry geom = new PolylineGeometry(points, false);

                int W = 108;
                int H = 240;

                List <List <Point> > polyList = new List <List <Point> >();
                polyList.Add(points);
                AutomatedCar controlledCar = new Models.AutomatedCar(0, 0, "car_1_white", W, H, polyList);

                controlledCar.RadarBrush  = new SolidColorBrush(Color.Parse("blue"));
                controlledCar.CameraBrush = new SolidColorBrush(Color.Parse("red"));

                List <Avalonia.Point> sensorPoints = new List <Avalonia.Point>();
                sensorPoints.Add(new Avalonia.Point(51, 239));
                sensorPoints.Add(new Avalonia.Point(200, 100));
                sensorPoints.Add(new Avalonia.Point(100, 300));

                List <Avalonia.Point> cameraSensorPoints = new List <Avalonia.Point>();
                cameraSensorPoints.Add(new Avalonia.Point(100, 200));
                cameraSensorPoints.Add(new Avalonia.Point(300, 200));
                cameraSensorPoints.Add(new Avalonia.Point(150, 300));

                controlledCar.RadarGeometry = new PolylineGeometry(sensorPoints, false);

                controlledCar.Geometry          = geom;
                controlledCar.RadarVisible      = true;
                controlledCar.UltraSoundVisible = true;

                controlledCar.CameraGeometry = new PolylineGeometry(cameraSensorPoints, false);
                controlledCar.CameraVisible  = true;

                world.AddObject(controlledCar);
                world.ControlledCar = controlledCar;
                controlledCar.Start();

                NpcCar npcCar = new NpcCar("car_1_red", W, H, polyList, $"AutomatedCar.Assets.npcCarRoute.json");
                npcCar.SetStartPosition();
                world.AddObject(npcCar);

                NpcPedestrian npcPedMan = new NpcPedestrian("man", W / 3, H / 3, polyList, $"AutomatedCar.Assets.npcPedRoute1.json");
                npcPedMan.SetStartPosition();
                world.AddObject(npcPedMan);

                NpcPedestrian npcPedWoman = new NpcPedestrian("woman", W / 3, H / 3, polyList, $"AutomatedCar.Assets.npcPedRoute2.json");
                npcPedWoman.SetStartPosition();
                world.AddObject(npcPedWoman);

                world.OnTick += npcCar.Move;
                world.OnTick += npcPedMan.Move;
                world.OnTick += npcPedWoman.Move;

                Game game = new Game(world);
                game.Start();

                desktop.MainWindow = new MainWindow {
                    DataContext = new MainWindowViewModel(world)
                };
            }

            base.OnFrameworkInitializationCompleted();
        }
Ejemplo n.º 13
0
        public static NFTask GetGeometry()
        {
            Msg("[Nesting Factory] Starting collect geometry...");

            ICollection <Area> Areas = Doc.GetAreas();

            NFTask task = new NFTask();

            foreach (var area in Areas)
            {
                Rectangle BoundBox = area.BoundRect;
                double    boundX   = BoundBox.Left;
                double    boundY   = BoundBox.Top;


                NFItem item = new NFItem(area.ObjectId.ToString());

                for (int num_contour = 0; num_contour < area.ContourCount; num_contour++)
                {
                    Contour   contour = area.GetContour(num_contour);
                    NFContour cont    = new NFContour();

                    foreach (var csegment in contour)
                    {
                        switch (csegment.GeometryType)
                        {
                        case ObjectGeometryType.Line:
                            LineGeometry linegeom = csegment.Geometry as LineGeometry;
                            cont.AddPoint(new NFPoint(linegeom.X1 - boundX, boundY - linegeom.Y1, 0));
                            cont.AddPoint(new NFPoint(linegeom.X2 - boundX, boundY - linegeom.Y2, 0));
                            break;

                        case ObjectGeometryType.CircleArc:
                            CircleArcGeometry cgeom = csegment.Geometry as CircleArcGeometry;
                            cArcToDoubles(cgeom, ref cont, BoundBox, csegment.IsCounterclockwise);
                            break;

                        case ObjectGeometryType.Circle:
                            CircleGeometry cirgeom = csegment.Geometry as CircleGeometry;
                            cont.AddPoint(new NFPoint(cirgeom.CenterX + cirgeom.Radius - boundX, boundY - cirgeom.CenterY, 1));
                            cont.AddPoint(new NFPoint(cirgeom.CenterX - cirgeom.Radius - boundX, boundY - cirgeom.CenterY, 1));
                            break;

                        default:
                            PolylineGeometry polygeom = csegment.Geometry as PolylineGeometry;
                            int v_count = polygeom.Count;
                            for (int i = 0; i < v_count; i++)
                            {
                                if (v_count < 50 || i % (csegment.GeometryType == ObjectGeometryType.Ellipse ? 5 : 1) == 0 || i == v_count)
                                {
                                    cont.AddPoint(new NFPoint(polygeom.GetX(i) - boundX, boundY - polygeom.GetY(i), 0));
                                }
                            }
                            break;
                        }
                    }
                    item.AddContour(cont);
                }
                task.AddItem(item);
            }
            Msg("[Nesting Factory] Geometry collected");
            return(task);
        }
Ejemplo n.º 14
0
        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();
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 解析指定的XML对象
        /// </summary>
        /// <param name="messageXML"></param>
        private void ParseXML(XmlReader xmlReader)
        {
            Geometry2D shape = null;

            switch (xmlReader.Name)
            {
            case "ArcGeometry":
                shape = new ArcGeometry();
                break;

            case "BeamGeometry":
                shape = new BeamGeometry();
                break;

            case "CircleGeometry":
                shape = new CircleGeometry();
                break;

            case "CSectionGeometry":
                shape = new CSectionGeometry();
                break;

            case "EllipseGeometry":
                shape = new EllipseGeometry();
                break;

            case "FloorGeometry":
                shape = new FloorGeometry();
                break;

            case "LineGeometry":
                shape = new LineGeometry();
                break;

            case "MeasureGeometry":
                shape = new MeasureGeometry();
                break;

            case "MemberGeometry":
                shape = new MemberGeometry();
                break;

            case "OSBGeometry":
                shape = new OSBGeometry();
                break;

            case "PointGeometry":
                shape = new PointGeometry();
                break;

            case "PolygonGeometry":
                shape = new PolygonGeometry();
                break;

            case "PolylineGeometry":
                shape = new PolylineGeometry();
                break;

            case "RectangleGeometry":
                shape = new RectangleGeometry();
                break;

            case "SteelBeamGeometry":
                shape = new SteelBeamGeometry();
                break;

            case "TextGeometry":
                shape = new TextGeometry();
                break;

            case "WallGeometry":
                shape = new WallGeometry();
                break;
            }

            if (shape != null)
            {
                //将信息写入数据流中
                shape.ReadXML(xmlReader);
                //将图形添加都界面上
                this.drawingKernel.AddShape(shape);
            }
        }