Example #1
0
        //Go through GPS setup
        private void GPSSetup_Click(object sender, RoutedEventArgs e)
        {
            //Handling case when the application is not connected to the server
            if (GPSServices.connectedToServer == false)
            {
                MessageBox.Show(Properties.Resources.MessageBox_GPS_ConnectionUnsuccessful);
                return;
            }

            //Handling case when no maps were added
            if (mapAdded == false)
            {
                MessageBox.Show(Properties.Resources.MessageBox_GPS_NoMap);
                return;
            }

            //Handling case when no teams were created
            if (Team.getTeamList().Count == 0)
            {
                MessageBox.Show(Properties.Resources.MessageBox_GPS_NoAssociation);
                return;
            }

            //Check if click was to cancel setup or start it
            if (GPSServices.setupOngoing == false)
            {
                //Create and populate list of registered teams
                List <Team> registeredTeams = new List <Team>();
                foreach (Team team in Team.getTeamList())
                {
                    if (team.getGPSLocation() != null)
                    {
                        registeredTeams.Add(team);
                    }
                }

                //Check if there is at least one team that is registered, it will be used for setup
                if (registeredTeams.Count != 0)
                {
                    GPSSetup_Button.Background = new SolidColorBrush(Colors.Red);
                    GPSSetup_Button.Foreground = new SolidColorBrush(Colors.White);
                    GPSServices.SetupGPSToMapTranslation_Start(mapSection, registeredTeams);
                }
                else
                {
                    MessageBox.Show(Properties.Resources.MessageBox_GPS_NoAssociation);
                }
            }
            else
            {
                GPSServices.setupOngoing = false;
                GPSSetup_Button.ClearValue(Button.BackgroundProperty);
                GPSSetup_Button.ClearValue(Button.ForegroundProperty);
                mapSection.Update();                 //Redrawing everything on the map
            }
        }
Example #2
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
            }
        }
Example #3
0
        //Override the default DragStop method to add functionality to it
        public override void DragStop(Canvas Canvas_map, MouseButtonEventArgs e)
        {
            //Merging teams
            if (parentPin != null && SufficientOverlap(parentPin)) //Want to merge
            {
                Team.removeSplitTeam(team);                        //Delete the fragment
                if (gpsLocation != null)
                {
                    gpsLocation.setTeamSplit(false);                     //Reactivationg gps
                }

                //Removing rogue arrows that might appear by movement of the teams or interventions while teams where split
                RemoveArrow();
                parentPin.RemoveArrow();
                if (interventionPin != null)
                {
                    interventionPin.RemoveArrow();
                }

                mapSection.Update();
            }

            //Identifying whether the user wants to split the team
            Intervention splitIntervention = null;

            if (team.getStatus().ToString().Equals("intervening"))
            {
                foreach (Pin pin in pinList)
                {
                    if (SufficientOverlap(pin) && pin.IsOfType("InterventionPin") && pin != interventionPin)
                    {
                        splitIntervention = ((InterventionPin)pin).getIntervention();
                        break;
                    }
                }
            }

            bool accidentalDrag = false;

            if (splitIntervention != null)
            {
                //Disabling GPS because of its unreliability when the team is split
                if (gpsLocation != null)
                {
                    gpsLocation.setTeamSplit(true);
                }

                //Creating team as a duplicate of the initial team, name it using the number of the intervention it is assigned to
                Team team2 = new Team(team);
                team2.setName(team.getName() + splitIntervention.getInterventionNumber());
                splitIntervention.AddInterveningTeam(team2); //Assigning split team onto the second intervention
                mapSection.Update();                         //Redrawing map so that the split team pin gets recreated with a pointer to the interventionPin it is assigned to
                return;
            }
            else if (interventionPin != null && interventionPin.getInterventionContainer() != null) //Handling the case when the team was in an intervention, choose between keeping it on the intervention (for an accidental drag-and-drop) or removing it from the intervention
            {
                if (SufficientOverlap(interventionPin.getInterventionContainer()))                  //Considered accidental drag-and-drop
                {
                    accidentalDrag = true;
                    interventionPin.getInterventionContainer().PlaceAll();
                }
                else //Remove team from intervention
                {
                    interventionPin.getIntervention().RemoveInterveningTeam(team);
                    interventionPin.SelectGPSLocation();
                    team.setStatus("unavailable");

                    //If it was the last team on that intervention and it has been removed, force redrawing of the map so that the InterventionContainer is removed
                    if (interventionPin.getInterveningTeamsPin().Count == 0)
                    {
                        mapSection.Update();
                        return;
                    }

                    interventionPin = null;
                }
            }
            else if (team.getStatus().ToString().Equals("available"))            //If the team was available and has been moved, set the team as moving
            {
                team.setStatus("moving");
            }

            base.DragStop(Canvas_map, e);

            //Handle situation when the TeamPin is tracked by GPS and the user moves it
            if (gpsLocation != null && GPSLocation.gpsConfigured == true && !accidentalDrag)
            {
                //Create and draw the arrow to the destination point and replace pin at current GPS position
                GPSPinDrop(GPSServices.connectedToServer && gpsLocation.PhoneOnline());
            }
        }