Beispiel #1
0
        public static HashSet <CyPhyML.Component> getCyPhyMLComponentSet(CyPhyML.TestBench cyPhyMLTestBench)
        {
            HashSet <CyPhyML.Component> cyPhyMLComponentSet = new HashSet <CyPhyML.Component>();

            foreach (CyPhyML.TopLevelSystemUnderTest cyPhyMLTopLevelSystemUnderTest in cyPhyMLTestBench.Children.TopLevelSystemUnderTestCollection)
            {
                CyPhyML.DesignEntity cyPhyMLDesignEntity = cyPhyMLTopLevelSystemUnderTest.Referred as CyPhyML.DesignEntity;
                if (cyPhyMLDesignEntity is CyPhyML.ComponentAssembly)
                {
                    cyPhyMLComponentSet.UnionWith(getCyPhyMLComponentSet(cyPhyMLDesignEntity as CyPhyML.ComponentAssembly));
                }
            }

            foreach (CyPhyML.ComponentAssembly cyPhyMLComponentAssembly in cyPhyMLTestBench.Children.ComponentAssemblyCollection)
            {
                if ((cyPhyMLComponentAssembly.Impl as MgaFCO).MetaRole.Name != "TopLevelSystemUnderTest")
                {
                    continue;
                }

                cyPhyMLComponentSet.UnionWith(getCyPhyMLComponentSet(cyPhyMLComponentAssembly));
            }

            return(cyPhyMLComponentSet);
        }
Beispiel #2
0
 private static String GetDesignSpaceSourceObjectID(CyPhy.ComponentRef cr)
 {
     foreach (CyPhy.BuiltDesignEntityRef bdef in cr.ReferencedBy.BuiltDesignEntityRef)
     {
         foreach (CyPhy.Built built in bdef.SrcConnections.BuiltCollection)
         {
             CyPhy.DesignEntityRef der       = built.SrcEnds.DesignEntityRef;
             CyPhy.DesignEntity    de_Source = der.Referred.DesignEntity;
             return(de_Source.Guid.ToString());
         }
     }
     return("");
 }
Beispiel #3
0
        public bool SaveDesign(CyPhy.DesignEntity designEntity)
        {
            if (designEntity == null)
            {
                throw new ArgumentNullException("designEntity");
            }

            string outputFolder = "design-exporter-output";

            if (designEntity is CyPhy.DesignContainer)
            {
                outputFolder = this.GetDesignSpacesFolder();
            }
            else if (designEntity is CyPhy.ComponentAssembly)
            {
                outputFolder = this.GetDesignsFolder();
            }

            try
            {
                this.infoTextWriter.WriteLine("Exporting design {0}", designEntity.Name);
                var design = CyPhy2DesignInterchange.CyPhy2DesignInterchange.Convert(designEntity);
                //design.SaveToFile(Path.GetFullPath(Path.Combine(outputFolder, design.Name + ".adm")));
                OpenMETA.Interchange.AvmXmlSerializer.SaveToFile(Path.GetFullPath(Path.Combine(outputFolder, design.Name + ".adm")), design);

                string designFileName = Path.Combine(".", Path.GetFileName(outputFolder), design.Name + ".adm").Replace('\\', '/');
                if (designEntity is CyPhy.DesignContainer)
                {
                    if (this.Project.DesignSpaceModels.Contains(designFileName) == false)
                    {
                        this.Project.DesignSpaceModels.Add(designFileName);
                    }
                }
                else if (designEntity is CyPhy.ComponentAssembly)
                {
                    if (this.Project.Configurations.Contains(designFileName) == false)
                    {
                        this.Project.Configurations.Add(designFileName);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                this.errorTextWriter.WriteLine("Exception in CyPhy2DesignInterchange: {0}", ex);
                return(false);
            }
        }
Beispiel #4
0
        private string ExportToFile(CyPhy.DesignEntity de, String s_outFolder)
        {
            // Elaborate first
            var traceability = CallElaborator(de.Impl.Project, de.Impl as MgaFCO, null, 128, true);

            var    dm            = CyPhy2DesignInterchange.CyPhy2DesignInterchange.Convert(de, traceability);
            String s_outFilePath = String.Format("{0}\\{1}.adm", s_outFolder, Safeify(de.Name));

            //dm.SaveToFile(s_outFilePath);
            OpenMETA.Interchange.AvmXmlSerializer.SaveToFile(Path.GetFullPath(Path.Combine(s_outFolder, Safeify(de.Name) + ".adm")), dm);

            CheckForDuplicateIDs(dm);

            return(s_outFilePath);
        }
Beispiel #5
0
        private static String GetOrSetID(CyPhy.DesignEntity de)
        {
            int id = de.Attributes.ID;

            if (id == 0)
            {
                de.Attributes.ID = de.Guid.GetHashCode();
                foreach (CyPhy.BuiltDesignEntityRef bdef in de.ReferencedBy.BuiltDesignEntityRef)
                {
                    foreach (CyPhy.Built built in bdef.SrcConnections.BuiltCollection)
                    {
                        CyPhy.DesignEntityRef der = built.SrcEnds.DesignEntityRef;
                        id = der.Guid.GetHashCode();
                    }
                }
            }
            if (id == 0)
            {
                id = Guid.NewGuid().GetHashCode();
            }

            de.Attributes.ID = id;
            return(id.ToString());
        }
Beispiel #6
0
        private void ImportContainer(CyPhy.DesignEntity cyphy_container, avm.Container ad_container)
        {
            cyphy_container.Name = ad_container.Name;
            AVM2CyPhyML.CyPhyMLComponentBuilder.SetLayoutData(ad_container, cyphy_container.Impl);

            Dictionary <Type, CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum> typeToAttribute = new Dictionary <Type, CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum>()
            {
                { typeof(avm.DesignSpaceContainer), CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Compound },
                { typeof(avm.Alternative), CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Alternative },
                { typeof(avm.Optional), CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Optional },
                { typeof(avm.Compound), CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Compound },
            };

            if (cyphy_container is CyPhy.DesignContainer)
            {
                ((CyPhy.DesignContainer)cyphy_container).Attributes.ContainerType = typeToAttribute[ad_container.GetType()];
                if (ad_container is avm.Alternative)
                {
                    ((IMgaFCO)cyphy_container.Impl).SetRegistryValueDisp("icon", "alternative_ds.png");
                }
                if (ad_container is avm.Optional)
                {
                    ((IMgaFCO)cyphy_container.Impl).SetRegistryValueDisp("icon", "optional_ds");
                }
            }
            if (ad_container is avm.Alternative)
            {
                foreach (var ad_mux in ((avm.Alternative)ad_container).ValueFlowMux)
                {
                    processMux((CyPhy.DesignContainer)cyphy_container, ad_mux);
                }
            }

            foreach (avm.Port avmPort in ad_container.Port)
            {
                if (cyphy_container is CyPhy.DesignContainer)
                {
                    process((CyPhy.DesignContainer)cyphy_container, avmPort);
                }
                else
                {
                    process((CyPhy.ComponentAssembly)cyphy_container, avmPort);
                }
            }
            foreach (var ad_connector in ad_container.Connector)
            {
                var cyphy_connector = CyPhyClasses.Connector.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container, typeof(CyPhyClasses.Connector)));
                processConnector(ad_connector, cyphy_connector);
            }

            foreach (var ad_prop in ad_container.Property)
            {
                if (cyphy_container is CyPhy.DesignContainer)
                {
                    process((CyPhy.DesignContainer)cyphy_container, ad_prop);
                }
                else
                {
                    process((CyPhy.ComponentAssembly)cyphy_container, ad_prop);
                }
            }

            foreach (var ad_componentinstance in ad_container.ComponentInstance)
            {
                CyPhy.ComponentRef cyphy_componentref;
                if (cyphy_container is CyPhy.DesignContainer)
                {
                    cyphy_componentref = CyPhyClasses.ComponentRef.Create((CyPhy.DesignContainer)cyphy_container);
                }
                else
                {
                    cyphy_componentref = CyPhyClasses.ComponentRef.Create((CyPhy.ComponentAssembly)cyphy_container);
                }
                ImportComponentInstance(ad_componentinstance, cyphy_componentref);
            }

            foreach (var ad_childcontainer in ad_container.Container1)
            {
                CyPhy.DesignEntity cyphy_childcontainer;
                if (cyphy_container is CyPhy.DesignContainer)
                {
                    cyphy_childcontainer = CyPhyClasses.DesignContainer.Create((CyPhy.DesignContainer)cyphy_container);
                }
                else
                {
                    cyphy_childcontainer = CyPhyClasses.ComponentAssembly.Create((CyPhy.ComponentAssembly)cyphy_container);
                }
                ImportContainer(cyphy_childcontainer, ad_childcontainer);
            }

            foreach (var simpleFormula in ad_container.Formula.OfType <avm.SimpleFormula>())
            {
                CyPhyML.SimpleFormula cyphy_simpleFormula = CyPhyClasses.SimpleFormula.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container, typeof(CyPhyClasses.SimpleFormula)));
                process(simpleFormula, cyphy_simpleFormula);
            }

            foreach (var complexFormula in ad_container.Formula.OfType <avm.ComplexFormula>())
            {
                var cyphy_customFormula = CyPhyClasses.CustomFormula.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container, typeof(CyPhyClasses.CustomFormula)));
                processComplexFormula(complexFormula, cyphy_customFormula);
            }
        }
