public void CopyTo(CyPhyCOMInterfaces.IMgaTraceability copy) { foreach (var item in this.map) { string mapped; if (copy.TryGetMappedObject(item.Value, out mapped)) { copy.AddItem(item.Key, mapped); } else { copy.AddItem(item.Key, item.Value); } } }
public ComponentInfo(GME.MGA.IMgaFCO gmeObject, string modelType = null, CyPhyCOMInterfaces.IMgaTraceability traceability = null) { this.Name = gmeObject.Name; this.AbsPath = gmeObject.AbsPath; this.ID = gmeObject.ID; this.Path = this.GetPath(); this.Kind = gmeObject.Meta.Name; this.ModelType = modelType; if (this.Kind == typeof(CyPhy.Component).Name) { var component = CyPhyClasses.Component.Cast(gmeObject); this.AVMID = component.Attributes.AVMID; } if (traceability != null) { string id = string.Empty; if (traceability.TryGetMappedObject(gmeObject.ID, out id)) { GME.MGA.MgaFCO baseComponent = gmeObject.Project.GetFCOByID(id); if (baseComponent != null) { if (baseComponent.Status == 1) { // object is already deleted // try to get it in a different way. var idChain = gmeObject.RegistryValue["Elaborator/ID_Chain"]; if (string.IsNullOrWhiteSpace(idChain) == false) { id = idChain.Split(new char[] { ',' }).LastOrDefault(); if (id != null) { baseComponent = gmeObject.Project.GetFCOByID(id); if (baseComponent != null) { this.Reference = new ComponentInfo(baseComponent, modelType); } } } } else { this.Reference = new ComponentInfo(baseComponent, modelType); } } } } }
/// <summary> /// Intializes a new instance of the <see cref="CodeGenerator"/> class. /// </summary> /// <param name="parameters">Passed through the Main function in CyPhyGUIs API.</param> /// <param name="logger">Instance of logger to log to.</param> /// <param name="traceability">Traceability map from CyPhyElborate (and if called by it, the MasterInterpreter too).</param> public CodeGenerator(CyPhyGUIs.IInterpreterMainParameters parameters, CyPhyGUIs.GMELogger logger, CyPhyCOMInterfaces.IMgaTraceability traceability) { this.Logger = logger; this.MainParameters = parameters; this.modelicaSettings = this.MainParameters.config as CyPhy2Modelica_v2Settings; this.traceability = traceability; this.LimitDefintion = new LimitDefinition(); this.reservedPackageNames = new List<string>() { "Modelica", MainPackage }; this.instanceURIMap = new Dictionary<string, ComponentInfo>(); this.modelURIMap = new Dictionary<string, ComponentInfo>(); this.extendsURIMap = new Dictionary<string, ComponentInfo>(); this.pccInputs = new List<PCCInputDistribution>(); this.ModelicaURIMap = new ComponentMap() { InstanceMapping = this.instanceURIMap, ModelMapping = this.modelURIMap, ExtendsMapping = this.extendsURIMap }; var externalPackages = (this.MainParameters.config as CyPhy2Modelica_v2Settings).IncludeDirectoryPath; foreach (var packagePath in externalPackages) { this.reservedPackageNames.Add(ModelicaLibrary.GetLibraryFromPath(packagePath).Name); } this.requirementMetrics = new List<RequirementMetric>(); }
public static IEnumerable<IMgaObject> getTracedObjectOrSelf(this IEnumerable<IMgaObject> enumerable, CyPhyCOMInterfaces.IMgaTraceability traceability) { foreach (var obj in enumerable) { string originalID; if (traceability != null && traceability.TryGetMappedObject(obj.ID, out originalID)) { yield return obj.Project.GetObjectByID(originalID); } else { yield return obj; } } }
public static bool MatchStructuralInterfaceDatums(DataRep.StructuralInterfaceConstraint a, DataRep.StructuralInterfaceConstraint b, List<Tuple<DataRep.Datum, DataRep.Datum>> constraintPairs, CyPhyCOMInterfaces.IMgaTraceability Traceability) { string apath = a.CyPhyImpl.Path, bpath = b.CyPhyImpl.Path; // Means no error bool result = false; if (!DataRep.StructuralInterfaceConstraint.MatchSIType(a.InterfaceDefinition, b.InterfaceDefinition)) //if (!MatchSIType(a.InterfaceDefinition, b.InterfaceDefinition)) { Logger.Instance.AddLogMessage("Mismatched Type attribute on connected StructuralInterfaces. Interface 1: [" + a.CyPhyImpl.ToHyperLink(Traceability) + "] (" + a.InterfaceDefinition + "). Interface 2: [" + b.CyPhyImpl.ToHyperLink(Traceability) + "] (" + b.InterfaceDefinition + ")", Severity.Error); return true; } List<string> adatumnames = a.DatumList.Keys.ToList(); List<string> bdatumnames = b.DatumList.Keys.ToList(); if (adatumnames.Count() != bdatumnames.Count()) { Logger.Instance.AddLogMessage("Connected StructuralInterfaces have different number of datum ports: [" + a.CyPhyImpl.ToHyperLink(Traceability) + ", " + b.CyPhyImpl.ToHyperLink(Traceability) + "]", Severity.Error); return true; } if (adatumnames.Count() > 1 && bdatumnames.Count() > 1) { foreach (KeyValuePair<string, DataRep.Datum> adatum in a.DatumList) { if (b.DatumList.ContainsKey(adatum.Key)) { DataRep.DatumType a_type = adatum.Value.Type; DataRep.DatumType b_type = b.DatumList[adatum.Key].Type; if (a_type != b_type) { Logger.Instance.AddLogMessage("Matching datum ports are different type [" + a.CyPhyImpl.ToHyperLink(Traceability) + "," + b.CyPhyImpl.ToHyperLink(Traceability) + "]", Severity.Error); result = true; continue; } else { if (a_type == DataRep.DatumType.Surface) { if (adatum.Value.Alignment != b.DatumList[adatum.Key].Alignment) { Logger.Instance.AddLogMessage("Matching Surface datum ports have different Alignment attributes [" + a.CyPhyImpl.ToHyperLink(Traceability) + "," + b.CyPhyImpl.ToHyperLink(Traceability) + "]", Severity.Error); result = true; continue; } } var atumple = new Tuple<DataRep.Datum, DataRep.Datum>(adatum.Value, b.DatumList[adatum.Key]); constraintPairs.Add(atumple); } adatumnames.Remove(adatum.Key); bdatumnames.Remove(adatum.Key); } } if (adatumnames.Any() || bdatumnames.Any()) { Logger.Instance.AddLogMessage(String.Format("Connected connectors contain unmatched named feature ports. Port names must match inside connectors. Connectors are: {0} ({1}) and {2} ({3}).", a.CyPhyImpl.ToHyperLink(Traceability), String.Join(",", adatumnames.ToArray()), b.CyPhyImpl.ToHyperLink(Traceability), String.Join(",", bdatumnames)), Severity.Error); return true; } } else { var atuple = new Tuple<DataRep.Datum, DataRep.Datum>(a.DatumList.Values.First(), b.DatumList.Values.First()); constraintPairs.Add(atuple); } return result; }