void OnManagerActivityProfileChanged(GarminActivityProfile profileChanged, System.ComponentModel.PropertyChangedEventArgs changedProperty)
 {
     if (ProfileChanged != null)
     {
         ProfileChanged(this, new PropertyChangedEventArgs("ActivityProfile"));
     }
 }
        public SetupWizardEditProfileControl(ExtendedWizard wizard)
            : base(wizard)
        {
            InitializeComponent();

            GarminActivityBanner.ThemeChanged(PluginMain.GetApplication().VisualTheme);
            HRZonesTreeList.ThemeChanged(PluginMain.GetApplication().VisualTheme);
            SpeedZonesTreeList.ThemeChanged(PluginMain.GetApplication().VisualTheme);

            GarminProfileManager.Instance.ProfileChanged += new GarminProfileManager.ProfileChangedEventHandler(OnProfileChanged);
            GarminProfileManager.Instance.ActivityProfileChanged += new GarminProfileManager.ActivityProfileChangedEventHandler(OnActivityProfileChanged);

            m_CurrentCategory = GarminCategories.Running;
            m_CurrentProfile = GarminProfileManager.Instance.GetProfileForActivity(m_CurrentCategory);

            BuildTreeLists();
            RefreshProfileInfo();
            RefreshUIFromCategory();

            ExplanationLabel.Text = GarminFitnessView.GetLocalizedString("EditProfileExplanationText");
            BirthDateTimePicker.CustomFormat = CultureInfo.CreateSpecificCulture(GarminFitnessView.UICulture.Name).DateTimeFormat.ShortDatePattern;

            // User data
            ProfileNameLabel.Text = GarminFitnessView.GetLocalizedString("NameLabelText");
            GenderLabel.Text = GarminFitnessView.GetLocalizedString("GenderLabelText");
            MaleRadioButton.Text = GarminFitnessView.GetLocalizedString("MaleText");
            FemaleRadioButton.Text = GarminFitnessView.GetLocalizedString("FemaleText");
            WeightLabel.Text = GarminFitnessView.GetLocalizedString("WeightLabelText");
            WeightUnitLabel.Text = Weight.LabelAbbr(PluginMain.GetApplication().SystemPreferences.WeightUnits);
            BirthDateLabel.Text = GarminFitnessView.GetLocalizedString("BirthDateLabelText");
            RestingHeartRateLabel.Text = GarminFitnessView.GetLocalizedString("RestingHeartRateLabelText");
            RestBPMLabel.Text = CommonResources.Text.LabelBPM;

            // Activity data
            MaxHRLabel.Text = GarminFitnessView.GetLocalizedString("MaxHRLabelText");
            MaxHRBPMLabel.Text = CommonResources.Text.LabelBPM;
            GearWeightLabel.Text = GarminFitnessView.GetLocalizedString("GearWeightLabelText");
            GearWeightUnitLabel.Text = Weight.LabelAbbr(PluginMain.GetApplication().SystemPreferences.WeightUnits);

            // HR zones
            HRZonesGroupBox.Text = GarminFitnessView.GetLocalizedString("HRZonesGroupBoxText");
            BPMRadioButton.Text = CommonResources.Text.LabelBPM;
            PercentMaxRadioButton.Text = CommonResources.Text.LabelPercentOfMax;
            PercentHRRRadioButton.Text = CommonResources.Text.LabelPercentOfReserve;
            LowHRLabel.Text = GarminFitnessView.GetLocalizedString("LowLabelText");
            HighHRLabel.Text = GarminFitnessView.GetLocalizedString("HighLabelText");

            // Speed zones
            SpeedZonesGroupBox.Text = GarminFitnessView.GetLocalizedString("SpeedZonesGroupBoxText");
            SpeedRadioButton.Text = Length.LabelAbbr(m_CurrentProfile.BaseSpeedUnit) +
                                    GarminFitnessView.GetLocalizedString("PerHourText");
            PaceRadioButton.Text = GarminFitnessView.GetLocalizedString("MinuteAbbrText") + "/" +
                                   Length.LabelAbbr(m_CurrentProfile.BaseSpeedUnit);
            LowSpeedLabel.Text = GarminFitnessView.GetLocalizedString("LowLabelText");
            HighSpeedLabel.Text = GarminFitnessView.GetLocalizedString("HighLabelText");
            NameSpeedLabel.Text = GarminFitnessView.GetLocalizedString("NameLabelText");
        }
        public GarminProfileControl()
        {
            InitializeComponent();

            m_CurrentCategory = GarminCategories.Running;
            m_CurrentProfile = GarminProfileManager.Instance.GetProfileForActivity(m_CurrentCategory);
            m_CurrentBikeProfile = null;

            GarminProfileManager.Instance.ProfileChanged += new GarminProfileManager.ProfileChangedEventHandler(OnProfileChanged);
            GarminProfileManager.Instance.ActivityProfileChanged += new GarminProfileManager.ActivityProfileChangedEventHandler(OnActivityProfileChanged);

            BuildTreeLists();
        }
        public SetupWizardEditBikingProfileControl(ExtendedWizard wizard)
            : base(wizard)
        {
            InitializeComponent();

            GarminProfileManager.Instance.ActivityProfileChanged += new GarminProfileManager.ActivityProfileChangedEventHandler(OnActivityProfileChanged);

            BikeProfileActionBanner.ThemeChanged(PluginMain.GetApplication().VisualTheme);
            PowerZonesTreeList.ThemeChanged(PluginMain.GetApplication().VisualTheme);

            m_CurrentProfile = GarminProfileManager.Instance.GetProfileForActivity(GarminCategories.Biking);
            m_CurrentBikeProfile = null;

            ExplanationLabel.Text = GarminFitnessView.GetLocalizedString("BikeProfileExplanationText");

            // Power zones
            FTPLabel.Text = GarminFitnessView.GetLocalizedString("FTPLabelText");
            FTPUnitsLabel.Text = CommonResources.Text.LabelWatts;
            PowerZonesGroupBox.Text = GarminFitnessView.GetLocalizedString("PowerZonesGroupBoxText");
            LowPowerLabel.Text = GarminFitnessView.GetLocalizedString("LowLabelText");
            HighPowerLabel.Text = GarminFitnessView.GetLocalizedString("HighLabelText");

            // Bike profiles
            BikeNameLabel.Text = GarminFitnessView.GetLocalizedString("NameLabelText");
            OdometerLabel.Text = GarminFitnessView.GetLocalizedString("OdometerLabelText");
            OdometerUnitsLabel.Text = Length.LabelAbbr(m_CurrentProfile.BaseSpeedUnit);
            BikeWeightLabel.Text = GarminFitnessView.GetLocalizedString("WeightLabelText");
            BikeWeightUnitLabel.Text = Weight.LabelAbbr(PluginMain.GetApplication().SystemPreferences.WeightUnits);
            HasCadenceCheckBox.Text = GarminFitnessView.GetLocalizedString("HasCadenceText");
            HasPowerCheckBox.Text = GarminFitnessView.GetLocalizedString("HasPowerText");
            WheelSizeGroupBox.Text = GarminFitnessView.GetLocalizedString("WheelSizeGroupBoxText");
            AutoWheelSizeCheckBox.Text = GarminFitnessView.GetLocalizedString("AutoText");
            WheelSizeLabel.Text = GarminFitnessView.GetLocalizedString("WheelSizeLabelText");
            WheelSizeUnitLabel.Text = GarminFitnessView.GetLocalizedString("MillimeterText");

            BuildTreeLists();
            RefreshUIFromProfile();
        }
 public GarminSpeedZoneWrapper(GarminCategories category, int zoneIndex)
     : base(null, null)
 {
     m_Profile = GarminProfileManager.Instance.GetProfileForActivity(category);
     m_ZoneIndex = zoneIndex;
 }
        public void OtherProfileEventHandler(object sender, EventArgs args)
        {
            m_CurrentCategory = GarminCategories.Other;
            m_CurrentProfile = GarminProfileManager.Instance.GetProfileForActivity(m_CurrentCategory);

            RefreshUIFromCategory();
        }
        void OnActivityProfileChanged(GarminActivityProfile profileModified, System.ComponentModel.PropertyChangedEventArgs changedProperty)
        {
            if (profileModified.Category == m_CurrentCategory)
            {
                // make sure we have the right profile, when deserializing from
                //  XML, this is not valid
                m_CurrentProfile = GarminProfileManager.Instance.GetProfileForActivity(m_CurrentCategory);

                RefreshUIFromProfile();
            }
        }
        public void RefreshUIFromLogbook()
        {
            this.Enabled = PluginMain.GetApplication().Logbook != null;

            // Update profile from new logbook
            m_CurrentProfile = GarminProfileManager.Instance.GetProfileForActivity(m_CurrentCategory);

            RefreshProfileInfo();
            RefreshUIFromCategory();
        }
