예제 #1
0
        //Translate the GPS coordinates to X-Y Map coordinates, via X-Y Image coordinates
        private void TranslatePointToMap()
        {
            //Handling case when the current position is equal to the reference position
            if (lattitude == referencePoints.ElementAt(0).getLattitude() && longitude == referencePoints.ElementAt(0).getLongitude())
            {
                X = referencePoints.ElementAt(0).getX() / xRatio;
                Y = referencePoints.ElementAt(0).getY() / yRatio;
                return;
            }

            //Getting all the necessary lengths in order to get the triangle angles using them
            double distanceA = GPSServices.CalculateGPSDistance(referencePoints.ElementAt(1).getLattitude(), referencePoints.ElementAt(1).getLongitude(), lattitude, longitude);
            double distanceB = GPSServices.CalculateGPSDistance(referencePoints.ElementAt(0).getLattitude(), referencePoints.ElementAt(0).getLongitude(), lattitude, longitude);
            double distanceC = GPSServices.CalculateGPSDistance(referencePoints.ElementAt(0).getLattitude(), referencePoints.ElementAt(0).getLongitude(), referencePoints.ElementAt(1).getLattitude(), referencePoints.ElementAt(1).getLongitude());

            //Getting distance ratio
            double distanceRatio = distanceB / distanceC;

            //Getting all the angles of the triangle formed by the reference point 0, reference point 1, and the current team position
            double angleA = Math.Acos(((distanceB * distanceB) + (distanceC * distanceC) - (distanceA * distanceA)) / (2 * distanceB * distanceC));

            //Find vector between reference points
            double dx = referencePoints.ElementAt(1).getX() - referencePoints.ElementAt(0).getX();
            double dy = referencePoints.ElementAt(1).getY() - referencePoints.ElementAt(0).getY();

            //Scaling the vector so that it has the appropriate length
            double dxScaled = dx * distanceRatio;
            double dyScaled = dy * distanceRatio;

            //Determining if the point is in the clockwise or anti-clockwise direction of the reference line
            double referenceBearing = GPSServices.CalculateGPSBearing(referencePoints.ElementAt(0).getLattitude(), referencePoints.ElementAt(0).getLongitude(), referencePoints.ElementAt(1).getLattitude(), referencePoints.ElementAt(1).getLongitude());
            double actualBearing    = GPSServices.CalculateGPSBearing(referencePoints.ElementAt(0).getLattitude(), referencePoints.ElementAt(0).getLongitude(), lattitude, longitude);

            if (referenceBearing < 180)
            {
                if (actualBearing < referenceBearing || actualBearing > (referenceBearing + 180))
                {
                    angleA = -angleA;                     //Changing direction of rotation
                }
            }
            else
            {
                if (actualBearing < referenceBearing && actualBearing > (referenceBearing - 180))
                {
                    angleA = -angleA;                     //Changing direction of rotation
                }
            }

            //Rotate vector to get the vector that start at the first reference point and ends at the current location of the team
            double dxPrime = (dxScaled * Math.Cos(angleA)) - (dyScaled * Math.Sin(angleA));
            double dyPrime = (dxScaled * Math.Sin(angleA)) + (dyScaled * Math.Cos(angleA));

            //Getting the final image coordinates of the point at which the team is
            double xImage = referencePoints.ElementAt(0).getX() + dxPrime;
            double yImage = referencePoints.ElementAt(0).getY() + dyPrime;

            //Translating the image coordinates into map coordinates with the generated ratios
            X = xImage / xRatio;
            Y = yImage / yRatio;
        }
예제 #2
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
            }
        }
예제 #3
0
        public MainWindow()
        {
            InitializeComponent();

            //only attach SelectionChanged event here to avoid the culture being updated twice
            ComboBox_Languages.SelectedItem           = Properties.Settings.Default.DefaultCulture.NativeName;
            this.ComboBox_Languages.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.ComboBox_Languages_SelectionChanged);

            FormPopup.RegisterMainWindow(this);//Register main window as the master window, used for displaying popups
            followupSection        = new FollowUpSectionForm();
            shiftSection           = new ShiftsSection();
            mapModificationSection = new AdditionalInfoPage(this);
            teamsSection           = new TeamsSectionPage(this);
            mapSection             = new MapSectionPage(this, mapModificationSection);
            interventionsSection   = new InterventionSectionPage(this);

            previousWidth  = MapSection.ActualWidth;
            previousHeight = MapSection.ActualHeight;

            //Populating the Map modification section
            Frame AIFrame = new Frame();

            AIFrame.Content  = mapModificationSection;
            AIPSection.Child = AIFrame;


            //Populating the Teams section
            Frame teamsFrame = new Frame();

            teamsFrame.Content = teamsSection;
            TeamsSection.Child = teamsFrame;

            //Populating the Map section
            Frame mapFrame = new Frame();

            mapFrame.Content = mapSection;
            MapSection.Child = mapFrame;

            //Populating the Interventions section
            Frame interventionsFrame = new Frame();

            interventionsFrame.Content = interventionsSection;
            InterventionsSection.Child = interventionsFrame;

            //Starting GPS Services tasks
            GPSServices.StartServices(this);
        }
예제 #4
0
        public GPSAssignment(MainWindow caller)
        {
            this.caller            = caller;
            teamList               = Team.getTeamList();
            gpsLocationsDictionary = GPSLocation.getDictionary();
            int row = 0;

            InitializeComponent();

            foreach (Team t in teamList)
            {
                Label teamName = new Label();
                teamName.Content = t.getName();
                Grid.SetRow(teamName, row);
                Grid.SetColumn(teamName, 0);

                teamGrid.Children.Add(teamName);

                ComboBox combo   = new ComboBox();
                String   forName = row.ToString();
                //combo.Name = forName;
                Grid.SetRow(combo, row);
                Grid.SetColumn(combo, 1);

                List <TeamMember> tempList = new List <TeamMember>();
                tempList = t.getMemberList();

                volunteerList = GPSServices.getUsers();

                foreach (KeyValuePair <string, string> entry in volunteerList)
                {
                    combo.Items.Add(entry.Value);
                }

                combo.Items.Add(" ");

                teamGrid.Children.Add(combo);


                if (t.getGPSLocation() != null)
                {
                    int tempIndex = 0;

                    foreach (KeyValuePair <string, GPSLocation> entry in gpsLocationsDictionary)
                    {
                        if (entry.Value.id == t.getGPSLocation().id)
                        {
                            foreach (KeyValuePair <string, string> ID in volunteerList)
                            {
                                if (entry.Key == ID.Key)
                                {
                                    combo.SelectedIndex = tempIndex;
                                }

                                tempIndex++;
                            }
                        }
                    }
                }
                row++;
            }
        }