Beispiel #7
0
        private void AddReferenceCoordinateSystemForAssemblyRoot(avm.Design ad_import, CyPhy.DesignEntity cyphy_container)
        {
            foreach (var root in ad_import.DomainFeature.OfType <avm.cad.AssemblyRoot>())
            {
                CyPhyML.ComponentRef componentRef;
                if (idToComponentInstanceMap.TryGetValue(root.AssemblyRootComponentInstance, out componentRef))
                {
                    MgaFCO rcs = CreateChild((ISIS.GME.Common.Interfaces.Model)componentRef.ParentContainer, typeof(CyPhyML.ReferenceCoordinateSystem));
                    rcs.Name = "AssemblyRoot";
                    CyPhyML.ReferenceCoordinateSystem componentRcs = componentRef.Referred.Component.Children.ReferenceCoordinateSystemCollection.FirstOrDefault();
                    if (componentRcs == null)
                    {
                        componentRcs = CyPhyClasses.ReferenceCoordinateSystem.Create(componentRef.Referred.Component);
                    }

                    ((MgaModel)componentRef.ParentContainer.Impl).CreateSimpleConnDisp(((MgaMetaModel)componentRef.ParentContainer.Impl.MetaBase).RoleByName[typeof(CyPhyML.RefCoordSystem2RefCoordSystem).Name],
                                                                                       rcs, (MgaFCO)componentRcs.Impl, null, (MgaFCO)componentRef.Impl);

                    while (rcs.ParentModel.ID != cyphy_container.ID)
                    {
                        var oldrcs = rcs;
                        rcs      = CreateChild(rcs.ParentModel.ParentModel, typeof(CyPhyML.ReferenceCoordinateSystem));
                        rcs.Name = "AssemblyRoot";
                        ((MgaModel)rcs.ParentModel).CreateSimplerConnDisp(((MgaMetaModel)rcs.ParentModel.Meta).RoleByName[typeof(CyPhyML.RefCoordSystem2RefCoordSystem).Name],
                                                                          rcs, oldrcs);
                    }
                }
            }
        }
