/// <summary>
        /// Find the shape that's closest to the mouse X,Y
        /// </summary>
        /// <param name="ScreenMouseX"></param>
        /// <param name="ScreenMouseY"></param>
        /// <returns></returns>
        ///
        protected Edge FindEdgeFromMouse(int ScreenMouseX, int ScreenMouseY)
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(null);
            }

            for (int i = 0; i < MostRecentlySelectedLayer.EdgeList.Count; i++)
            {
                Edge pe = MostRecentlySelectedLayer.EdgeList.GetFrom(i);

                // Find the center point of the edge

                PointF Center = MostRecentlySelectedLayer.EdgeCenter(pe);

                PointF CenterScreen = this.W2S(Center.X, Center.Y);

                double distance = Math.Sqrt(
                    (ScreenMouseX - CenterScreen.X) * (ScreenMouseX - CenterScreen.X) +
                    (ScreenMouseY - CenterScreen.Y) * (ScreenMouseY - CenterScreen.Y));

                if (distance < 10)
                {
                    return(pe);
                }
            }

            return(null);
        }
示例#2
0
        public void SelectEdgeByHoleGroupID(string HoleGroupID)
        {
            if (MostRecentlySelectedLayer == null)
            {
                return;
            }

            MostRecentlySelectedLayer.SelectEdgeByHoleGroupID(HoleGroupID);
        }
        public PointF?FindInsideIntersectionPoint(Edge peGreen, Edge peBlue)
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(null);
            }

            return(MostRecentlySelectedLayer.FindInsideIntersectionPoint(peGreen, peBlue));

#if false
            // We can see now if there is a common point. If there is a common point they don't intersect
            if (peGreen.p1 == peBlue.p1 ||
                peGreen.p1 == peBlue.p2 ||
                peGreen.p2 == peBlue.p1 ||
                peGreen.p2 == peBlue.p2)
            {
                // no intersection, there is a common point
                return(null);
            }

            Vertex GreenFrom = FindVertexFromIndex(peGreen.p1);
            Vertex GreenTo   = FindVertexFromIndex(peGreen.p2);

            Vertex BlueFrom = FindVertexFromIndex(peBlue.p1);
            Vertex BlueTo   = FindVertexFromIndex(peBlue.p2);

            /*
             * Are they parallel?
             */

            float par = (float)((GreenTo.X - GreenFrom.X) * (BlueTo.Y - BlueFrom.Y) -
                                (GreenTo.Y - GreenFrom.Y) * (BlueTo.X - BlueFrom.X));

            if (par == 0)
            {
                return(null);                               /* parallel lines */
            }

            /*
             * Find the proportional distance from one point to another
             */
            float tp = ((BlueFrom.X - GreenFrom.X) * (BlueTo.Y - BlueFrom.Y) - (BlueFrom.Y - GreenFrom.Y) * (BlueTo.X - BlueFrom.X)) / par;
            float tq = ((GreenTo.Y - GreenFrom.Y) * (BlueFrom.X - GreenFrom.X) - (GreenTo.X - GreenFrom.X) * (BlueFrom.Y - GreenFrom.Y)) / par;

            /*
             * If the distance isn't between 0 and 1 the segments don't intersect
             */
            if (tp < 0 || tp > 1 || tq < 0 || tq > 1)
            {
                return(null);
            }

            return(new PointF(GreenFrom.X + tp * (GreenTo.X - GreenFrom.X), GreenFrom.Y + tp * (GreenTo.Y - GreenFrom.Y)));
#endif
        }
示例#4
0
        public PointF EdgeP1(Edge oEdge)
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(new PointF(0, 0));
            }

            return(MostRecentlySelectedLayer.EdgeP1(oEdge));

            //return new PointF(0, 0);
        }
示例#5
0
        public eOperationStatus MoveCurrentEdgeByScreenDelta(int ScreenDeltaX, int ScreenDeltaY)
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(eOperationStatus.NoLayerSelected);
            }

            int WorldDeltaX = (int)((float)ScreenDeltaX * this.CurrentZoom);
            int WorldDeltaY = (int)((float)ScreenDeltaY * this.CurrentZoom);

            return(MostRecentlySelectedLayer.MoveCurrentEdgeByWorldDelta(WorldDeltaX, WorldDeltaY));
        }
        // Flip p1 and p2, effectively changing what direction is considered the 'front' for purposes of placing holes

        public void FlipMostRecentlySelectedEdge()
        {
            if (MostRecentlySelectedLayer == null)
            {
                return;
            }

            MostRecentlySelectedLayer.FlipMostRecentlySelectedEdge();
#if false
            int tmp = MostRecentlySelectedEdge.p1;
            MostRecentlySelectedEdge.p1 = MostRecentlySelectedEdge.p2;
            MostRecentlySelectedEdge.p2 = tmp;
#endif

            DrawShapes();
        }