示例#9
0
 private void OnActivityProfileChanged(GarminActivityProfile profileModified, PropertyChangedEventArgs changedProperty)
 {
     TriggerActivityProfileChangedEvent(profileModified, changedProperty);
 }
示例#10
0
        public void DeserializeFromFIT(Stream importStream)
        {
            FITMessageField profileName = null;
            FITMessageField gender = null;
            FITMessageField weight = null;
            FITMessageField restingHR = null;

            GarminActivityProfile[] profiles;

            profiles = new GarminActivityProfile[]
                {
                    m_ActivityProfiles[0].Clone(),
                    m_ActivityProfiles[1].Clone(),
                    m_ActivityProfiles[2].Clone()
                };

            Logger.Instance.LogText("Init parser in profile");

            if (FITParser.Instance.Init(importStream))
            {
                FITMessage parsedMessage = null;
                FITMessage sportMessage = null;
                FITSports fileSportType = FITSports.Other;

                do
                {
                    parsedMessage = FITParser.Instance.ReadNextMessage();

                    if (parsedMessage != null)
                    {
                        Logger.Instance.LogText(String.Format("FIT parsed message type={0:0}", (int)parsedMessage.GlobalMessageType));

                        switch (parsedMessage.GlobalMessageType)
                        {
                            case FITGlobalMessageIds.FileId:
                                {
                                    // Make sure we have a profile file (settings or sport)
                                    FITMessageField fileTypeField = parsedMessage.GetField((Byte)FITFileIdFieldsIds.FileType);

                                    if (fileTypeField == null ||
                                        ((FITFileTypes)fileTypeField.GetEnum() != FITFileTypes.Settings &&
                                         (FITFileTypes)fileTypeField.GetEnum() != FITFileTypes.Sport))
                                    {
                                        Logger.Instance.LogText("Not a profile FIT file");
                                        return;
                                    }

                                    if ((FITFileTypes)fileTypeField.GetEnum() == FITFileTypes.Sport)
                                    {
                                        // Prefetch the sport message so we know what to deal with before parsing the other
                                        //  messages that contain sport relative data
                                        sportMessage = FITParser.Instance.PrefetchMessageOfType(FITGlobalMessageIds.Sport);

                                        fileSportType = (FITSports)sportMessage.GetField((Byte)FITSportFieldIds.Sport).GetEnum();
                                    }

                                    break;
                                }
                            case FITGlobalMessageIds.UserProfile:
                                {
                                    profileName = parsedMessage.GetField((Byte)FITUserProfileFieldIds.FriendlyName);
                                    gender = parsedMessage.GetField((Byte)FITUserProfileFieldIds.Gender);
                                    weight = parsedMessage.GetField((Byte)FITUserProfileFieldIds.Weight);
                                    restingHR = parsedMessage.GetField((Byte)FITUserProfileFieldIds.RestingHR);
                                    break;
                                }
                            case FITGlobalMessageIds.BikeProfile:
                                {
                                    (profiles[(int)GarminCategories.Biking] as GarminBikingActivityProfile).DeserializeBikeProfile(parsedMessage);
                                    break;
                                }
                            case FITGlobalMessageIds.ZonesTarget:
                                {
                                    if (sportMessage != null)
                                    {
                                        GarminActivityProfile activityProfile = profiles[(int)Options.Instance.GetGarminCategory(fileSportType)];

                                        activityProfile.DeserializeZonesTargetFromFIT(parsedMessage);
                                    }
                                    else
                                    {
                                        throw new FITParserException("No sport defined for zones target");
                                    }
                                    break;
                                }
                            case FITGlobalMessageIds.HRZones:
                                {
                                    if (sportMessage != null)
                                    {
                                        GarminActivityProfile activityProfile = profiles[(int)Options.Instance.GetGarminCategory(fileSportType)];

                                        activityProfile.DeserializeHRZonesFromFIT(parsedMessage);
                                    }
                                    else
                                    {
                                        throw new FITParserException("No sport defined for HR zones");
                                    }
                                    break;
                                }
                            case FITGlobalMessageIds.SpeedZones:
                                {
                                    if (sportMessage != null)
                                    {
                                        GarminActivityProfile activityProfile = profiles[(int)Options.Instance.GetGarminCategory(fileSportType)];

                                        activityProfile.DeserializeSpeedZonesFromFIT(parsedMessage);
                                    }
                                    else
                                    {
                                        throw new FITParserException("No sport defined for speed zones");
                                    }
                                    break;
                                }
                            case FITGlobalMessageIds.PowerZones:
                                {
                                    if (sportMessage != null)
                                    {
                                        GarminActivityProfile activityProfile = profiles[(int)Options.Instance.GetGarminCategory(fileSportType)];

                                        activityProfile.DeserializePowerZonesFromFIT(parsedMessage);
                                    }
                                    else
                                    {
                                        throw new FITParserException("No sport defined for power zones");
                                    }
                                    break;
                                }
                            default:
                                {
                                    // Nothing to do, unsupported message
                                    break;
                                }
                        }
                    }
                }
                while (parsedMessage != null);

                FITParser.Instance.Close();

                // Saved loaded values
                if (profileName != null)
                {
                    ProfileName = profileName.GetString();
                }

                if (gender != null)
                {
                    IsMale = gender.GetEnum() == (Byte)FITGenders.Male;
                }

                if (weight != null)
                {
                    WeightInKilos = weight.GetUInt16() / 10.0;
                }

                if (restingHR != null)
                {
                    RestingHeartRate = restingHR.GetUInt8();
                }

                // Everything was correctly deserialized, so update with the new profiles
                for (int i = 0; i < m_ActivityProfiles.Length; ++i)
                {
                    m_ActivityProfiles[i].ActivityProfileChanged -= new GarminActivityProfile.ActivityProfileChangedEventHandler(OnActivityProfileChanged);
                }

                m_ActivityProfiles = profiles;

                for (int i = 0; i < m_ActivityProfiles.Length; ++i)
                {
                    m_ActivityProfiles[i].ActivityProfileChanged += new GarminActivityProfile.ActivityProfileChangedEventHandler(OnActivityProfileChanged);
                }

                TriggerActivityProfileChangedEvent(m_ActivityProfiles[0], new PropertyChangedEventArgs(""));
                TriggerActivityProfileChangedEvent(m_ActivityProfiles[1], new PropertyChangedEventArgs(""));
                TriggerActivityProfileChangedEvent(m_ActivityProfiles[2], new PropertyChangedEventArgs(""));
            }
        }
