Exemple #1
0
        private void Picture_Click(object sender, System.EventArgs e)
        {
            if (AddNewMarker == true)
            {
                // Disable adding anymore markers
                // AddNewMarker = false; // Commented out so that you can add many markers
                MouseEventArgs mouseEventArgs = e as MouseEventArgs;
                if (mouseEventArgs != null)
                {
                    Create_Marker(mouseEventArgs);
                }
            }
            else if (AddNewConnector == true)
            {
                MouseEventArgs mouseEventArgs = e as MouseEventArgs;
                Marker         candidate      = new Marker();
                double         smallestLength = 0;
                for (int i = 0; i < PointContainers.Markers.Count; i++)
                {
                    if (candidate.ID == null)
                    {
                        int    xDiff  = mouseEventArgs.X - PointContainers.Markers[i].X;
                        int    yDiff  = mouseEventArgs.Y - PointContainers.Markers[i].Y;
                        double length = Math.Sqrt(Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2));
                        if (length < 15 / 2)
                        {
                            candidate                 = PointContainers.Markers[i];
                            smallestLength            = length;
                            theChosenMarkerIndexes[0] = i;
                        }
                    }
                    else
                    {
                        int    xDiff  = mouseEventArgs.X - PointContainers.Markers[i].X;
                        int    yDiff  = mouseEventArgs.Y - PointContainers.Markers[i].Y;
                        double length = Math.Sqrt(Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2));
                        if (length < smallestLength)
                        {
                            candidate                 = PointContainers.Markers[i];
                            smallestLength            = length;
                            theChosenMarkerIndexes[0] = i;
                        }
                    }
                }

                if (candidate.ID != null)
                {
                    theChosenMarker = candidate;
                }
                else
                {
                    return;
                }

                AddNewConnector      = false; // Comment out to add many connectors
                DraggingNewConnector = true;
                ConnectorPoint1      = new Point(mouseEventArgs.X, mouseEventArgs.Y);
            }
            else if (RunLogistics == true)
            {
                MouseEventArgs mouseEventArgs = e as MouseEventArgs;
                Marker         candidate      = new Marker();
                double         smallestLength = 0;
                for (int i = 0; i < PointContainers.Markers.Count; i++)
                {
                    if (candidate.ID == null)
                    {
                        int    xDiff  = mouseEventArgs.X - PointContainers.Markers[i].X;
                        int    yDiff  = mouseEventArgs.Y - PointContainers.Markers[i].Y;
                        double length = Math.Sqrt(Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2));
                        if (length < 15 / 2)
                        {
                            candidate                 = PointContainers.Markers[i];
                            smallestLength            = length;
                            theChosenMarkerIndexes[0] = i;
                        }
                    }
                    else
                    {
                        int    xDiff  = mouseEventArgs.X - PointContainers.Markers[i].X;
                        int    yDiff  = mouseEventArgs.Y - PointContainers.Markers[i].Y;
                        double length = Math.Sqrt(Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2));
                        if (length < smallestLength)
                        {
                            candidate                 = PointContainers.Markers[i];
                            smallestLength            = length;
                            theChosenMarkerIndexes[0] = i;
                        }
                    }
                }

                if (candidate.ID != null)
                {
                    theChosenMarker = candidate;
                }
                else
                {
                    return;
                }

                RunLogistics         = false;
                chosenLogisticsStart = true;
                Draw_Marker(candidate.X, candidate.Y, Color.Yellow);
            }
            else if (chosenLogisticsStart == true)
            {
                MouseEventArgs mouseEventArgs = e as MouseEventArgs;
                Marker         candidate      = new Marker();
                double         smallestLength = 0;
                for (int i = 0; i < PointContainers.Markers.Count; i++)
                {
                    if (candidate.ID == null)
                    {
                        int    xDiff  = mouseEventArgs.X - PointContainers.Markers[i].X;
                        int    yDiff  = mouseEventArgs.Y - PointContainers.Markers[i].Y;
                        double length = Math.Sqrt(Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2));
                        if (length < 15 / 2)
                        {
                            candidate      = PointContainers.Markers[i];
                            smallestLength = length;
                        }
                    }
                    else
                    {
                        int    xDiff  = mouseEventArgs.X - PointContainers.Markers[i].X;
                        int    yDiff  = mouseEventArgs.Y - PointContainers.Markers[i].Y;
                        double length = Math.Sqrt(Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2));
                        if (length < smallestLength)
                        {
                            candidate      = PointContainers.Markers[i];
                            smallestLength = length;
                        }
                    }
                }

                if (candidate.ID != null)
                {
                }
                else
                {
                    return;
                }

                chosenLogisticsStart = false;
                Draw_Marker(candidate.X, candidate.Y, Color.Yellow);
                LogisticsRun(theChosenMarker.ID, candidate.ID);
            }
        }