Beispiel #8
0
        private static IEnumerable <CyPhy.DesignEntity> ExpandInnerOptionalAndAlternativesRecursively(CyPhy.DesignEntity designEntity)
        {
            // FIXME: Recursive function, when this will terminate?
            List <CyPhy.DesignEntity> possibleTargets = new List <CyPhy.DesignEntity>();

            if (designEntity is CyPhy.DesignContainer)
            {
                foreach (var childDesignContainer in (designEntity as CyPhy.DesignContainer).Children.DesignContainerCollection)
                {
                    if (childDesignContainer.Attributes.ContainerType == CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Compound)
                    {
                        possibleTargets.Add(childDesignContainer);
                    }
                    else
                    {
                        possibleTargets.AddRange(ExpandInnerOptionalAndAlternativesRecursively(childDesignContainer));
                    }
                }

                foreach (var item in (designEntity as CyPhy.DesignContainer).Children.ComponentAssemblyCollection)
                {
                    possibleTargets.Add(item);
                }

                foreach (var item in (designEntity as CyPhy.DesignContainer).Children.ComponentRefCollection)
                {
                    possibleTargets.Add(item);
                }

                foreach (var item in (designEntity as CyPhy.DesignContainer).Children.ComponentCollection)
                {
                    possibleTargets.Add(item);
                }
            }

            return(possibleTargets);
        }
Beispiel #9
0
        public static IMgaFCO FindTestInjectionTarget(
            CyPhy.TopLevelSystemUnderTest originalSut,
            IMgaReference originalTip,
            CyPhy.TopLevelSystemUnderTest targetSut)
        {
            if (originalSut == null)
            {
                throw new ArgumentNullException("originalSut");
            }

            if (originalTip == null)
            {
                throw new ArgumentNullException("originalTip");
            }

            if (targetSut == null)
            {
                throw new ArgumentNullException("targetSut");
            }

            // target that the reference has to be redirected
            IMgaFCO targetTipByBuilt   = null;
            IMgaFCO targetTipByAbsPath = null;

            // get tip reference

            // relative path
            var relativePath = string.Empty;

            // ASSUME original SUT is a design container
            if (originalSut.Referred.DesignContainer == null &&
                targetSut.Referred.ComponentAssembly == null)
            {
                throw new NotImplementedException();
            }

            var sutDesignContainer         = originalSut.Referred.DesignContainer;
            var sutComponentAssemblyTarget = targetSut.Referred.ComponentAssembly;

            // TOOD: Double check this cast
            CyPhy.DesignEntity originalDesignEntity = null;

            if (originalTip.Referred.Meta.Name == typeof(CyPhy.DesignContainer).Name)
            {
                originalDesignEntity = CyPhyClasses.DesignContainer.Cast(originalTip.Referred);
            }
            else if (originalTip.Referred.Meta.Name == typeof(CyPhy.Component).Name)
            {
                originalDesignEntity = CyPhyClasses.Component.Cast(originalTip.Referred);
            }
            else if (originalTip.Referred.Meta.Name == typeof(CyPhy.ComponentRef).Name)
            {
                originalDesignEntity = CyPhyClasses.ComponentRef.Cast(originalTip.Referred);
            }
            else if (originalTip.Referred.Meta.Name == typeof(CyPhy.ComponentAssembly).Name)
            {
                originalDesignEntity = CyPhyClasses.ComponentAssembly.Cast(originalTip.Referred);
            }


            List <CyPhy.DesignEntity> possibleDesignEntities = new List <CyPhy.DesignEntity>();

            possibleDesignEntities.Add(originalDesignEntity);

            // TODO: abspath for component assemblies / Component assembly refs too. Call function recursively
            if (originalTip.Referred.Meta.Name == typeof(CyPhy.DesignContainer).Name)
            {
                var designContainer = CyPhyClasses.DesignContainer.Cast(originalTip.Referred);
                if (designContainer.Attributes.ContainerType ==
                    CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Compound)
                {
                    // there could be a referece to the compound container

                    // BUG: no tracking of compound containers attempt to get it by AbsPath
                    // this implementation will work as long as
                    //    names are unqiue to Compound containes
                    //    structure as follows
                    //
                    // == PASS ==
                    // | Compound
                    // +-- Compound
                    //   |
                    //   +-- Compound
                    //
                    // == FAIL 1 == Have no idea how to get the path correctly
                    // | Compound
                    // +-- Alternative
                    //   |
                    //   +-- Compound
                    //
                    // == FAIL 2 == Have no idea how to get the path correctly
                    // | Compound
                    // +-- Optional
                    //   |
                    //   +-- Compound

                    // TODO: would be nice to use a regexp or something like that
                    Func <string, string> shortenAbsPath = new Func <string, string>((absPath) =>
                    {
                        // Example:
                        // input:  /@NewTesting|kind=Testing|relpos=0/@FEA_CompoundTIP_DS|kind=CADTestBench|relpos=0/@DesignContainer|kind=TopLevelSystemUnderTest|relpos=0
                        // output: /@NewTesting/@FEA_CompoundTIP_DS/@DesignContainer
                        return(string.Join("/", absPath.Split('/').Select(x => string.Join("", x.TakeWhile(y => y != '|')))));
                    });

                    var sutPath         = shortenAbsPath(originalSut.AllReferred.Impl.AbsPath);
                    var originalTipPath = shortenAbsPath(originalTip.Referred.AbsPath);
                    relativePath = originalTipPath.Substring(sutPath.Length);

                    // TODO: meta base name [kind] can be different if there are no unique path to the object.
                    targetTipByAbsPath = (targetSut.AllReferred.Impl as MgaModel).get_ObjectByPath(relativePath) as MgaFCO;
                }
                else
                {
                    // while optional and alternative containers are not tracked, get all ComponentAssembly, Component, ComponentRef recursively.
                    possibleDesignEntities.AddRange(ExpandInnerOptionalAndAlternativesRecursively(designContainer));
                }
            }

            Exception ex = null;

            foreach (var designEntity in possibleDesignEntities)
            {
                // Look for a DesignEntityRef, within a CWC, that points to this element in the Design Space.
                foreach (CyPhy.DesignEntityRef designEntityRef in designEntity.ReferencedBy.DesignEntityRef)
                {
                    var cwc = CyPhyClasses.CWC.Cast(designEntityRef.ParentContainer.Impl);

                    bool hasMatchingCARoot = false;

                    var caRefs = cwc.DstConnections.Config2CACollection.Select(x => x.DstEnds.ComponentAssemblyRef);
                    foreach (var caRef in caRefs)
                    {
                        if (caRef.AllReferred != null)
                        {
                            if ((caRef.AllReferred.Impl as MgaFCO).RootFCO.ID == (sutComponentAssemblyTarget.Impl as MgaFCO).RootFCO.ID)
                            {
                                hasMatchingCARoot = true;
                                break;
                            }
                        }
                    }

                    if (hasMatchingCARoot == false)
                    {
                        // do not log any messages since they irrelevant.
                        continue;
                    }

                    // TODO: log if design is dirty.


                    // get design entity ref where the refered object is the test injection point reference
                    //
                    // Multiple configuration (1, 2, 3, ...) can have the same design entity refs
                    //
                    //      design entity ref ----> DesignSpace element
                    //                                       ^
                    //                                       |
                    //      original test injection ---------

                    // verify root fco do match
                    if ((designEntityRef.Impl as MgaFCO).RootFCO != (sutDesignContainer.Impl as MgaFCO).RootFCO)
                    {
                        // in case user accidentally moves these object in the tree
                        string message = string.Format("Model does not contain traceablity information between the generated configurations and the design space. {0} will not be found in the original design space. Please try to export the configurations again using CAExporter or run the design space exploration tool.", originalTip.Meta.Name);

                        ex = new AnalysisModelTipNotFoundException(message);
                        continue;
                    }

                    // user may have leftovers from running CAExporter then deleting the CA
                    var builts           = designEntityRef.DstConnections.BuiltCollection.Where(x => x.DstEnds.BuiltDesignEntityRef.AllReferred != null);
                    var builtConnections = builts.Count();

                    if (builtConnections == 0)
                    {
                        // no built connection -> not good
                        string message = string.Format("No 'built' connection. Model does not contain traceablity information between the generated configurations and the design space. {0} will not be found in the original design space. Please try to export the configurations again using CAExporter or run the design space exploration tool.", originalTip.Meta.Name);

                        ex = new AnalysisModelTipNotFoundException(message);
                        continue;
                    }

                    if (builtConnections > 1)
                    {
                        // more than one built connection -> not good
                        string message = string.Format("There are more than one 'built' connections traceability is ambiguous. Model has to be fixed first. {0} will not be found in the original design space. Please try to export the configurations again using CAExporter or run the design space exploration tool.", originalTip.Meta.Name);

                        ex = new AnalysisModelTipNotFoundException(message);
                        continue;
                    }

                    // Get the Built connection and then the BuildDesignEntityRef.
                    // The BuildDesignEntityRef will point to our source object within a Component Assembly / configuration.
                    foreach (CyPhy.Built built in builts)
                    {
                        var builtDesignEntityRef = built.DstEnds.BuiltDesignEntityRef;

                        if ((builtDesignEntityRef.AllReferred.Impl as MgaFCO).RootFCO.ID == (sutComponentAssemblyTarget.Impl as MgaFCO).RootFCO.ID)
                        {
                            // verify that the component is inside the target design
                            // TODO: how this would work if it points to a component in a CA which is referred in the design???
                            targetTipByBuilt = builtDesignEntityRef.AllReferred.Impl as MgaFCO;
                        }
                    }
                }
            }


            if (targetTipByBuilt != null)
            {
                // prefer by built
                return(targetTipByBuilt);
            }
            else if (targetTipByAbsPath != null)
            {
                // fallback to by abs path
                return(targetTipByAbsPath);
            }
            else if (ex != null)
            {
                // not found
                throw ex;
            }
            else
            {
                return(null);
            }
        }
