Exemple #1
0
        // Add a polygon. This is managed with a simplelayout object
        public void AddPolygon(int ScreenOffsetX, int ScreenOffsetY, int InitialSides, int Radius)
        {
            if (MostRecentlySelectedHoleGroup == null)
            {
                return;
            }

            BoundaryPolygon oPolygon = new BoundaryPolygon();

            oPolygon.PointList = new Point3D[InitialSides];

            float Angle      = 0;
            float AngleDelta = (float)Math.PI * 2 / InitialSides;

            for (int i = 0; i < InitialSides; i++)
            {
                Point3D p = new Point3D();
#if DOTNET
                float x = (float)Math.Cos(Angle) * Radius;
                float y = (float)Math.Sin(Angle) * Radius;
#else
                float x = (float)Math.cos(Angle) * Radius;
                float y = (float)Math.sin(Angle) * Radius;
#endif
                p.X = x;
                p.Y = y;

                oPolygon.PointList[i] = p;

                Angle += AngleDelta;
            }

            /*
             * Create a hole and boundary polygon object
             */
            PointF     WorldOffset = this.S2W(ScreenOffsetX, ScreenOffsetY);
            LayoutHole oHole       = new LayoutHole();
            oHole.HoleType      = "poly";
            oHole.HoleTypeIndex = BoundaryPolygonList.Count;
            oHole.OffsetX       = WorldOffset.X;
            oHole.OffsetY       = WorldOffset.Y;

            AddHoleToHoleGroup(MostRecentlySelectedHoleGroup, oHole);

            CurrentlySelectedHole    = oHole;
            MostRecentlySelectedHole = oHole;

            BoundaryPolygonList.Add(oPolygon);

            // trigger redraw

            DrawShapes();
        }
        public void DuplicateCurrentHole()
        {
            if (MostRecentlySelectedHole == null)
            {
                return;
            }

            LayoutHole oHole = LayoutHole.CopyFrom(MostRecentlySelectedHole);

            // Add at an offset so it will be easy to see
            oHole.OffsetX += 10;
            oHole.OffsetY += 10;

            // Create a new version of the instance of the hole

            int ndx = MostRecentlySelectedHole.HoleTypeIndex;

            switch (MostRecentlySelectedHole.HoleType)
            {
            case "ell":
                oHole.HoleTypeIndex = BoundaryEllipseList.Count;
                BoundaryEllipse e = BoundaryEllipseList.GetFrom(ndx);
                BoundaryEllipseList.Add(BoundaryEllipse.CopyFrom(e));
                break;

            case "rect":
                oHole.HoleTypeIndex = BoundaryRectangleList.Count;
                BoundaryRectangle r = BoundaryRectangleList.GetFrom(ndx);
                BoundaryRectangleList.Add(BoundaryRectangle.CopyFrom(r));
                break;

            case "poly":
                oHole.HoleTypeIndex = BoundaryPolygonList.Count;
                BoundaryPolygon p = BoundaryPolygonList.GetFrom(ndx);
                BoundaryPolygonList.Add(BoundaryPolygon.CopyFrom(p));
                break;
            }

            // Add the new hole to the hole group
            AddHoleToHoleGroup(MostRecentlySelectedHoleGroup, oHole);

            // trigger a repaint
            DrawShapes();
        }