private void ConvertFromParameter(CyPhy.Parameter parameter) { try { LoadValue = String.IsNullOrEmpty(parameter.Attributes.Value) ? 0 : double.Parse(parameter.Attributes.Value); } catch (InvalidOperationException) { Logger.Instance.AddLogMessage("Parameter" + parameter.Name + " was not found in Load.", Severity.Error); } catch (FormatException) { Logger.Instance.AddLogMessage("Parameter" + parameter.Name + " is not a valid floating point value.", Severity.Error); } if (parameter.Referred != null) { if (parameter.Referred.unit != null) { if (!String.IsNullOrEmpty(parameter.Referred.unit.Name)) { Unit = parameter.Referred.unit.Name; } } } }
// Extend Cyber CAT module to create component-level Parameters for Cyber Model's Parameters void CyberModuleImportExtension(CyPhy.CyberModel ProcessedCyberModel) { // When the user imports a Cyber Model, the current implementation creates a CyPhy CyberModel object. After this point: int numComponentParams = 0; foreach (CyPhy.ModelicaParameter parm in ProcessedCyberModel.Children.ModelicaParameterCollection) { // - For each ModelicaParameter object, create a corresponding Parameter object under the parent Component. // - Give the Parameter the same name CyPhy.Parameter newparam = CyPhyClasses.Parameter.Create(GetCurrentComp()); newparam.Name = parm.Name; if (!String.IsNullOrWhiteSpace(parm.Attributes.Value)) { newparam.Attributes.Value = parm.Attributes.Value; } // - Create a CyberParameterPortMap connection from the Property to the CyberParameter CyPhy.ModelicaParameterPortMap ppmap = CyPhyClasses.ModelicaParameterPortMap.Connect(newparam, parm); ppmap.Name = parm.Name; // - Perform some layout "niceification" on the resulting objects. foreach (MgaPart item in (newparam.Impl as MgaFCO).Parts) { item.SetGmeAttrs(null, PARAMETER_START_X, greatest_current_y + PARAMETER_START_Y + (numComponentParams * PARAMETER_ADJUST_Y)); } numComponentParams++; } }
public CyPhy.Parameter Create(ISIS.GME.Common.Interfaces.Container container) { CyPhy.Parameter result = ISIS.GME.Common.Utils.CreateObject <ISIS.GME.Dsml.CyPhyML.Classes.Parameter>(container, "" + ISIS.GME.Dsml.CyPhyML.Classes.Parameter.DefaultRole.Parameter.ToString()); result.Name = Name; result.Attributes.Value = DefaultValue; result.Attributes.DataType = Type; return(result); }
private CyPhy.Parameter FollowParam(CyPhy.Parameter input) { CyPhy.ValueFlow conn = null; while ((conn = input.SrcConnections.ValueFlowCollection.FirstOrDefault()) != null) { input = conn.SrcEnds.Parameter; } return(input); }
private int GetParamOrDefault(CyPhy.Parameter param, int def) { if (param == null || param.Attributes.Value.Length == 0) { GMEConsole.Warning.WriteLine("No parameter was specified, assuming " + def); return(def); } else { return(Int32.Parse(param.Attributes.Value)); } }
private CyPhy.Parameter GetGravityLoadParam(CyPhy.GravityLoad gravityload, string name, out double param) { try { CyPhy.Parameter prm = gravityload.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == name).First(); param = String.IsNullOrEmpty(prm.Attributes.Value) ? 0 : double.Parse(prm.Attributes.Value); return(prm); } catch (InvalidOperationException) { Logger.Instance.AddLogMessage("Parameter" + name + " was not found in AccelerationLoad.", Severity.Error); } catch (FormatException) { Logger.Instance.AddLogMessage("Parameter" + name + " is not a valid floating point value.", Severity.Error); } param = 0; return(null); }
private void btnConfigParams_Click(object sender, EventArgs e) { ConfigurationParametersForm confparams = new ConfigurationParametersForm(currentObj); if (confparams.ShowDialog() == System.Windows.Forms.DialogResult.OK) { foreach (var param in confparams.SelectedTemplates) { try { CyPhy.Parameter cyphyparam = param.Create(currentObj); ((BindingList <ComponentParameterItem>)dgvParameters.DataSource).Add(new ComponentParameterItem((MgaFCO)cyphyparam.Impl)); } catch (Exception) { // Log something here } } } }
public FEAThermalElement(CyPhy.Parameter param) { Type = ((MgaFCO)param.Impl).MetaRole.Name; ConvertFromParameter(param); }
private string GetSimulationScriptEntry(CyPhy.CarSimulation sim) { if (sim.Kind == "Acceleration") { AccelSim outp = new AccelSim(); CyPhy.Acceleration accelsim = sim as CyPhy.Acceleration; CyPhy.Parameter endtimeparam = accelsim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault(); int endtime = GetParamOrDefault(endtimeparam, 20); outp.ModelName = "DefaultCar"; outp.InitialVelocity = "3"; outp.NumSteps = (endtime * 10).ToString(); outp.EndTime = endtime.ToString(); outp.FinalThrottle = "100.0"; outp.StepDuration = "1.0"; outp.StartTime = "0.0"; outp.ShiftGears = "no"; outp.OutputPrefix = "test"; outp.OutputPostfix = sim.Kind; outp.GearPosition = "2"; outp.Acceleration = "0"; outp.RoadData = "acar_shared/roads.tbl/2d_flat.rdf"; CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime" }); return(outp.TransformText()); } else if (sim.Kind == "Braking") { BrakingSim outp = new BrakingSim(); outp.ModelName = "DefaultCar"; outp.InitialVelocity = "20"; outp.NumSteps = "300"; outp.EndTime = "30"; outp.FinalBrake = "100.0"; outp.StepDuration = "1.0"; outp.StartValue = "0.0"; outp.OutputPrefix = "test"; outp.OutputPostfix = sim.Kind; outp.GearPosition = "5"; return(outp.TransformText()); } else if (sim.Kind == "ConstantSpeed") { ConstantSpeedSim outp = new ConstantSpeedSim(); CyPhy.ConstantSpeed csim = sim as CyPhy.ConstantSpeed; CyPhy.Parameter endtimeparam = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault(); CyPhy.Parameter speedparam = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Speed").FirstOrDefault(); CyPhy.Parameter gearparam = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Gear").FirstOrDefault(); int endtime = GetParamOrDefault(endtimeparam, 20); int speed = GetParamOrDefault(speedparam, 15); int gear = GetParamOrDefault(gearparam, 2); outp.ModelName = "DefaultCar"; outp.InitialVelocity = speed.ToString(); outp.NumSteps = (endtime * 10).ToString(); outp.GearPosition = gear.ToString(); outp.OutputPrefix = "test"; outp.OutputPostfix = sim.Kind; outp.EndTime = endtime.ToString(); outp.RoadData = "roads.tbl\\pothole_4in.rdf"; CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime" }); CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(speedparam).Name, ParamID = "Speed" }); CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(gearparam).Name, ParamID = "Gear" }); /*AccelSim outp = new AccelSim(); * CyPhy.ConstantSpeed csim = sim as CyPhy.ConstantSpeed; * CyPhy.Parameter endtimeparam = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault(); * int endtime = GetParamOrDefault(endtimeparam, 20); * outp.ModelName = "DefaultCar"; * outp.InitialVelocity = "3"; * outp.NumSteps = (endtime * 10).ToString(); * outp.EndTime = endtime.ToString(); * outp.FinalThrottle = "100.0"; * outp.StepDuration = "5.0"; * outp.StartTime = "0.0"; * outp.ShiftGears = "no"; * outp.OutputPrefix = "test"; * outp.OutputPostfix = sim.Kind; * outp.GearPosition = "2"; * outp.Acceleration = "1"; * outp.RoadData = "isis_test\\roads.tbl\\pothole_4in.rdf"; * CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime" }); */ return(outp.TransformText()); } else if (sim.Kind == "Steering") { SteerSim outp = new SteerSim(); CyPhy.Steering ssim = sim as CyPhy.Steering; CyPhy.Parameter endtimeparam = ssim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault(); CyPhy.Parameter speedparam = ssim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Speed").FirstOrDefault(); CyPhy.Parameter angleparam = ssim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Angle").FirstOrDefault(); int endtime = GetParamOrDefault(endtimeparam, 20); int speed = GetParamOrDefault(speedparam, 50); int angle = GetParamOrDefault(angleparam, 20); outp.ModelName = "DefaultCar"; outp.OutputPrefix = "test"; outp.OutputPostfix = sim.Kind; outp.EndTime = endtime.ToString(); outp.InitialVelocity = speed.ToString(); outp.NumSteps = (endtime * 10).ToString(); outp.SteerAngle = angle.ToString(); outp.GearPosition = "1"; CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime" }); CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(speedparam).Name, ParamID = "Speed" }); CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(angleparam).Name, ParamID = "Angle" }); return(outp.TransformText()); } else { GMEConsole.Warning.WriteLine("Unknown simulation type:" + sim.Kind); } return(null); }