Beispiel #10
0
        protected IEnumerable <ContextCheckerResult> TestBenchReferences()
        {
            List <ContextCheckerResult> results = new List <ContextCheckerResult>();

            // at least one test bench ref
            if (this.testBenchSuite.Children.TestBenchRefCollection.Any())
            {
                var feedback = new ContextCheckerResult()
                {
                    Success = true,
                    Subject = this.testBenchSuite.Impl,
                    Message = "Test bench suite has at least one test bench reference."
                };

                results.Add(feedback);

                var ids = this.testBenchSuite
                          .Children
                          .TestBenchRefCollection
                          .Where(x => (x.Impl as GME.MGA.IMgaReference).Referred != null)
                          .Select(x => (x.Impl as GME.MGA.IMgaReference).Referred.ID)
                          .ToList();

                if (ids.Count != ids.Distinct().Count())
                {
                    feedback = new ContextCheckerResult()
                    {
                        Success = false,
                        Subject = this.testBenchSuite.Impl,
                        Message = "One test bench can be used only once. Remove the duplicates."
                    };

                    results.Add(feedback);
                }
                else
                {
                    feedback = new ContextCheckerResult()
                    {
                        Success = true,
                        Subject = this.testBenchSuite.Impl,
                        Message = "Each test bench used only once."
                    };

                    results.Add(feedback);
                }
            }
            else
            {
                var feedback = new ContextCheckerResult()
                {
                    Success = false,
                    Subject = this.testBenchSuite.Impl,
                    Message = "Test bench suite has no test bench reference. It must have at least one test bench reference."
                };

                results.Add(feedback);
            }

            CyPhy.DesignEntity designEntity = null;

            // no null refs
            foreach (var testBenchRef in this.testBenchSuite.Children.TestBenchRefCollection)
            {
                // check test benches
                if (testBenchRef.AllReferred == null)
                {
                    var feedback = new ContextCheckerResult()
                    {
                        Success = false,
                        Subject = testBenchRef.Impl,
                        Message = "Test bench reference cannot be null."
                    };

                    results.Add(feedback);

                    continue;
                }
                else if ((testBenchRef.AllReferred is CyPhy.TestBenchType) == false)
                {
                    var feedback = new ContextCheckerResult()
                    {
                        Success = false,
                        Subject = testBenchRef.Impl,
                        Message = "Currently only Test Bench Types are allowed."
                    };

                    results.Add(feedback);

                    continue;
                }
                else
                {
                    var feedback = new ContextCheckerResult()
                    {
                        Success = true,
                        Subject = testBenchRef.Impl,
                        Message = "Test bench reference is not null."
                    };

                    results.Add(feedback);
                }

                var testBench = testBenchRef.AllReferred as CyPhy.TestBenchType;

                // testbench ref is NOT null at this point
                ContextChecker testBenchChecker = ContextChecker.GetContextChecker(testBench.Impl as GME.MGA.MgaModel);

                testBenchChecker.TryCheck();

                results.AddRange(testBenchChecker.Details);

                // check top level system under test pointers
                var tlsut = testBench.Children.TopLevelSystemUnderTestCollection.FirstOrDefault();

                if (tlsut != null &&
                    tlsut.Referred.DesignEntity != null)
                {
                    if (designEntity == null)
                    {
                        designEntity = tlsut.Referred.DesignEntity;
                    }
                    else
                    {
                        if (designEntity.Impl.ID == tlsut.Referred.DesignEntity.ID)
                        {
                            var feedback = new ContextCheckerResult()
                            {
                                Success = true,
                                Subject = testBenchRef.Impl,
                                Message = "Test bench is defined for the same design or design space."
                            };

                            results.Add(feedback);
                        }
                        else
                        {
                            var feedback = new ContextCheckerResult()
                            {
                                Success = false,
                                Subject = testBenchRef.Impl,
                                Message = "Test bench does not point to the same design space."
                            };

                            results.Add(feedback);
                        }
                    }
                }
            }

            return(results);
        }
