private void BBuild_Click(object sender, EventArgs e) { Action = new TimeAction(); Action.Name = TBName.Text; try { Action.Timeout = float.Parse(TBTimout.Text); } catch (System.Exception ex) { MessageBox.Show("Timeout value must be a float"); return; } try { Action.TimeToPass = float.Parse(TBTimeToPass.Text); } catch (System.Exception ex) { MessageBox.Show("Time Period value must be a float"); return; } DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); }
public void BuildFromAction(TimeAction pastAction) { TBName.Text = pastAction.Name; TBTimout.Text = pastAction.Timeout.ToString(); TBTimeToPass.Text = pastAction.TimeToPass.ToString(); }
private Action LoadAction(StreamReader streamReader) { Action action = null; string line = streamReader.ReadLine();//read ActionType: string type = line.Substring(11); if (type == "Position") { PositionAction posAction = new PositionAction(); posAction.Name = streamReader.ReadLine().Substring(11); //read name: posAction.Timeout = float.Parse(streamReader.ReadLine().Substring(8)); //read FBP: posAction.FirstBodyPart = int.Parse(streamReader.ReadLine().Substring(4)); //read FBP: posAction.Relationship = int.Parse(streamReader.ReadLine().Substring(9)); //read Relationship: posAction.SecondBodyPart = int.Parse(streamReader.ReadLine().Substring(4)); //read SBP: posAction.UpperBoundsRelationshipValue = float.Parse(streamReader.ReadLine().Substring(17)); //read UpperBoundsValue: posAction.LowerBoundsRelationshipValue = float.Parse(streamReader.ReadLine().Substring(17)); //read LowerBoundsValue: action = posAction; } else if (type == "Velocity") { VelocityAction velAction = new VelocityAction(); velAction.Name = streamReader.ReadLine().Substring(11); //read name: velAction.Timeout = float.Parse(streamReader.ReadLine().Substring(8)); //read FBP: velAction.FirstBodyPart = int.Parse(streamReader.ReadLine().Substring(4)); //read FBP: velAction.Relationship = int.Parse(streamReader.ReadLine().Substring(9)); //read Relationship: velAction.RelationshipValue = float.Parse(streamReader.ReadLine().Substring(6)); //read RelationshipL: action = velAction; } else if (type == "ConditionalVelocity") { ConditionalVelocityAction velAction = new ConditionalVelocityAction(); velAction.Name = streamReader.ReadLine().Substring(11); //read name: velAction.Timeout = float.Parse(streamReader.ReadLine().Substring(8)); //read FBP: velAction.FirstBodyPart = int.Parse(streamReader.ReadLine().Substring(4)); //read FBP: velAction.VelocityRelationship = int.Parse(streamReader.ReadLine().Substring(17)); //read VelocityRelation: velAction.ConditionalBodyPart = int.Parse(streamReader.ReadLine().Substring(12)); //read ConditionBP: velAction.ConditionRelationship = int.Parse(streamReader.ReadLine().Substring(24)); //read ConditionalRelationship: velAction.RelationshipValue = float.Parse(streamReader.ReadLine().Substring(14)); //read VelocityValue: if (streamReader.ReadLine() == "-----InnerAction-----") { velAction.PassAction = ( AndAction )LoadAction(streamReader); } action = velAction; } else if (type == "And") { AndAction andAction = new AndAction(); andAction.Name = streamReader.ReadLine().Substring(11); //read name: andAction.Timeout = float.Parse(streamReader.ReadLine().Substring(8)); //read FBP: while (true) { line = streamReader.ReadLine(); if (line == "-----MultiEnd-----") { break; } else if (line == "-----InnerAction-----") { andAction.AddAction(LoadAction(streamReader)); } } action = andAction; } else if (type == "Or") { OrAction andAction = new OrAction(); andAction.Name = streamReader.ReadLine().Substring(11); //read name: andAction.Timeout = float.Parse(streamReader.ReadLine().Substring(8)); //read FBP: while (true) { line = streamReader.ReadLine(); if (line == "-----MultiEnd-----") { break; } else if (line == "-----InnerAction-----") { andAction.AddAction(LoadAction(streamReader)); } } action = andAction; } else if (type == "Time") { TimeAction timeAction = new TimeAction(); timeAction.Name = streamReader.ReadLine().Substring(11); //read name: timeAction.Timeout = float.Parse(streamReader.ReadLine().Substring(8)); //read FBP: timeAction.TimeToPass = float.Parse(streamReader.ReadLine().Substring(11)); //read TimeToPass action = timeAction; } return(action); }