/[cits3200i]/branches/gps-running-clean-r116/HighScorePlugin/Util/UnitUtil.cs


UCC Code Repository

Contents of /branches/gps-running-clean-r116/HighScorePlugin/Util/UnitUtil.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations) (download)
Sun Sep 5 15:48:34 2010 UTC (11 years, 2 months ago) by rvvs89
File size: 33091 byte(s)
Branching a local copy of the HEAD revision of the gps-running project on Google Code.
We will probably have to use this project as a template for our own plugins if we want to support SportTracks 2.1.
1 /*
2 Copyright (C) 2010 Gerhard Olsson
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /* This should be a common utility for all plugins, but to avoid
19 * to handle the Plugin application reference (not available at startup)
20 * why this is copied right now.
21 * */
22
23 using System;
24 using System.Globalization;
25 using ZoneFiveSoftware.Common.Data.Measurement;
26 using ZoneFiveSoftware.Common.Visuals;
27 using GpsRunningPlugin;
28
29 namespace GpsRunningPlugin.Util
30 {
31 class CollectionUtils
32 {
33 #if !ST_2_1
34 public static System.Collections.Generic.IList<ItemType> GetAllContainedItems<ItemType>(ISelectionProvider selectionProvider)
35 {
36 System.Collections.Generic.List<ItemType> items = new System.Collections.Generic.List<ItemType>();
37 foreach (ItemType item in ZoneFiveSoftware.Common.Visuals.Util.CollectionUtils.GetItemsOfType<ItemType>(selectionProvider.SelectedItems))
38 {
39 if (!items.Contains(item)) items.Add(item);
40 }
41 AddGroupItems<ItemType>(ZoneFiveSoftware.Common.Visuals.Util.CollectionUtils.GetItemsOfType<ZoneFiveSoftware.Common.Data.IGroupedItem<ItemType>>(
42 selectionProvider.SelectedItems), items);
43 return items;
44 }
45
46 public static void AddGroupItems<ItemType>(System.Collections.Generic.IList<ZoneFiveSoftware.Common.Data.IGroupedItem<ItemType>> groups, System.Collections.Generic.IList<ItemType> allItems)
47 {
48 foreach (ZoneFiveSoftware.Common.Data.IGroupedItem<ItemType> group in groups)
49 {
50 foreach (ItemType item in group.Items)
51 {
52 if (!allItems.Contains(item)) allItems.Add(item);
53 }
54 AddGroupItems(group.SubGroups, allItems);
55 }
56 }
57 #endif
58 }
59 class UnitUtil
60 {
61 //Helpfunction for common format
62 private static string encPar(string p)
63 {
64 //Some units (like Km in Danish) has a trailing space
65 char[] t = {' '};
66 return " (" + p.TrimEnd(t) + ")";
67 }
68
69 public class Power
70 {
71 //private static Length.Units Unit { get { return null; } }
72 public static int DefaultDecimalPrecision { get { return 0; } }
73 private static string DefFmt { get { return "F" + DefaultDecimalPrecision; } }
74
75 public static string ToString(double p)
76 {
77 return ToString(p, DefFmt);
78 }
79 public static string ToString(double p, string fmt)
80 {
81 string str = "";
82 if (fmt.EndsWith("U")) { str = " " + Label; fmt = fmt.Remove(fmt.Length-1); }
83 if (fmt.EndsWith("u")) { str = " " + LabelAbbr; fmt = fmt.Remove(fmt.Length-1); }
84 return ConvertFrom(p).ToString((fmt));
85 }
86 public static double ConvertFrom(double p)
87 {
88 return p;
89 }
90
91 public static double Parse(string p)
92 {
93 return double.Parse(p, NumberFormatInfo.InvariantInfo);
94 }
95
96 public static String Label
97 {
98 get
99 {
100 return CommonResources.Text.LabelWatts;
101 }
102 }
103 public static String LabelAbbr
104 {
105 get
106 {
107 return "W";
108 }
109 }
110 public static String LabelAbbr2
111 {
112 get
113 {
114 return encPar(LabelAbbr);
115 }
116 }
117 public static String LabelAxis
118 {
119 get
120 {
121 return CommonResources.Text.LabelPower + LabelAbbr2;
122 }
123 }
124 }
125
126 public class Cadence
127 {
128 //private static Length.Units Unit { get { return null; } }
129 public static int DefaultDecimalPrecision { get { return 0; } }
130 private static string DefFmt { get { return "F" + DefaultDecimalPrecision; } }
131
132 public static string ToString(double p)
133 {
134 return ToString(p, DefFmt);
135 }
136 public static string ToString(double p, string fmt)
137 {
138 string str = "";
139 if (fmt.EndsWith("U")) { str = " " + Label; fmt = fmt.Remove(fmt.Length-1); }
140 if (fmt.EndsWith("u")) { str = " " + LabelAbbr; fmt = fmt.Remove(fmt.Length-1); }
141 return ConvertFrom(p).ToString((fmt));
142 }
143 public static double ConvertFrom(double p)
144 {
145 return p;
146 }
147
148 private static double Parse(string p)
149 {
150 return double.Parse(p, NumberFormatInfo.InvariantInfo);
151 }
152
153 public static String Label
154 {
155 get
156 {
157 return CommonResources.Text.LabelRPM;
158 }
159 }
160 public static String LabelAbbr
161 {
162 get
163 {
164 return CommonResources.Text.LabelRPM;
165 }
166 }
167 public static String LabelAbbr2
168 {
169 get
170 {
171 return encPar(LabelAbbr);
172 }
173 }
174 public static String LabelAxis
175 {
176 get
177 {
178 return CommonResources.Text.LabelCadence + LabelAbbr2;
179 }
180 }
181 }
182
183 public static class HeartRate
184 {
185 //private static Length.Units Unit { get { return null; } }
186 public static int DefaultDecimalPrecision { get { return 0; } }
187 private static string DefFmt { get { return "F" + DefaultDecimalPrecision; } }
188
189 public static string ToString(double p)
190 {
191 return ToString(p, DefFmt);
192 }
193 public static string ToString(double p, string fmt)
194 {
195 string str = "";
196 if (fmt.EndsWith("U")) { str = " " + Label; fmt = fmt.Remove(fmt.Length-1); }
197 if (fmt.EndsWith("u")) { str = " " + LabelAbbr; fmt = fmt.Remove(fmt.Length-1); }
198 return ConvertFrom(p).ToString((fmt));
199 }
200 public static double ConvertFrom(double p)
201 {
202 return p;
203 }
204
205 public static double Parse(string p)
206 {
207 return double.Parse(p, NumberFormatInfo.InvariantInfo);
208 }
209
210 public static String Label
211 {
212 get
213 {
214 return CommonResources.Text.LabelBPM;
215 }
216 }
217 public static String LabelAbbr
218 {
219 get
220 {
221 return CommonResources.Text.LabelBPM;
222 }
223 }
224 public static String LabelAbbr2
225 {
226 get
227 {
228 return encPar(LabelAbbr);
229 }
230 }
231 public static String LabelAxis
232 {
233 get
234 {
235 return CommonResources.Text.LabelHeartRate + LabelAbbr2;
236 }
237 }
238 }
239
240 public static class Energy
241 {
242 private static ZoneFiveSoftware.Common.Data.Measurement.Energy.Units Unit { get { return Plugin.GetApplication().SystemPreferences.EnergyUnits; } }
243 public static int DefaultDecimalPrecision { get { return 0; } }
244 private static string DefFmt { get { return "F" + DefaultDecimalPrecision; } }
245
246 public static string ToString(double p)
247 {
248 return ToString(p, DefFmt);
249 }
250 public static string ToString(double p, string fmt)
251 {
252 string str = "";
253 if (fmt.EndsWith("U")) { str = " " + Label; fmt = fmt.Remove(fmt.Length - 1); }
254 if (fmt.EndsWith("u")) { str = " " + LabelAbbr; fmt = fmt.Remove(fmt.Length - 1); }
255 return ConvertFrom(p).ToString((fmt));
256 }
257 public static double ConvertFrom(double p)
258 {
259 return ZoneFiveSoftware.Common.Data.Measurement.Energy.Convert(p,
260 ZoneFiveSoftware.Common.Data.Measurement.Energy.Units.Kilocalorie,
261 Unit);
262 }
263
264 public static double Parse(string p)
265 {
266 ZoneFiveSoftware.Common.Data.Measurement.Energy.Units unit = Unit;
267 return ZoneFiveSoftware.Common.Data.Measurement.Energy.ParseEnergyKilocalories(p, unit);
268 }
269
270 public static String Label
271 {
272 get
273 {
274 return ZoneFiveSoftware.Common.Data.Measurement.Energy.Label(Unit);
275 }
276 }
277 public static String LabelAbbr
278 {
279 get
280 {
281 return ZoneFiveSoftware.Common.Data.Measurement.Energy.Label(Unit);
282 }
283 }
284 public static String LabelAbbr2
285 {
286 get
287 {
288 return encPar(LabelAbbr);
289 }
290 }
291 public static String LabelAxis
292 {
293 //This is included for completeness only
294 get
295 {
296 return CommonResources.Text.LabelCalories + LabelAbbr2;
297 }
298 }
299 }
300
301 public static class Temperature
302 {
303 private static ZoneFiveSoftware.Common.Data.Measurement.Temperature.Units Unit { get { return Plugin.GetApplication().SystemPreferences.TemperatureUnits; } }
304 public static int DefaultDecimalPrecision { get { return 1; } }
305 private static string DefFmt { get { return "F" + DefaultDecimalPrecision; } }
306
307 public static string ToString(double p)
308 {
309 return ToString(p, DefFmt);
310 }
311 public static string ToString(double p, string fmt)
312 {
313 if (fmt.ToLower().Equals("u")) { fmt = DefFmt + fmt; }
314 return ZoneFiveSoftware.Common.Data.Measurement.Temperature.ToString(ConvertFrom(p), Unit, fmt);
315 }
316 public static double ConvertFrom(double p)
317 {
318 return ZoneFiveSoftware.Common.Data.Measurement.Temperature.Convert(p,
319 ZoneFiveSoftware.Common.Data.Measurement.Temperature.Units.Celsius, Unit);
320 }
321
322 public static double Parse(string p)
323 {
324 return double.Parse(p, NumberFormatInfo.InvariantInfo);
325 }
326
327 public static String Label
328 {
329 get
330 {
331 return ZoneFiveSoftware.Common.Data.Measurement.Temperature.Label(Unit);
332 }
333 }
334 public static String LabelAbbr
335 {
336 get
337 {
338 return ZoneFiveSoftware.Common.Data.Measurement.Temperature.LabelAbbr(Unit);
339 }
340 }
341 public static String LabelAbbr2
342 {
343 get
344 {
345 return encPar(LabelAbbr);
346 }
347 }
348 public static String LabelAxis
349 {
350 //This is included for completeness only
351 get
352 {
353 return CommonResources.Text.LabelTemperature + LabelAbbr2;
354 }
355 }
356 }
357
358 public static class Weight
359 {
360 private static ZoneFiveSoftware.Common.Data.Measurement.Weight.Units Unit { get { return Plugin.GetApplication().SystemPreferences.WeightUnits; } }
361 public static int DefaultDecimalPrecision { get { return 1; } }
362 private static string DefFmt { get { return "F" + DefaultDecimalPrecision; } }
363
364 public static string ToString(double p)
365 {
366 return ToString(p, DefFmt);
367 }
368 public static string ToString(double p, string fmt)
369 {
370 if (fmt.ToLower().Equals("u")) { fmt = DefFmt + fmt; }
371 return ZoneFiveSoftware.Common.Data.Measurement.Weight.ToString(ConvertFrom(p), Unit, fmt);
372 }
373 public static double ConvertFrom(double p)
374 {
375 return ZoneFiveSoftware.Common.Data.Measurement.Weight.Convert(p,
376 ZoneFiveSoftware.Common.Data.Measurement.Weight.Units.Kilogram, Unit);
377 }
378
379 public static double Parse(string p)
380 {
381 return ZoneFiveSoftware.Common.Data.Measurement.Weight.ParseWeightKilograms(p, Unit);
382 }
383
384 public static String Label
385 {
386 get
387 {
388 return ZoneFiveSoftware.Common.Data.Measurement.Weight.Label(Unit);
389 }
390 }
391 public static String LabelAbbr
392 {
393 get
394 {
395 return ZoneFiveSoftware.Common.Data.Measurement.Weight.LabelAbbr(Unit);
396 }
397 }
398 public static String LabelAbbr2
399 {
400 get
401 {
402 return encPar(LabelAbbr);
403 }
404 }
405 public static String LabelAxis
406 {
407 get
408 {
409 return CommonResources.Text.LabelWeight + LabelAbbr2;
410 }
411 }
412 }
413
414 public static class Elevation
415 {
416 private static Length.Units Unit { get { return Plugin.GetApplication().SystemPreferences.ElevationUnits; } }
417 public static int DefaultDecimalPrecision { get { return Length.DefaultDecimalPrecision(Unit); } }
418 private static string DefFmt { get { return defFmt(Unit); } }
419 private static string defFmt(Length.Units unit) { return "F" + Length.DefaultDecimalPrecision(unit); }
420
421 public static string ToString(double p)
422 {
423 return ToString(p, DefFmt);
424 }
425 public static string ToString(double p, string fmt)
426 {
427 if (fmt.ToLower().Equals("u")) { fmt = DefFmt + fmt; }
428 return Length.ToString(ConvertFrom(p), Unit, fmt);
429 }
430 public static double ConvertFrom(double p)
431 {
432 return Length.Convert(p, Length.Units.Meter, Unit);
433 }
434
435 public static double Parse(string p)
436 {
437 Length.Units unit = Unit;
438 return Length.ParseDistanceMeters(p, ref unit);
439 }
440
441 public static String Label
442 {
443 get
444 {
445 return Length.Label(Unit);
446 }
447 }
448 public static String LabelAbbr
449 {
450 get
451 {
452 return Length.LabelAbbr(Unit);
453 }
454 }
455 public static String LabelAbbr2
456 {
457 get
458 {
459 return encPar(LabelAbbr);
460 }
461 }
462 public static String LabelAxis
463 {
464 get
465 {
466 return CommonResources.Text.LabelElevation + LabelAbbr2;
467 }
468 }
469 }
470
471 public static class Time
472 {
473 //This class handles Time as in "Time for activities" rather than "Time of day"
474 public static int DefaultDecimalPrecision { get { return 1; } } //Unly used for time less than a minute
475 private static string DefFmt { get { return ""; } }
476
477 public static string ToString(double p)
478 {
479 return ToString(p, DefFmt);
480 }
481 public static String ToString(double sec, string fmt)
482 {
483 return ToString(new TimeSpan(0, 0, 0, 0, (int)(sec * 1000)), fmt);
484 }
485 public static string ToString(TimeSpan p)
486 {
487 return ToString(p, DefFmt);
488 }
489 public static String ToString(TimeSpan sec, string fmt)
490 {
491 string str = "";
492 if (fmt.EndsWith("U")) { fmt = fmt.Remove(fmt.Length - 1); }
493 if (fmt.EndsWith("u")) { fmt = fmt.Remove(fmt.Length - 1); }
494 //.NET 2 has no built-in formatting for time
495 //Currently remove millisec ("mm:ss" format)
496 if (fmt.Equals("ss") && sec.TotalSeconds < 60 || fmt.Equals("s"))
497 {
498 str = (sec.TotalMilliseconds / 1000).ToString(("F" + DefaultDecimalPrecision));
499 }
500 else
501 {
502 //Truncate to seconds by creating new TimeSpan
503 str = (new TimeSpan(0, 0, (int)Math.Round(sec.TotalSeconds))).ToString();
504 if (fmt.Equals("mm:ss") && str.StartsWith("00:")) { str = str.Substring(3); }
505 }
506
507 return str;
508 }
509
510 public static double Parse(string p)
511 {
512 String[] pair = p.Split(':');
513 double seconds;
514 if (pair.Length >= 2)
515 {
516 if (pair.Length == 2)
517 {
518 p = "00:" + p;
519 }
520 //This seem to be a regular time span, use standard metod
521 TimeSpan ts = TimeSpan.Parse(p);
522 seconds = ts.TotalMilliseconds / 1000;
523 }
524 else
525 {
526 //Try parsing as double - there will be an exception if incorrect
527 seconds = double.Parse(p);
528 }
529
530 return seconds;
531 }
532
533 public static String LabelAxis
534 {
535 get
536 {
537 return CommonResources.Text.LabelTime; //no unit info
538 }
539 }
540 }
541
542 public static class Distance
543 {
544 //Some lists uses unit when storing user entered data, why this is public
545 public static Length.Units Unit { get { return Plugin.GetApplication().SystemPreferences.DistanceUnits; } }
546 public static int DefaultDecimalPrecision { get { return Length.DefaultDecimalPrecision(Unit); } }
547 private static string DefFmt { get { return defFmt(Unit); } }
548 private static string defFmt(Length.Units unit) { return "F" + Length.DefaultDecimalPrecision(unit); }
549
550 public static string ToString(double p)
551 {
552 return ToString(p, DefFmt);
553 }
554 public static string ToString(double p, string fmt)
555 {
556 return ToString(p, Unit, fmt);
557 }
558 public static string ToString(double p, Length.Units unit, string fmt)
559 {
560 //The source is in system format (meter), but should be converted
561 //defFmt should not be required, but ST applies it automatically if "u" is added
562 if (fmt.ToLower().Equals("u")) { fmt = defFmt(unit) + fmt; }
563 return Length.ToString(ConvertFrom(p, unit), unit, fmt);
564 }
565 public static double ConvertFrom(double p)
566 {
567 return ConvertFrom(p, Unit);
568 }
569 public static double ConvertFrom(double p, Length.Units unit)
570 {
571 return Length.Convert(p, Length.Units.Meter, unit);
572 }
573
574 public static double Parse(string p)
575 {
576 Length.Units unit = Unit;
577 return Parse(p, ref unit);
578 }
579 public static double Parse(string p, ref Length.Units unit)
580 {
581 return Length.ParseDistanceMeters(p, ref unit);
582 }
583
584 public static String Label
585 {
586 get
587 {
588 return Length.Label(Unit);
589 }
590 }
591 public static String LabelAbbr
592 {
593 get
594 {
595 return Length.LabelAbbr(Unit);
596 }
597 }
598 public static String LabelAbbr2
599 {
600 get
601 {
602 return encPar(LabelAbbr);
603 }
604 }
605 public static String LabelAxis
606 {
607 get
608 {
609 return CommonResources.Text.LabelDistance + LabelAbbr2;
610 }
611 }
612 }
613
614 //Pace/speed handling
615 //Limit distance to units where we have pace/speed labels
616 //(meter is available for distance as well, but no labels are available)
617
618 private static Length.Units getDistUnit(bool isPace)
619 {
620 Length.Units distUnit = Plugin.GetApplication().SystemPreferences.DistanceUnits;
621 //Add all known statute length units, in case they are added to ST
622 if (distUnit.Equals(Length.Units.Mile) || distUnit.Equals(Length.Units.Inch) ||
623 distUnit.Equals(Length.Units.Foot) || distUnit.Equals(Length.Units.Yard))
624 {
625 distUnit = Length.Units.Mile;
626 }
627 else
628 {
629 distUnit = Length.Units.Kilometer;
630 }
631 return distUnit;
632 }
633
634 public static class Speed
635 {
636 //Convert pace/speed from system type (m/s) to used value
637 // all speed units are per hour
638 private static Length.Units Unit { get { return getDistUnit(false); } }
639 public static int DefaultDecimalPrecision { get { return 1; } }
640 private static string DefFmt { get { return "F" + DefaultDecimalPrecision; } }
641
642 public static string ToString(double p)
643 {
644 return ToString(p, DefFmt);
645 }
646 public static string ToString(double p, string fmt)
647 {
648 string str = "";
649 if (fmt.EndsWith("U")) { str = " " + Label; fmt = fmt.Remove(fmt.Length-1); }
650 if (fmt.EndsWith("u")) { str = " " + LabelAbbr; fmt = fmt.Remove(fmt.Length-1); }
651 if (string.IsNullOrEmpty(fmt)) { fmt = DefFmt; }
652 return ConvertFrom(p).ToString((fmt)) + str;
653 }
654 public static double ConvertFrom(double speedMS)
655 {
656 return Length.Convert(speedMS, Length.Units.Meter, Unit) * 60 * 60;
657 }
658
659 public static double Parse(string p)
660 {
661 return Length.Convert(double.Parse(p, NumberFormatInfo.InvariantInfo), Unit, Length.Units.Meter) / (60 * 60);
662 }
663
664 private static String getLabel()
665 {
666 String unit;
667 #if ST_2_1
668 if (Unit.Equals(Length.Units.Mile))
669 {
670 unit = CommonResources.Text.LabelMilePerHour;
671 }
672 else
673 {
674 unit = CommonResources.Text.LabelKmPerHour;
675 }
676 #else
677 unit = ZoneFiveSoftware.Common.Data.Measurement.Speed.Label(
678 ZoneFiveSoftware.Common.Data.Measurement.Speed.Units.Speed,
679 new Length(1, Plugin.GetApplication().SystemPreferences.DistanceUnits));
680 #endif
681 return unit;
682 }
683 public static String Label
684 {
685 get
686 {
687 return getLabel();
688 }
689 }
690 public static String LabelAbbr
691 {
692 get
693 {
694 return getLabel();
695 }
696 }
697 public static String LabelAbbr2
698 {
699 get
700 {
701 return encPar(LabelAbbr);
702 }
703 }
704 public static String LabelAxis
705 {
706 get
707 {
708 return CommonResources.Text.LabelSpeed + LabelAbbr2;
709 }
710 }
711 }
712
713 public static class Pace
714 {
715 //Pace units are in "unspecified time" per distance
716 //Display is done as time, input parsing expects time in minutes or "minute time"
717
718 private static Length.Units Unit { get { return getDistUnit(true); } }
719 public static int DefaultDecimalPrecision { get { return 1; } } //Not really applicable
720 private static string DefFmt { get { return ""; } }
721
722 public static string ToString(double p)
723 {
724 return ToString(p, DefFmt);
725 }
726 public static String ToString(double speedMS, string fmt)
727 {
728 //The only formatting handled is "u"/"U"
729 double pace = ConvertFrom(speedMS);
730 string str = "";
731 if (fmt.EndsWith("U")) { str = " " + Label; fmt = fmt.Remove(fmt.Length - 1); }
732 if (fmt.EndsWith("u")) { str = " " + LabelAbbr; fmt = fmt.Remove(fmt.Length - 1); }
733 if (Math.Abs(speedMS) == double.MinValue)//"divide by zero" check. Or some hardcoded value?
734 {
735 str = "-" + str;
736 }
737 else
738 {
739 str = new TimeSpan(0, 0, (int)Math.Round(pace)).ToString() + str;
740 if (str.StartsWith("00:")) { str = str.Substring(3); }
741 }
742 return str;
743 }
744 public static double ConvertFrom(double speedMS)
745 {
746 return 1 / Length.Convert(speedMS, Length.Units.Meter, Unit);
747 }
748
749 public static double Parse(string p)
750 {
751 //Almost the same as parsing time, except that no colons is interpreted as minutes
752 String[] pair = p.Split(':');
753 double seconds;
754 if (pair.Length == 3 || pair.Length == 2)
755 {
756 if (pair.Length == 2)
757 {
758 p = "00:" + p;
759 }
760 //This seem to be a regular time span, use standard metod
761 TimeSpan ts = TimeSpan.Parse(p);
762 seconds = ts.TotalMilliseconds / 1000;
763 }
764 else
765 {
766 seconds = 60 * double.Parse(p);
767 }
768
769 return seconds;
770 }
771
772 private static String getLabel()
773 {
774 String unit;
775 #if ST_2_1
776 if (Unit.Equals(Length.Units.Mile))
777 {
778 unit = CommonResources.Text.LabelMinPerMile;
779 }
780 else
781 {
782 unit = CommonResources.Text.LabelMinPerKm;
783 }
784 #else
785 unit = ZoneFiveSoftware.Common.Data.Measurement.Speed.Label(
786 ZoneFiveSoftware.Common.Data.Measurement.Speed.Units.Pace,
787 new Length(1, Plugin.GetApplication().SystemPreferences.DistanceUnits));
788 #endif
789 return unit;
790 }
791 public static String Label
792 {
793 get
794 {
795 return getLabel();
796 }
797 }
798 public static String LabelAbbr
799 {
800 get
801 {
802 return getLabel();
803 }
804 }
805 public static String LabelAbbr2
806 {
807 get
808 {
809 return encPar(LabelAbbr);
810 }
811 }
812 public static String LabelAxis
813 {
814 get
815 {
816 return CommonResources.Text.LabelPace + LabelAbbr2;
817 }
818 }
819 //Some forms uses the label to find if pace/speed is used, get a way to find how
820 public static bool isLabelPace(string label)
821 {
822 //All possible labels should be checked here
823 //The "min/" is for changed languages, not foolproof, but that was the way HighScore checked it
824 return (
825 #if ST_2_1
826 label.Equals(CommonResources.Text.LabelMinPerKm) || label.Equals(CommonResources.Text.LabelMinPerMile)
827 #else
828 label.Equals(ZoneFiveSoftware.Common.Data.Measurement.Speed.Label(
829 ZoneFiveSoftware.Common.Data.Measurement.Speed.Units.Pace,
830 new Length(1, Plugin.GetApplication().SystemPreferences.DistanceUnits)))
831 #endif
832 || label.Contains("min/")
833 );
834 }
835 }
836
837 public static class PaceOrSpeed
838 {
839 public static int DefaultDecimalPrecision(bool isPace)
840 {
841 if (isPace)
842 {
843 return Pace.DefaultDecimalPrecision;
844 }
845 return Speed.DefaultDecimalPrecision;
846 }
847 public static String ToString(bool isPace, double speedMS)
848 {
849 if (isPace)
850 {
851 return Pace.ToString(speedMS);
852 }
853 return Speed.ToString(speedMS);
854 }
855 public static String ToString(bool isPace, double speedMS, string fmt)
856 {
857 if (isPace)
858 {
859 return Pace.ToString(speedMS, fmt);
860 }
861 return Speed.ToString(speedMS, fmt);
862 }
863 public static double ConvertFrom(bool isPace, double speedMS)
864 {
865 if (isPace)
866 {
867 return Pace.ConvertFrom(speedMS);
868 }
869 return Speed.ConvertFrom(speedMS);
870 }
871
872 public static double Parse(bool isPace, string p)
873 {
874 if (isPace)
875 {
876 return Pace.Parse(p);
877 }
878 return Speed.Parse(p);
879 }
880
881 public static String Label(bool isPace)
882 {
883 if (isPace)
884 {
885 return Pace.Label;
886 }
887 return Speed.Label;
888 }
889 public static String LabelAbbr(bool isPace)
890 {
891 if (isPace)
892 {
893 return Pace.LabelAbbr;
894 }
895 return Speed.LabelAbbr;
896 }
897 public static String LabelAbbr2(bool isPace)
898 {
899 if (isPace)
900 {
901 return Pace.LabelAbbr2;
902 }
903 return Speed.LabelAbbr2;
904 }
905 public static String LabelAxis(bool isPace)
906 {
907 if (isPace)
908 {
909 return Pace.LabelAxis;
910 }
911 return Speed.LabelAxis;
912 }
913 }
914 }
915 }

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26