示例#7
0
        public eOperationStatus AppendEdge(int Width, int Height, int DeltaX, int DeltaY)
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(eOperationStatus.NoLayerSelected);
            }

            eOperationStatus sts = MostRecentlySelectedLayer.AppendEdge(Width, Height, DeltaX, DeltaY);

            if (sts != eOperationStatus.OK)
            {
                return(sts);
            }
#if false
            if (MostRecentlySelectedVertex == null)
            {
                return(eOperationStatus.NoVertexSelected);
            }

            // Add a new point
            int nextindex = FindNextIndex();

            Vertex vP = new Vertex();
            vP.Index = nextindex;
            vP.X     = MostRecentlySelectedVertex.X + DeltaX;
            vP.Y     = MostRecentlySelectedVertex.Y + DeltaY;
            VertexList.Add(vP);

            // Add an edge

            Edge oEdge = new Edge();
            oEdge.Height      = Height;
            oEdge.Width       = Width;
            oEdge.p1          = MostRecentlySelectedVertex.Index;
            oEdge.p2          = vP.Index;
            oEdge.ID          = "";
            oEdge.HoleGroupID = "";

            EdgeList.Add(oEdge);
#endif

            // Redraw shapes
            DrawShapes();

            return(eOperationStatus.OK);
        }
示例#8
0
        public eOperationStatus AddHoleInMostRecentlySelectedEdge(int Width)
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(eOperationStatus.NoLayerSelected);
            }

            eOperationStatus sts = MostRecentlySelectedLayer.AddHoleInMostRecentlySelectedEdge(Width);

            if (sts != eOperationStatus.OK)
            {
                return(sts);
            }

            // trigger redraw
            DrawShapes();

            return(eOperationStatus.OK);
        }
示例#9
0
        public eOperationStatus UnMergeMostRecentlySelectedHandle()
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(eOperationStatus.NoLayerSelected);
            }

            eOperationStatus sts = MostRecentlySelectedLayer.UnMergeMostRecentlySelectedHandle();

            if (sts != eOperationStatus.OK)
            {
                return(sts);
            }

            // trigger a redraw
            DrawShapes();

            return(eOperationStatus.OK);
        }
        public eOperationStatus SplitMostRecentlySelectedEdge(float RelativeDistance)
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(eOperationStatus.NoLayerSelected);
            }

            eOperationStatus sts = MostRecentlySelectedLayer.SplitMostRecentlySelectedEdge(RelativeDistance);

            if (sts != eOperationStatus.OK)
            {
                return(sts);
            }


            // trigger redraw
            DrawShapes();

            return(eOperationStatus.OK);
        }
示例#11
0
        // Add a new line into the simple layout struct, new vertices and a new edge

        public eOperationStatus AddEdge(PointF WorldFrom, PointF WorldTo, int Width, int Height)
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(eOperationStatus.NoLayerSelected);
            }

            MostRecentlySelectedLayer.AddEdge(WorldFrom, WorldTo, Width, Height);

#if false
            int nextindex = FindNextIndex();

            Vertex vP1 = new Vertex();
            vP1.Index = nextindex++;
            vP1.X     = WorldFrom.X;
            vP1.Y     = WorldFrom.Y;
            VertexList.Add(vP1);

            Vertex vP2 = new Vertex();
            vP2.Index = nextindex++;
            vP2.X     = WorldTo.X;
            vP2.Y     = WorldTo.Y;
            VertexList.Add(vP2);

            // Now add a segment

            Edge oEdge = new Edge();
            oEdge.Height      = 30;
            oEdge.Width       = 10;
            oEdge.p1          = vP1.Index;
            oEdge.p2          = vP2.Index;
            oEdge.ID          = "";
            oEdge.HoleGroupID = "";

            EdgeList.Add(oEdge);
#endif
            // redraw shapes
            DrawShapes();

            return(eOperationStatus.OK);
        }
