Exemple #1
0
        //Tag the point at which the team is
        private static void TagPoint_Click(object sender, RoutedEventArgs e)
        {
            MenuItem    mi      = (MenuItem)sender;
            ContextMenu cm      = (ContextMenu)mi.Parent;
            TeamPin     teamPin = (TeamPin)cm.PlacementTarget;

            GPSLocation.referencePoints.Add(new GPSLocation(teamPin.getTeam().getGPSLocation().getLattitude(), teamPin.getTeam().getGPSLocation().getLongitude(), teamPin.getX() * GPSLocation.xRatio, teamPin.getY() * GPSLocation.yRatio));
            MessageBox.Show("Point tagged");
            if (GPSLocation.referencePoints.Count == 2)
            {
                MessageBox.Show("Setup completed");

                GPSLocation.setConfigured(true);     //Change flag to signify that the setup is successfully done
                mapSection.Update();                 //Readding all the pins to the map
                setupOngoing = false;
                gpsStatusCallbacks.SetupCompleted(); //Notifying caller
            }
        }
Exemple #2
0
        //Called when team is picked for setup, prepare team pin for setup
        private static void ChooseTeamForSetup_Click(object sender, RoutedEventArgs e)
        {
            MenuItem    mi      = (MenuItem)sender;
            ContextMenu cm      = (ContextMenu)mi.Parent;
            TeamPin     teamPin = (TeamPin)cm.PlacementTarget;

            //Hiding all pins except the pin of the selected team, change its context menu for point tagging
            Pin.ClearAllPins(mapSection.Canvas_map);

            //Customizing the context menu for the exact use needed
            MenuItem tagPointMenuItem = new MenuItem();

            tagPointMenuItem.Header = "Tag point";
            tagPointMenuItem.Click += TagPoint_Click;

            ContextMenu contextMenu = new ContextMenu();

            contextMenu.Items.Add(tagPointMenuItem);
            teamPin.ContextMenu = contextMenu;

            //Replacing pin on the map for tagging
            mapSection.Canvas_map.Children.Add(teamPin);
            double[] previousPinPosition = Pin.getPreviousPinPosition(teamPin.getRelatedObject());
            if (previousPinPosition == null)
            {
                previousPinPosition = new double[] { teamPin.Width / 2, teamPin.Height / 2 };                 //Top-left corner
            }
            teamPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]);

            //Clearing the reference points in case the user is going through the setup again for any reason
            if (GPSLocation.gpsConfigured == true || GPSLocation.referencePoints.Count > 0)
            {
                GPSLocation.gpsConfigured = false;
                GPSLocation.referencePoints.Clear();
                MessageBox.Show("Previous setup is cleared. You can now proceed to re-setup the GPS");
            }

            MessageBox.Show("Team " + teamPin.getTeam().getName() + " selected. Please ask the team to position themselves at different locations of the site.\n"
                            + "As soon as they reach a particular location, wait at least 10 seconds and then tag the position by placing the team pin on the equivalent point on the map, right click on it, and select \"Tag point\".\n"
                            + "Only 2 points are required. For best results, have the points on two different sides of the map.\nSetup will complete as soon as the second point is tagged.");
        }
        //Callback when any of the observed objects modified i.e. creation and addition of all pins (including new pins, excluding deleted pins)
        public void Update()
        {
            Pin.ClearAllPins(Canvas_map);             //Clearing all pins from the map

            //Creating all team pins and adding the map to their previous or a new position while detecting newly created collisions
            foreach (Team team in Team.getTeamList())
            {
                TeamPin teamPin = new TeamPin(team, this);
                Canvas_map.Children.Add(teamPin);

                //Redrawing arrow if the pin has one
                if (Pin.getPinArrow(team) != null && GPSServices.connectedToServer && teamPin.gpsLocation.PhoneOnline())
                {
                    Pin.getPinArrow(team).DisplayArrow();
                }

                //Setting the pin to it's previous position, if it exists, or to the top-left corner
                bool     ignoreSpecialCollisions = false;
                double[] previousPinPosition     = Pin.getPreviousPinPosition(team);
                if (previousPinPosition == null)
                {
                    ignoreSpecialCollisions = true;
                    previousPinPosition     = new double[] { teamPin.Width / 2, teamPin.Height / 2 };                //Top-left corner
                }
                teamPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]);
                teamPin.CollisionDetectionAndResolution(ignoreSpecialCollisions);
            }

            //Creating team fragments when a team is split
            foreach (Team team in Team.getSplitTeamList())
            {
                TeamPin parentTeamPin = null;
                foreach (Team parentTeam in Team.getTeamList())
                {
                    if (team.getID() == parentTeam.getID())
                    {
                        foreach (Pin pin in Pin.getPinList())
                        {
                            if (pin.relatedObject == parentTeam)
                            {
                                parentTeamPin = (TeamPin)pin;
                                break;
                            }
                        }
                        break;
                    }
                }

                TeamPin teamPin = new TeamPin(team, this, parentTeamPin);
                Canvas_map.Children.Add(teamPin);

                //Setting the pin to it's previous position, if it exists, or to the top-left corner
                bool     ignoreSpecialCollisions = false;
                double[] previousPinPosition     = Pin.getPreviousPinPosition(team);
                if (previousPinPosition == null)
                {
                    ignoreSpecialCollisions = true;
                    previousPinPosition     = new double[] { teamPin.Width / 2, teamPin.Height / 2 }; //Top-left corner
                }
                teamPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]);
                teamPin.CollisionDetectionAndResolution(ignoreSpecialCollisions);
            }

            //Creating all intervention pins and adding the map to their previous or a new position while detecting newly created collisions
            foreach (Intervention intervention in Intervention.getActiveInterventionList())
            {
                InterventionPin interventionPin = new InterventionPin(intervention, this);
                Canvas_map.Children.Add(interventionPin);

                //Redrawing arrow if the pin has one
                if (Pin.getPinArrow(intervention) != null && GPSServices.connectedToServer && interventionPin.gpsLocation != null && interventionPin.gpsLocation.PhoneOnline())
                {
                    Pin.getPinArrow(intervention).DisplayArrow();
                }

                //Setting the pin to it's previous position, if it exists, or to the top-left corner
                bool     ignoreSpecialCollisions = false;
                double[] previousPinPosition     = Pin.getPreviousPinPosition(intervention);
                if (previousPinPosition == null)
                {
                    ignoreSpecialCollisions = true;
                    previousPinPosition     = new double[] { (interventionPin.Width / 2), Canvas_map.ActualHeight - (interventionPin.Height / 2) };                 //Bottom-right corner
                }
                interventionPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]);
                interventionPin.Update();
                interventionPin.CollisionDetectionAndResolution(ignoreSpecialCollisions);
            }

            //Creating all equipment pins and adding the map to their previous or a new position while detecting newly created collisions
            foreach (Equipment equipment in Equipment.getEquipmentList())
            {
                if (!equipment.IsAssigned())
                {
                    EquipmentPin equipmentPin = new EquipmentPin(equipment, this);
                    Canvas_map.Children.Add(equipmentPin);

                    //Setting the pin to it's previous position, if it exists, or to the top-left corner
                    bool     ignoreSpecialCollisions = true;
                    double[] previousPinPosition     = Pin.getPreviousPinPosition(equipment);
                    if (previousPinPosition == null)
                    {
                        previousPinPosition = new double[] { Canvas_map.ActualWidth - (equipmentPin.Width / 2), (equipmentPin.Height / 2) };                         //Top-right corner
                    }
                    equipmentPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]);
                    equipmentPin.CollisionDetectionAndResolution(ignoreSpecialCollisions);
                }
            }
        }