public BinaryFit Clone() { BinaryFit bf = new BinaryFit(this.Name, this.workoutLength); bf.Clear(); foreach (CommandBlock b in this.blocks) { bf.Add(b.Clone()); } return(bf); }
public void ImportLayoutDotFitFile(int numWorkouts, string pathToLayoutFit) { char[] charBuf = new char[32]; lines.Clear(); sFs.Clear(); bFs.Clear(); System.IO.StreamReader objFile = null; objFile = new System.IO.StreamReader(pathToLayoutFit); for (int ii = 0; ii < numWorkouts; ii++) { objFile.ReadBlock(charBuf, 0, 32); lines.Add(new LayoutLine(charBuf)); if (ii == 0) { //determine workoutLength string layoutDirectory = pathToLayoutFit.Substring(0, pathToLayoutFit.Length - 10); workoutLength = getWorkoutLength(layoutDirectory + lines[ii].binaryFitFileName + ".fit"); } bFs.Add(new BinaryFit(lines[ii].binaryFitFileName, workoutLength)); sFs.Add(new SoundFit(lines[ii].soundFitFileName)); //okay, at this point we now have the LayoutFit object constructed //along with some empty BinaryFit and SoundFit objects //now we need to populate the BinaryFit and SoundFit objects with //valid information from the files on the disk //first we need to fill in the command blocks for this newly created //BinaryFit file BinaryFit bF = bFs[ii]; SoundFit sF = sFs[ii]; string bFName = new string(charBuf, 0, 8); string sFName = new string(charBuf, 9, 8); if (bFName.Equals("********")) //nothing to read from disk here { ASCIIEncoding AE = new ASCIIEncoding(); byte[] me = new byte[1]; //byte me :> :P :) ;) me[0] = lowByte((short)ii); me[0] += 65; //'A' string bFNamer = string.Format("W000000{0}", new String(AE.GetChars(me))); string sFNamer = string.Format("S000000{0}", new String(AE.GetChars(me))); bFs[ii] = new BinaryFit(bFNamer, workoutLength); sFs[ii] = new SoundFit(sFNamer); Replace(ii, new LayoutLine(bFNamer, sFNamer)); } else //each BinaryFit object can load itself from disk { string sFPath = pathToLayoutFit; sFPath = sFPath.Replace("layout", sFName); sF.LoadFromDisk(sFPath); string bFPath = pathToLayoutFit; bFPath = bFPath.Replace("layout", bFName); bF.LoadFromDisk(bFPath, sF); } } }
public BinaryFit Clone(string bfNameParam, BinaryFit bfToBeReplaced, double speedGradient, double inclineGradient) { BinaryFit bf = new BinaryFit(bfNameParam, workoutLength); int nthX5d = 0; int idx = 0; for (int ii = 0; ii < this.Count; ii++) { if (this.blocks[ii].Type != BlockType.AdjustSpeedAndIncline) { bf.Insert(idx++, this.blocks[ii].Clone()); } else { idx++; CommandBlock newX5d = bfToBeReplaced.GetNth0x5dBlock(nthX5d++); // CommandBlock newX5d = this.blocks[ii].Clone(); // CommandBlock newX5d = bf.GetNth0x5dBlock(nthX5d-1); int indexOfNthX5d = bf.IndexOfNth0x5dBlock(nthX5d - 1); // newX5d = oldX5d; if (this.blocks[ii].IsGraduatable && nthX5d != CountOf0x5dBlocks())//don't increment the final x5d block //since it's used to end the program and set incline to 0 { newX5d.CurrentSpeed = this.blocks[ii].CurrentSpeed + speedGradient; newX5d.CurrentSpeedMetric = newX5d.CurrentSpeed * 1.609344; if (newX5d.CurrentSpeed > this.blocks[ii].SpeedSlider.Maximum) { newX5d.CurrentSpeed = this.blocks[ii].SpeedSlider.Maximum; } if (newX5d.CurrentSpeed < this.blocks[ii].SpeedSlider.Minimum) { newX5d.CurrentSpeed = this.blocks[ii].SpeedSlider.Minimum; } newX5d.CurrentIncline = this.blocks[ii].CurrentIncline + inclineGradient; if (newX5d.CurrentIncline > this.blocks[ii].InclineSlider.Maximum) { newX5d.CurrentIncline = this.blocks[ii].InclineSlider.Maximum; } if (newX5d.CurrentIncline < this.blocks[ii].InclineSlider.Minimum) { newX5d.CurrentIncline = this.blocks[ii].InclineSlider.Minimum; } } else if (!this.blocks[ii].IsGraduatable && nthX5d != CountOf0x5dBlocks()) //just copy the values { newX5d.CurrentSpeed = this.blocks[ii].CurrentSpeed; newX5d.CurrentSpeedMetric = this.blocks[ii].CurrentSpeed * 1.609344; if (newX5d.CurrentSpeed > this.blocks[ii].SpeedSlider.Maximum) { newX5d.CurrentSpeed = this.blocks[ii].SpeedSlider.Maximum; } if (newX5d.CurrentSpeed < this.blocks[ii].SpeedSlider.Minimum) { newX5d.CurrentSpeed = this.blocks[ii].SpeedSlider.Minimum; } newX5d.CurrentIncline = this.blocks[ii].CurrentIncline; if (newX5d.CurrentIncline > this.blocks[ii].InclineSlider.Maximum) { newX5d.CurrentIncline = this.blocks[ii].InclineSlider.Maximum; } if (newX5d.CurrentIncline < this.blocks[ii].InclineSlider.Minimum) { newX5d.CurrentIncline = this.blocks[ii].InclineSlider.Minimum; } } newX5d.Invalidate(); try { bf.blocks[indexOfNthX5d] = newX5d; } catch (Exception e) { MessageBox.Show(e.ToString()); return(bf); } } } return(bf); }