示例#12
0
        public eOperationStatus DeleteCurrentEdge()
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(eOperationStatus.NoLayerSelected);
            }

            eOperationStatus sts = MostRecentlySelectedLayer.DeleteCurrentEdge();

            if (sts != eOperationStatus.OK)
            {
                return(sts);
            }


            // Trigger redraw

            DrawShapes();

            return(eOperationStatus.OK);
        }
        public eOperationStatus DeleteSelectedVertex()
        {
            if (MostRecentlySelectedLayer == null)
            {
                return(eOperationStatus.NoLayerSelected);
            }

            // If there is not a most recently selected handle return

            eOperationStatus sts = MostRecentlySelectedLayer.DeleteSelectedVertex();

            if (sts != eOperationStatus.OK)
            {
                return(sts);
            }

#if false
            if (MostRecentlySelectedVertex == null)
            {
                return(eOperationStatus.NoVertexSelected);
            }

            /*
             * This vertex must have exactly two different edges coming into it
             */
            int         ReferenceCount     = 0;
            List <Edge> ConnectingEdgeList = new List <Edge>();

            for (int i = 0; i < EdgeList.Count; i++)
            {
                Edge oEdge = EdgeList.GetFrom(i);
                if (oEdge.p1 == MostRecentlySelectedVertex.Index)
                {
                    ReferenceCount++;
                    ConnectingEdgeList.Add(oEdge);
                }
                if (oEdge.p2 == MostRecentlySelectedVertex.Index)
                {
                    ReferenceCount++;
                    ConnectingEdgeList.Add(oEdge);
                }
            }

            if (ReferenceCount != 2)
            {
                return(eOperationStatus.MustBeTwoConnectingEdgesForOperation);
            }

            // Get the from and to points of the remade edge
            int NewP1 = -1;
            int NewP2 = -1;

            Edge oEdge0 = ConnectingEdgeList.GetFrom(0);
            if (oEdge0.p1 == MostRecentlySelectedVertex.Index)
            {
                NewP1 = oEdge0.p2;
            }
            else
            {
                NewP1 = oEdge0.p1;
            }

            Edge oEdge1 = ConnectingEdgeList.GetFrom(1);
            if (oEdge1.p2 == MostRecentlySelectedVertex.Index)
            {
                NewP2 = oEdge1.p1;
            }
            else
            {
                NewP2 = oEdge1.p2;
            }

            // Replace the p1 and p2 in the 0th edge and delete the 1th edge. We know that the current handle
            // will be redundant so we can delete it.

            oEdge0.p1 = NewP1;
            oEdge0.p2 = NewP2;

            // delete the current handle, it the one we're removing
            for (int i = 0; i < VertexList.Count; i++)
            {
                Vertex v = VertexList.GetFrom(i);
                if (v.Index == MostRecentlySelectedVertex.Index)
                {
                    VertexList.RemoveAt(i);
                    break;
                }
            }

            // Delete the 1th edge.

            for (int i = 0; i < EdgeList.Count; i++)
            {
                Edge e = EdgeList.GetFrom(i);
                if (e == oEdge1)
                {
                    EdgeList.RemoveAt(i);
                    break;
                }
            }
#endif

            // trigger redraw
            DrawShapes();

            return(eOperationStatus.OK);
        }
示例#14
0
        public void SplitEdgesAtIntersection()
        {
            if (MostRecentlySelectedLayer == null)
            {
                return;
            }

            MostRecentlySelectedLayer.SplitEdgesAtIntersection();

#if false
            // Set a tolerence of the thinnest edge.

            bool ThereAreSplits = true;

            while (ThereAreSplits)
            {
                ThereAreSplits = false;

                for (int i = 0; i < EdgeList.Count && ThereAreSplits == false; i++)
                {
                    Edge S1 = EdgeList.GetFrom(i);

                    for (int j = i + 1; j < EdgeList.Count && ThereAreSplits == false; j++)
                    {
                        Edge   S2 = EdgeList.GetFrom(j);
                        PointF?p  = FindInsideIntersectionPoint(S1, S2);

                        if (p != null)
                        {
                            // Add this as a new vertex
                            Vertex vNew = new Vertex();
#if DOTNET
                            vNew.X = p.Value.X;
                            vNew.Y = p.Value.Y;
#else
                            vNew.X = p.X;
                            vNew.Y = p.Y;
#endif
                            vNew.Index = FindNextIndex();
                            VertexList.Add(vNew);
                            // TBD make sure its not too close to an existing point

                            // Create two new segments with the intersection as the 'from' point.

                            Edge pe1 = new Edge();
                            pe1.Width       = S1.Width;
                            pe1.Height      = S1.Height;
                            pe1.ID          = "";       // new segment, remove any id
                            pe1.HoleGroupID = "";       // new segment don't try to bring holes over
                            pe1.p1          = vNew.Index;
                            pe1.p2          = S1.p2;
                            EdgeList.Add(pe1);

                            Edge pe2 = new Edge();
                            pe2.Width       = S1.Width;
                            pe2.Height      = S1.Height;
                            pe2.ID          = "";       // new segment, remove any id
                            pe2.HoleGroupID = "";       // new segment don't try to bring holes over
                            pe2.p1          = vNew.Index;
                            pe2.p2          = S2.p2;
                            EdgeList.Add(pe2);

                            // Truncate the existing segments to the new point

                            S1.p2 = vNew.Index;
                            S2.p2 = vNew.Index;

                            // Indicate that there are splits so that the list can be reprocessed

                            ThereAreSplits = true;
                        }
                    }
                }
            }
#endif

            // Trigger redraw of shapes
            DrawShapes();
        }