Exemple #2
0
        private void Picture_Release(object sender, System.EventArgs e)
        {
            if (DraggingNewConnector == false)
            {
                return;
            }


            MouseEventArgs mouseEventArgs = e as MouseEventArgs;
            Marker         candidate      = new Marker();
            double         smallestLength = 0;

            for (int i = 0; i < PointContainers.Markers.Count; i++)
            {
                if (candidate.ID == null)
                {
                    int    xDiff  = mouseEventArgs.X - PointContainers.Markers[i].X;
                    int    yDiff  = mouseEventArgs.Y - PointContainers.Markers[i].Y;
                    double length = Math.Sqrt(Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2));
                    if (length < 15 / 2)
                    {
                        candidate                 = PointContainers.Markers[i];
                        smallestLength            = length;
                        theChosenMarkerIndexes[1] = i;
                        Console.WriteLine("Adding New Candidate");
                    }
                }
                else
                {
                    int    xDiff  = mouseEventArgs.X - PointContainers.Markers[i].X;
                    int    yDiff  = mouseEventArgs.Y - PointContainers.Markers[i].Y;
                    double length = Math.Sqrt(Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2));
                    if (length < smallestLength)
                    {
                        candidate                 = PointContainers.Markers[i];
                        smallestLength            = length;
                        theChosenMarkerIndexes[1] = i;
                        Console.WriteLine("Overwriting Candidate");
                    }
                }
            }

            if (candidate.ID == null)
            {
                Console.WriteLine("Candidate is NULL");
                return;
            }

            AddNewConnector      = true; // Comment out to not add many connectors at a time
            DraggingNewConnector = false;
            //bool addNewConnection = true;
            for (int i = 0; i < PointContainers.Markers[theChosenMarkerIndexes[0]].ConnectedTo.Count; i++)
            {
                if (PointContainers.Markers[theChosenMarkerIndexes[0]].ConnectedTo[i] == PointContainers.Markers[theChosenMarkerIndexes[1]].ID)
                {
                    //addNewConnection = false;
                    return;
                }
            }

            Point p1 = new Point();
            Point p2 = new Point();

            p1.X = PointContainers.Markers[theChosenMarkerIndexes[0]].X;
            p1.Y = PointContainers.Markers[theChosenMarkerIndexes[0]].Y;
            p2.X = PointContainers.Markers[theChosenMarkerIndexes[1]].X;
            p2.Y = PointContainers.Markers[theChosenMarkerIndexes[1]].Y;
            Point difVector = new Point();

            difVector.X = p1.X - p2.X;
            difVector.Y = p1.Y - p2.Y;

            if (difVector.X != 0 && difVector.Y != 0)
            {
                double magnitude = Math.Sqrt(Math.Pow(difVector.X, 2) + Math.Pow(difVector.Y, 2));
                double unitX     = difVector.X / magnitude;
                double unitY     = difVector.Y / magnitude;
                Point  sP1       = new Point();
                Point  sP2       = new Point();
                sP1.X = Convert.ToInt32(p1.X - unitX * (15 / 2));
                sP1.Y = Convert.ToInt32(p1.Y - unitY * (15 / 2));
                sP2.X = Convert.ToInt32(p2.X + unitX * (15 / 2));
                sP2.Y = Convert.ToInt32(p2.Y + unitY * (15 / 2));

                PointContainers.Markers[theChosenMarkerIndexes[0]].ConnectedTo.Add(PointContainers.Markers[theChosenMarkerIndexes[1]].ID);
                PointContainers.Markers[theChosenMarkerIndexes[1]].ConnectedTo.Add(PointContainers.Markers[theChosenMarkerIndexes[0]].ID);

                Draw_Line(sP1.X, sP1.Y, sP2.X, sP2.Y, Color.Red);
            }
        }