Beispiel #11
0
        private void ImportContainer(CyPhy.DesignEntity cyphy_container, avm.Container ad_container)
        {
            // If an ID is provided, add to map.
            if (!String.IsNullOrWhiteSpace(ad_container.ID))
            {
                id2DesignEntity.Add(ad_container.ID, cyphy_container);
                if (cyphy_container is CyPhyML.ComponentAssembly)
                {
                    ((CyPhyML.ComponentAssembly)cyphy_container).Attributes.ManagedGUID = ad_container.ID;
                }
            }

            cyphy_container.Name = ad_container.Name;
            if (cyphy_container is CyPhy.ComponentAssembly)
            {
                var asm = cyphy_container as CyPhy.ComponentAssembly;
                asm.Attributes.Classifications = String.Join("\n", ad_container);
            }
            AVM2CyPhyML.CyPhyMLComponentBuilder.SetLayoutData(ad_container, cyphy_container.Impl);

            Dictionary <Type, CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum> typeToAttribute = new Dictionary <Type, CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum>()
            {
                { typeof(avm.DesignSpaceContainer), CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Compound },
                { typeof(avm.Alternative), CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Alternative },
                { typeof(avm.Optional), CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Optional },
                { typeof(avm.Compound), CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Compound },
            };

            if (cyphy_container is CyPhy.DesignContainer)
            {
                ((CyPhy.DesignContainer)cyphy_container).Attributes.ContainerType = typeToAttribute[ad_container.GetType()];
                if (ad_container is avm.Alternative)
                {
                    ((IMgaFCO)cyphy_container.Impl).SetRegistryValueDisp("icon", "alternative_ds.png");
                }
                if (ad_container is avm.Optional)
                {
                    ((IMgaFCO)cyphy_container.Impl).SetRegistryValueDisp("icon", "optional_ds");
                }
            }
            if (ad_container is avm.Alternative)
            {
                foreach (var ad_mux in ((avm.Alternative)ad_container).ValueFlowMux)
                {
                    processMux((CyPhy.DesignContainer)cyphy_container, ad_mux);
                }
            }

            foreach (avm.Port avmPort in ad_container.Port)
            {
                if (cyphy_container is CyPhy.DesignContainer)
                {
                    process((CyPhy.DesignContainer)cyphy_container, avmPort);
                }
                else
                {
                    process((CyPhy.ComponentAssembly)cyphy_container, avmPort);
                }
            }
            foreach (var ad_connector in ad_container.Connector)
            {
                var cyphy_connector = CyPhyClasses.Connector.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container, typeof(CyPhyClasses.Connector)));
                processConnector(ad_connector, cyphy_connector);
            }

            foreach (var ad_prop in ad_container.Property)
            {
                if (cyphy_container is CyPhy.DesignContainer)
                {
                    process((CyPhy.DesignContainer)cyphy_container, ad_prop);
                }
                else
                {
                    process((CyPhy.ComponentAssembly)cyphy_container, ad_prop);
                }
            }

            foreach (var ad_componentinstance in ad_container.ComponentInstance)
            {
                CyPhy.ComponentRef cyphy_componentref;
                if (cyphy_container is CyPhy.DesignContainer)
                {
                    cyphy_componentref = CyPhyClasses.ComponentRef.Create((CyPhy.DesignContainer)cyphy_container);
                }
                else
                {
                    cyphy_componentref = CyPhyClasses.ComponentRef.Create((CyPhy.ComponentAssembly)cyphy_container);
                }
                ImportComponentInstance(ad_componentinstance, cyphy_componentref);
            }

            foreach (var ad_childcontainer in ad_container.Container1)
            {
                CyPhy.DesignEntity cyphy_childcontainer;
                if (cyphy_container is CyPhy.DesignContainer)
                {
                    cyphy_childcontainer = CyPhyClasses.DesignContainer.Create((CyPhy.DesignContainer)cyphy_container);
                    // TODO: assign cyphy_childcontainer.Attributes.Description (need it in CyPhyML.xme first)
                }
                else
                {
                    cyphy_childcontainer = CyPhyClasses.ComponentAssembly.Create((CyPhy.ComponentAssembly)cyphy_container);
                    if (string.IsNullOrEmpty(ad_childcontainer.Description) == false)
                    {
                        ((CyPhyML.ComponentAssembly)cyphy_childcontainer).Attributes.Description = ad_childcontainer.Description;
                    }
                }
                ImportContainer(cyphy_childcontainer, ad_childcontainer);
            }

            foreach (var constraint in ad_container.ContainerFeature.OfType <avm.schematic.eda.ExactLayoutConstraint>())
            {
                CyPhyML.ExactLayoutConstraint cyphy_constraint = CyPhyClasses.ExactLayoutConstraint.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container, typeof(CyPhyClasses.ExactLayoutConstraint)));
                cyphy_constraint.Name = typeof(CyPhyML.ExactLayoutConstraint).Name;
                SetLayoutData(constraint, cyphy_constraint.Impl);

                if (constraint.XSpecified)
                {
                    cyphy_constraint.Attributes.X = constraint.X.ToString();
                }
                if (constraint.YSpecified)
                {
                    cyphy_constraint.Attributes.Y = constraint.Y.ToString();
                }
                if (constraint.LayerSpecified)
                {
                    cyphy_constraint.Attributes.Layer = d_LayerEnumMap[constraint.Layer];
                }
                if (constraint.RotationSpecified)
                {
                    cyphy_constraint.Attributes.Rotation = d_RotationEnumMap[constraint.Rotation];
                }
                if (false == String.IsNullOrWhiteSpace(constraint.Notes))
                {
                    cyphy_constraint.Attributes.Notes = constraint.Notes;
                }

                foreach (var idTarget in constraint.ConstraintTarget)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (idToComponentInstanceMap.TryGetValue(idTarget, out compInstance))
                    {
                        CyPhyClasses.ApplyExactLayoutConstraint.Connect(cyphy_constraint, compInstance);
                    }
                }

                foreach (var idTarget in constraint.ContainerConstraintTarget)
                {
                    CyPhyML.DesignEntity deInstance;
                    if (id2DesignEntity.TryGetValue(idTarget, out deInstance))
                    {
                        CyPhyClasses.ApplyExactLayoutConstraint.Connect(cyphy_constraint, deInstance);
                    }
                }
            }

            foreach (var constraint in ad_container.ContainerFeature.OfType <avm.schematic.eda.RangeLayoutConstraint>())
            {
                CyPhyML.RangeLayoutConstraint cyphy_constraint = CyPhyClasses.RangeLayoutConstraint.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container, typeof(CyPhyClasses.RangeLayoutConstraint)));
                cyphy_constraint.Name = typeof(CyPhyML.RangeLayoutConstraint).Name;
                SetLayoutData(constraint, cyphy_constraint.Impl);

                cyphy_constraint.Attributes.LayerRange = d_LayerRangeEnumMap[constraint.LayerRange];
                if (constraint.XRangeMinSpecified && constraint.XRangeMaxSpecified)
                {
                    cyphy_constraint.Attributes.XRange = constraint.XRangeMin + ":" + constraint.XRangeMax;
                }
                if (constraint.YRangeMinSpecified && constraint.YRangeMaxSpecified)
                {
                    cyphy_constraint.Attributes.YRange = constraint.YRangeMin + ":" + constraint.YRangeMax;
                }
                if (constraint.TypeSpecified)
                {
                    cyphy_constraint.Attributes.Type = d_RangeType[constraint.Type];
                }
                if (false == String.IsNullOrWhiteSpace(constraint.Notes))
                {
                    cyphy_constraint.Attributes.Notes = constraint.Notes;
                }

                foreach (var compId in constraint.ConstraintTarget)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (idToComponentInstanceMap.TryGetValue(compId, out compInstance))
                    {
                        CyPhyClasses.ApplyRangeLayoutConstraint.Connect(cyphy_constraint, compInstance);
                    }
                }
                foreach (var idTarget in constraint.ContainerConstraintTarget)
                {
                    CyPhyML.DesignEntity deInstance;
                    if (id2DesignEntity.TryGetValue(idTarget, out deInstance))
                    {
                        CyPhyClasses.ApplyRangeLayoutConstraint.Connect(cyphy_constraint, deInstance);
                    }
                }
            }

            foreach (var constraint in ad_container.ContainerFeature.OfType <avm.schematic.eda.RelativeLayoutConstraint>())
            {
                CyPhyML.RelativeLayoutConstraint cyphy_constraint = CyPhyClasses.RelativeLayoutConstraint.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container, typeof(CyPhyClasses.RelativeLayoutConstraint)));
                cyphy_constraint.Name = typeof(CyPhyML.RelativeLayoutConstraint).Name;
                SetLayoutData(constraint, cyphy_constraint.Impl);

                if (constraint.XOffsetSpecified)
                {
                    cyphy_constraint.Attributes.XOffset = constraint.XOffset.ToString();
                }
                if (constraint.YOffsetSpecified)
                {
                    cyphy_constraint.Attributes.YOffset = constraint.YOffset.ToString();
                }
                if (constraint.RelativeLayerSpecified)
                {
                    cyphy_constraint.Attributes.RelativeLayer = d_RelativeLayer[constraint.RelativeLayer];
                }
                if (constraint.RelativeRotationSpecified)
                {
                    cyphy_constraint.Attributes.RelativeRotation = d_RelativeRotation[constraint.RelativeRotation];
                }

                if (false == String.IsNullOrWhiteSpace(constraint.Notes))
                {
                    cyphy_constraint.Attributes.Notes = constraint.Notes;
                }

                foreach (var compId in constraint.ConstraintTarget)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (idToComponentInstanceMap.TryGetValue(compId, out compInstance))
                    {
                        CyPhyClasses.ApplyRelativeLayoutConstraint.Connect(cyphy_constraint, compInstance);
                    }
                }
                if (string.IsNullOrWhiteSpace(constraint.Origin) == false)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (idToComponentInstanceMap.TryGetValue(constraint.Origin, out compInstance))
                    {
                        CyPhyClasses.RelativeLayoutConstraintOrigin.Connect(compInstance, cyphy_constraint);
                    }
                }
            }

            foreach (var constraint in ad_container.ContainerFeature.OfType <avm.schematic.eda.RelativeRangeLayoutConstraint>())
            {
                CyPhyML.RelativeRangeConstraint cyphy_constraint =
                    CyPhyClasses.RelativeRangeConstraint.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container,
                                                                          typeof(CyPhyClasses.RelativeRangeConstraint)));
                cyphy_constraint.Name = typeof(CyPhyML.RelativeRangeConstraint).Name;
                SetLayoutData(constraint, cyphy_constraint.Impl);

                if (constraint.RelativeLayerSpecified)
                {
                    cyphy_constraint.Attributes.RelativeLayer = d_RelativeRangeLayer[constraint.RelativeLayer];
                }
                if (constraint.XRelativeRangeMinSpecified && constraint.XRelativeRangeMaxSpecified)
                {
                    cyphy_constraint.Attributes.XOffsetRange = String.Format("{0}:{1}", constraint.XRelativeRangeMin, constraint.XRelativeRangeMax);
                }
                if (constraint.YRelativeRangeMinSpecified && constraint.YRelativeRangeMaxSpecified)
                {
                    cyphy_constraint.Attributes.YOffsetRange = String.Format("{0}:{1}", constraint.YRelativeRangeMin, constraint.YRelativeRangeMax);
                }
                if (false == String.IsNullOrWhiteSpace(constraint.Notes))
                {
                    cyphy_constraint.Attributes.Notes = constraint.Notes;
                }

                foreach (var compId in constraint.ConstraintTarget)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (idToComponentInstanceMap.TryGetValue(compId, out compInstance))
                    {
                        CyPhyClasses.ApplyRelativeRangeLayoutConstraint.Connect(cyphy_constraint, compInstance);
                    }
                }
                foreach (var idTarget in constraint.ContainerConstraintTarget)
                {
                    CyPhyML.DesignEntity deInstance;
                    if (id2DesignEntity.TryGetValue(idTarget, out deInstance))
                    {
                        CyPhyClasses.ApplyRelativeRangeLayoutConstraint.Connect(cyphy_constraint, deInstance);
                    }
                }

                if (string.IsNullOrWhiteSpace(constraint.Origin) == false)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (idToComponentInstanceMap.TryGetValue(constraint.Origin, out compInstance))
                    {
                        CyPhyClasses.RelativeRangeLayoutConstraintOrigin.Connect(compInstance, cyphy_constraint);
                    }
                }
            }

            foreach (var constraint in ad_container.ContainerFeature.OfType <avm.schematic.eda.GlobalLayoutConstraintException>())
            {
                CyPhyML.GlobalLayoutConstraintException cyphy_constraint =
                    CyPhyClasses.GlobalLayoutConstraintException.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container,
                                                                                  typeof(CyPhyClasses.GlobalLayoutConstraintException)));
                cyphy_constraint.Name = typeof(CyPhyML.GlobalLayoutConstraintException).Name;
                SetLayoutData(constraint, cyphy_constraint.Impl);

                switch (constraint.Constraint)
                {
                case avm.schematic.eda.GlobalConstraintTypeEnum.BoardEdgeSpacing:
                    cyphy_constraint.Attributes.Constraint = CyPhyClasses.GlobalLayoutConstraintException.AttributesClass.Constraint_enum.Board_Edge_Spacing;
                    break;

                default:
                    throw new NotSupportedException("GlobalConstraintException value of " + constraint.Constraint.ToString() + " isn't supported");
                }

                cyphy_constraint.Attributes.Notes = constraint.Notes;
                foreach (var compId in constraint.ConstraintTarget)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (idToComponentInstanceMap.TryGetValue(compId, out compInstance))
                    {
                        CyPhyClasses.ApplyGlobalLayoutConstraintException.Connect(cyphy_constraint, compInstance);
                    }
                }
                foreach (var idTarget in constraint.ContainerConstraintTarget)
                {
                    CyPhyML.DesignEntity deInstance;
                    if (id2DesignEntity.TryGetValue(idTarget, out deInstance))
                    {
                        CyPhyClasses.ApplyGlobalLayoutConstraintException.Connect(cyphy_constraint, deInstance);
                    }
                }
            }

            // Get ResourceDependencies
            if (cyphy_container.Kind == "ComponentAssembly")
            {
                var ca_cyphy_container = CyPhyClasses.ComponentAssembly.Cast(cyphy_container.Impl);
                foreach (var avmRes in ad_container.ResourceDependency)
                {
                    // hack for layoutFile
                    if (avmRes.Name == "layoutFile")
                    {
                        ((IMgaFCO)cyphy_container.Impl).set_RegistryValue("layoutFile", avmRes.Path);
                        foreach (var circuitLayout in ad_container.DomainModel.OfType <avm.schematic.eda.CircuitLayout>().Where(x => x.UsesResource == avmRes.ID))
                        {
                            ((IMgaFCO)cyphy_container.Impl).set_RegistryValue("layoutBox", circuitLayout.BoundingBoxes ?? "");
                        }
                        continue;
                    }

                    var cyphy_resource = CyPhyClasses.Resource.Create(ca_cyphy_container);
                    cyphy_resource.Name = avmRes.Name;

                    if (!String.IsNullOrWhiteSpace(avmRes.Hash))
                    {
                        cyphy_resource.Attributes.Hash = avmRes.Hash;
                    }
                    if (!String.IsNullOrWhiteSpace(avmRes.ID))
                    {
                        cyphy_resource.Attributes.ID = avmRes.ID;
                    }
                    if (!String.IsNullOrWhiteSpace(avmRes.Notes))
                    {
                        cyphy_resource.Attributes.Notes = avmRes.Notes;
                    }

                    cyphy_resource.Attributes.Path = avmRes.Path;

                    SetLayoutData(avmRes, cyphy_resource.Impl);
                }
            }

            foreach (var simpleFormula in ad_container.Formula.OfType <avm.SimpleFormula>())
            {
                CyPhyML.SimpleFormula cyphy_simpleFormula = CyPhyClasses.SimpleFormula.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container, typeof(CyPhyClasses.SimpleFormula)));
                process(simpleFormula, cyphy_simpleFormula);
            }

            foreach (var complexFormula in ad_container.Formula.OfType <avm.ComplexFormula>())
            {
                var cyphy_customFormula = CyPhyClasses.CustomFormula.Cast(CreateChild((ISIS.GME.Common.Interfaces.Model)cyphy_container, typeof(CyPhyClasses.CustomFormula)));
                processComplexFormula(complexFormula, cyphy_customFormula);
            }
        }
