Beispiel #1
0
        public static string ToMgaHyperLink <T>(this T subject, CyPhyCOMInterfaces.IMgaTraceability elaboratedObjects = null, bool useName = false)
            where T : GME.MGA.IMgaObject
        {
            StringBuilder sb = new StringBuilder();

            if (elaboratedObjects != null)
            {
                string id = string.Empty;
                if (elaboratedObjects.TryGetMappedObject(subject.ID, out id))
                {
                    GME.MGA.MgaFCO fco = subject.Project.GetFCOByID(id);
                    if (fco != null)
                    {
                        // TODO: maybe get it until we reach the original source???
                        sb.AppendFormat("<a href=\"mga:{0}\">{1}</a>", fco.ID, SecurityElement.Escape(fco.Name));
                        return(sb.ToString());
                    }
                }
            }

            if (useName)
            {
                sb.AppendFormat("<a href=\"mga:{0}\">{1}</a>", subject.ID, subject.Name);
            }
            else
            {
                sb.AppendFormat("<a href=\"mga:{0}\">{1}</a>", subject.ID, getPath(subject));
            }
            return(sb.ToString());
        }
Beispiel #2
0
 public SmartLogger()
 {
     this.Traceability  = new META.MgaTraceability();
     this.LoggingLevel  = MessageType_enum.Debug;
     this.m_textWriters = new List <TextWriter>();
     this.m_filenames   = new List <string>();
 }
Beispiel #3
0
        public CADComponent(CyPhy.Component cyphycomp, string ProjectDirectory, bool size2fit = false,
                            CyPhyCOMInterfaces.IMgaTraceability Traceability = null, CyPhyClasses.CADModel.AttributesClass.FileFormat_enum cadFormat = CyPhyClasses.CADModel.AttributesClass.FileFormat_enum.Creo)
        {
            Type = CADDataType.Component;
            StructuralInterfaceNodes = new Dictionary <string, StructuralInterfaceConstraint>();
            DisplayID            = cyphycomp.Attributes.InstanceGUID;
            Id                   = cyphycomp.ID;
            GraphvizID           = UtilityHelpers.CleanString2(cyphycomp.ID, 50, "-");
            AVMID                = cyphycomp.Attributes.AVMID;
            RevID                = "";
            VersionID            = cyphycomp.Attributes.Version;
            CADFormat            = cadFormat;
            Name                 = cyphycomp.Name;
            CadParameters        = new List <CADParameter>();
            ModelType            = "Part";
            Size2Fit             = size2fit;
            MaterialName         = "";
            CyPhyModelPath       = cyphycomp.GetDirectoryPath(ProjectDirectory: ProjectDirectory);
            Classification       = cyphycomp.Attributes.Classifications;
            HyperLink            = cyphycomp.ToHyperLink();
            CadElementsList      = new List <CAD.ElementType>();
            pointCoordinatesList = new List <TestBenchModel.TBComputation>();
            this.Traceability    = Traceability;

            CreateStructuralInterfaceEquivalent(cyphycomp);

            AddManufacturingParameters(cyphycomp);

            var specialinstr = cyphycomp.Children.ParameterCollection.Where(p => p.Name.ToUpper() == SpecialInstrParamStr);

            if (specialinstr.Any())
            {
                SpecialInstructions = specialinstr.First().Attributes.Value.Replace("\"", "");
            }

            // META-3555 hack
            if (cyphycomp.Children.CADModelCollection.Any())
            {
                foreach (var datum in cyphycomp.Children.CADModelCollection.First().Children.CADDatumCollection)
                {
                    if (datum.Name == "FRONT" || datum.Name == "TOP" || datum.Name == "RIGHT")
                    {
                        SpecialDatums.Add(new Datum(datum, "", false));
                    }
                }
            }

            foreach (var prop in cyphycomp.Children.PropertyCollection)
            {
                if (prop.Name.StartsWith("METADATA."))
                {
                    MetaData.Add(prop.Name.Substring(9), prop.Attributes.Value);
                }
            }

            TraverseComposites(cyphycomp);
            CreatePointCoordinatesList(cyphycomp);
        }
Beispiel #4
0
        public static IMgaObject getTracedObjectOrSelf(this IMgaObject obj, CyPhyCOMInterfaces.IMgaTraceability traceability)
        {
            string originalID;

            if (traceability != null && traceability.TryGetMappedObject(obj.ID, out originalID))
            {
                return(obj.Project.GetObjectByID(originalID));
            }
            else
            {
                return(obj);
            }
        }
Beispiel #5
0
 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);
         }
     }
 }
Beispiel #6
0
        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);
                        }
                    }
                }
            }
        }
Beispiel #7
0
        /// <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>();
        }
Beispiel #8
0
 public static string ToHyperLink <T>(this T subject, CyPhyCOMInterfaces.IMgaTraceability elaboratedObjects = null, bool useName = false)
     where T : ISIS.GME.Common.Interfaces.Base
 {
     return(CyPhyCOMInterfaces.TraceabilityExtensions.ToMgaHyperLink(subject.Impl, elaboratedObjects, useName));
 }
Beispiel #9
0
        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);
        }