示例#11
0
        public virtual void Deserialize(XmlNode parentNode)
        {
            bool birthDateRead = false;
            bool weightRead = false;
            bool genderRead = false;
            int activitiesReadCount = 0;
            GarminActivityProfile[] profiles;

            profiles = new GarminActivityProfile[]
                {
                    m_ActivityProfiles[0].Clone(),
                    m_ActivityProfiles[1].Clone(),
                    m_ActivityProfiles[2].Clone()
                };

            for (int i = 0; i < parentNode.ChildNodes.Count; ++i)
            {
                XmlNode currentChild = parentNode.ChildNodes[i];

                if (currentChild.Name == Constants.BirthDateTCXString)
                {
                    m_BirthDate.Deserialize(currentChild);
                    birthDateRead = true;
                }
                else if (currentChild.Name == Constants.WeightTCXString)
                {
                    m_WeightInKilos.Deserialize(currentChild);
                    weightRead = true;
                }
                else if (currentChild.Name == Constants.GenderTCXString)
                {
                    m_IsGenderMale.Deserialize(currentChild);
                    genderRead = true;
                }
                else if (currentChild.Name == Constants.ActivitiesTCXString)
                {
                    string activityType = PeekActivityType(currentChild);

                    for (int j = 0; j < (int)GarminCategories.GarminCategoriesCount; ++j)
                    {
                        if (activityType == Constants.GarminCategoryTCXString[j])
                        {
                            profiles[j].Deserialize(currentChild);
                            activitiesReadCount++;
                            break;
                        }
                    }
                }
            }

            // Check if all was read successfully
            if (!birthDateRead || !weightRead || !genderRead || activitiesReadCount != 3)
            {
                throw new GarminFitnessXmlDeserializationException("Missing information in profile XML node", parentNode);
            }

            // Everything was correctly deserialized, so update with the new profiles
            for (int i = 0; i < m_ActivityProfiles.Length; ++i)
            {
                m_ActivityProfiles[i].ActivityProfileChanged -= new GarminActivityProfile.ActivityProfileChangedEventHandler(OnActivityProfileChanged);
            }

            m_ActivityProfiles = profiles;

            for (int i = 0; i < m_ActivityProfiles.Length; ++i)
            {
                m_ActivityProfiles[i].ActivityProfileChanged += new GarminActivityProfile.ActivityProfileChangedEventHandler(OnActivityProfileChanged);
            }

            TriggerActivityProfileChangedEvent(m_ActivityProfiles[0], new PropertyChangedEventArgs(""));
            TriggerActivityProfileChangedEvent(m_ActivityProfiles[1], new PropertyChangedEventArgs(""));
            TriggerActivityProfileChangedEvent(m_ActivityProfiles[2], new PropertyChangedEventArgs(""));
        }
        public void BikingProfileEventHandler(object sender, EventArgs args)
        {
            m_CurrentCategory = GarminCategories.Biking;
            m_CurrentProfile = GarminProfileManager.Instance.GetProfileForActivity(m_CurrentCategory);
            m_CurrentBikeProfile = ((GarminBikingActivityProfile)m_CurrentProfile).GetBikeProfile(m_BikeProfileIndex);

            RefreshUIFromCategory();
        }
        void OnActivityProfileChanged(GarminActivityProfile profileModified, PropertyChangedEventArgs changedProperty)
        {
            if (InvokeRequired)
            {
                Invoke(new ActivityProfileChanged(OnActivityProfileChanged),
                       new object[] { profileModified, changedProperty });
            }
            else
            {
                if (profileModified.Category == m_CurrentCategory)
                {
                    // Make sure we have the right profile, when deserializing from
                    //  XML, this is not valid
                    m_CurrentProfile = GarminProfileManager.Instance.GetProfileForActivity(m_CurrentCategory);

                    RefreshUIFromProfile();
                }
            }
        }
 public void UpdateProfile(GarminCategories category)
 {
     m_Profile = GarminProfileManager.Instance.GetProfileForActivity(category);
 }
示例#15
0
        private void TriggerActivityProfileChangedEvent(GarminActivityProfile profileModified, PropertyChangedEventArgs args)
        {
            if (!IsDeserializing)
            {
                PluginMain.GetApplication().Logbook.Modified = true;
            }

            if (ActivityProfileChanged != null)
            {
                ActivityProfileChanged(profileModified, args);
            }
        }
 private void OnUserActivityProfileChanged(GarminActivityProfile profileChanged, PropertyChangedEventArgs changedProperty)
 {
     if (ActivityProfileChanged != null)
     {
         ActivityProfileChanged(profileChanged, changedProperty);
     }
 }
        public virtual GarminActivityProfile Clone()
        {
            MemoryStream stream = new MemoryStream();
            GarminActivityProfile clone = new GarminActivityProfile(Category);

            Serialize(stream);
            stream.Position = 0;
            clone.Deserialize(stream, Constants.CurrentVersion);
            stream.Close();

            return clone;
        }