Beispiel #12
0
        // Only accept ComponentAssembly and DesignContainer
        public static DesignModel Convert(CyPhy.DesignEntity de)
        {
            if (!(de.Kind == "ComponentAssembly" || de.Kind == "DesignContainer"))
            {
                return(null);
            }

            ResetCache();

            var dm = new DesignModel {
                Name = de.Name
            };
            Container rootContainerType = null;


            if (de is CyPhy.ComponentAssembly)
            {
                String s_ID = (de as CyPhy.ComponentAssembly).Attributes.ConfigurationUniqueID;
                if (string.IsNullOrEmpty(s_ID))
                {
                    s_ID = Guid.NewGuid().ToString("B");
                    (de as CyPhy.ComponentAssembly).Attributes.ConfigurationUniqueID = s_ID;
                }
                if (s_ID.IndexOf("{") != 0)
                {
                    // Add curly braces
                    s_ID = string.Concat("{", s_ID, "}");
                }
                dm.DesignID = s_ID;

                rootContainerType = new Compound();
            }
            else if (de is CyPhy.DesignContainer)
            {
                dm.DesignID = (de as CyPhy.DesignContainer).Impl.GetGuidDisp();
                switch (((CyPhy.DesignContainer)de).Attributes.ContainerType)
                {
                case CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Compound:
                    rootContainerType = new Compound();
                    break;

                case CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Alternative:
                    rootContainerType = new Alternative();
                    break;

                case CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Optional:
                    rootContainerType = new Optional();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }


            // Add single ContainerType for the root level Container

            dm.Containers.AddItem(rootContainerType);
            rootContainerType.Name = de.Name;
            rootContainerType.id   = GetOrSetID(de);

            // Update DesignModel by calling recursive update method
            var innerPortInstances     = new Dictionary <CyPhy.Port, PortInstance>();
            var containerPortInstances = new Dictionary <CyPhy.Port, ContainerPort>();

            var innerStructuralPortInstances     = new Dictionary <CyPhy.Port, StructuralInterfaceInstance>();
            var containerStructuralPortInstances = new Dictionary <CyPhy.Port, ContainerStructuralInterface>();

            var connections    = new List <Connection>();
            var simpleFormulas = new Dictionary <CyPhy.SimpleFormula, ContainerCalculation>();

            // Can contain: ContainerNamedValue/ContainerCalculation/ComponentNamedValueInstance
            var valueInstances = new Dictionary <CyPhy.ValueFlowTarget, AVM.META.Design.ValueType>();


            UpdateSubContainers(new DesignPrimitivesWrapper(de), rootContainerType, dm, innerPortInstances, containerPortInstances, connections, simpleFormulas, valueInstances, innerStructuralPortInstances, containerStructuralPortInstances);


            #region Create AllPorts dictionary
            var allPorts = new Dictionary <CyPhy.Port, AbstractPort>();

            foreach (var portInstance in innerPortInstances)
            {
                allPorts.Add(portInstance.Key, portInstance.Value);
            }

            foreach (var containerPort in containerPortInstances)
            {
                allPorts.Add(containerPort.Key, containerPort.Value);
            }

            #endregion

            #region Create AllStructuralPorts dictionary
            var allStructuralPorts = new Dictionary <CyPhy.Port, AbstractStructuralInterface>();

            foreach (var abstractPortInstance in innerStructuralPortInstances)
            {
                allStructuralPorts.Add(abstractPortInstance.Key, abstractPortInstance.Value);
            }

            foreach (var abstractContainerPort in containerStructuralPortInstances)
            {
                allStructuralPorts.Add(abstractContainerPort.Key, abstractContainerPort.Value);
            }

            #endregion


            #region Join Structures -> PortConnectors

            // Pair construct
            //ConvertJoinStructures(dm, innerPortInstances, connections.OfType<CyPhy.JoinStructures>());


            // Grouping construct
            //ConvertJoinStrucutresInGroups(GetStructuralPortGroups(allPorts, connections.OfType<CyPhy.JoinStructures>()), dm, allPorts);

            // Pair construct

            #endregion

            #region ValueFlow -> ValueConnector

            ConvertValueFlows(dm, connections.OfType <CyPhy.ValueFlow>(), simpleFormulas, allPorts, valueInstances);

            #endregion

            return(dm);
        }