Exemplo n.º 1
0
 private static List<avm.ComponentInstance> RecursivelyGetAllComponentInstances(avm.Design dm_root)
 {
     List<avm.ComponentInstance> lci_rtn = new List<avm.ComponentInstance>();
     foreach (Compound c in dm_root.RootContainer.Container1.Where(c => c is Compound))
     {
         lci_rtn.InsertRange(0, RecursivelyGetAllComponentInstances(c));
     }
     return lci_rtn;
 }
Exemplo n.º 2
0
        public static Complexity.Design Design2Complexity(avm.Design dmInput)
        {
            var dMain = new Complexity.Design();
            dMain.ComponentInstances = new List<Complexity.ComponentInstance>();
            dMain.Connections = new List<Complexity.Connection>();
            dMain.AVMID = dmInput.DesignID;
            dMain.Name = dmInput.Name;

            var componentInstances = RecursivelyGetAllComponentInstances(dmInput);
            var componentMapping = new Dictionary<avm.ComponentInstance, Complexity.ComponentInstance>();
            foreach (var ci in componentInstances)
            {
                var cci_new = new Complexity.ComponentInstance
                              {
                                  AVMID = ci.ComponentID,
                                  Name = ci.Name,
                                  Complexity = 1,
                                  DistributionType = DistributionTypeEnum.None
                              };

                ((List<Complexity.ComponentInstance>)dMain.ComponentInstances).Add(cci_new);

                if (!componentMapping.ContainsKey(ci))
                    componentMapping[ci] = cci_new;
            }

            foreach (var ci in componentInstances)
            {
                if (!componentMapping.ContainsKey(ci)) continue;

                foreach (var pi in ci.PortInstance)
                {
                    foreach (var portMap in pi.PortMap)
                    {
                        var parentComponent = componentInstances.Where(x => x.PortInstance.Any(y => y.ID == portMap)).FirstOrDefault();
                        
                        if (parentComponent == null) continue;
                        if (!componentMapping.ContainsKey(parentComponent)) continue;

                        Complexity.Connection cc_new = new Complexity.Connection();
                        ((List<Complexity.Connection>)dMain.Connections).Add(cc_new);
                        cc_new.src = componentMapping[ci];
                        cc_new.dst = componentMapping[parentComponent];
                        cc_new.Complexity = 0.1;
                        cc_new.DistributionType = Complexity.DistributionTypeEnum.None;
                    }
                }
            }
            
            return dMain;
        }
Exemplo n.º 3
0
        public static CyPhyML.Component AVMComponent2CyPhyML(CyPhyML.Components cyPhyMLComponentParent, avm.Component avmComponent, bool resetUnitLib = true, object messageConsole = null)
        {
            CyPhyML.Component c_rtn = AVM2CyPhyML.CyPhyMLComponentBuilder.AVM2CyPhyML(cyPhyMLComponentParent, avmComponent, resetUnitLib, messageConsole);
//             CyPhyComponentAutoLayout.LayoutComponent(c_rtn);
             return c_rtn;
         }
Exemplo n.º 4
0
        public Model ImportDesign(avm.Design ad_import, DesignImportMode mode = DesignImportMode.CREATE_DS)
        {
            TellCyPhyAddonDontAssignIds();

            // TODO: check ad_import.SchemaVersion
            CyPhy.DesignEntity cyphy_container;

            if (mode == DesignImportMode.CREATE_CA_IF_NO_DS_CONCEPTS)
            {
                bool containsNonCompound = false;
                Queue<avm.Container> containers = new Queue<avm.Container>();
                containers.Enqueue(ad_import.RootContainer);
                while (containers.Count > 0)
                {
                    avm.Container container = containers.Dequeue();
                    containsNonCompound |= container is avm.Optional || container is avm.Alternative;
                    foreach (var subcontainer in container.Container1)
                    {
                        containers.Enqueue(subcontainer);
                    }
                }
                if (containsNonCompound)
                {
                    cyphy_container = CreateDesignSpaceRoot(ad_import);
                }
                else
                {
                    cyphy_container = CreateComponentAssemblyRoot(ad_import);
                }
            }
            else if (mode == DesignImportMode.CREATE_CAS)
            {
                cyphy_container = CreateComponentAssemblyRoot(ad_import);
            }
            else if (mode == DesignImportMode.CREATE_DS)
            {
                cyphy_container = CreateDesignSpaceRoot(ad_import);
            }
            else
            {
                throw new ArgumentOutOfRangeException("Unrecognized mode " + mode.ToString());
            }

            var ad_container = ad_import.RootContainer;

            ImportContainer(cyphy_container, ad_container);

            processValues();
            processPorts();

            Dictionary<avm.ConnectorCompositionTarget, avm.ConnectorCompositionTarget> connectorMap = new Dictionary<avm.ConnectorCompositionTarget, avm.ConnectorCompositionTarget>();
            foreach (var obj in this._avmCyPhyMLObjectMap)
            {
                if (obj.Key is avm.ConnectorCompositionTarget)
                {
                    avm.ConnectorCompositionTarget ad_compositionTarget1 = (avm.ConnectorCompositionTarget)obj.Key;
                    foreach (var ad_compositionTarget2ID in ad_compositionTarget1.ConnectorComposition.Where(id => string.IsNullOrEmpty(id) == false))
                    {
                        var ad_compositionTarget2 = _idConnectorMap[ad_compositionTarget2ID];
                        var cyphy_target = _avmCyPhyMLObjectMap[ad_compositionTarget2]; // TODO: handle lookup failure
                        if (string.Compare(ad_compositionTarget1.ID, ad_compositionTarget2.ID) < 0)
                        {
                            continue;
                        }
                        makeConnection(obj.Value, cyphy_target, typeof(CyPhy.ConnectorComposition).Name);
                    }
                }
            }

            AddReferenceCoordinateSystemForAssemblyRoot(ad_import, cyphy_container);

            DoLayout();

            return (Model)cyphy_container;
        }
Exemplo n.º 5
0
        private void ImportComponentInstance(avm.ComponentInstance ad_componentinstance, CyPhy.ComponentRef cyphy_componentref)
        {
            AVM2CyPhyML.CyPhyMLComponentBuilder.SetLayoutData(ad_componentinstance, cyphy_componentref.Impl);

            ISIS.GME.Dsml.CyPhyML.Interfaces.Component component;
            if (avmidComponentMap.TryGetValue(ad_componentinstance.ComponentID, out component) == false)
            {
                throw new ApplicationException(String.Format("Cannot find Component with ID {0}. Has it been imported?", ad_componentinstance.ComponentID));
            }
            cyphy_componentref.Referred.Component = component;
            cyphy_componentref.Name = ad_componentinstance.Name;
            //cyphy_componentref.Attributes.ID = ad_componentinstance.ID;
            cyphy_componentref.Attributes.InstanceGUID = ad_componentinstance.ID;
            idToComponentInstanceMap[ad_componentinstance.ID] = cyphy_componentref;

            foreach (var ad_propinstance in ad_componentinstance.PrimitivePropertyInstance)
            {
                var cyphy_component = this.avmidComponentMap[ad_componentinstance.ComponentID];
                var cyphy_componentPort = cyphy_component.AllChildren.OfType<CyPhy.ValueFlowTarget>()
                    .Where(x => ((MgaFCO)x.Impl).StrAttrByName["ID"] == ad_propinstance.IDinComponentModel).FirstOrDefault();

                _avmCyPhyMLObjectMap.Add(ad_propinstance, new KeyValuePair<ISIS.GME.Common.Interfaces.Reference, ISIS.GME.Common.Interfaces.FCO>(cyphy_componentref, cyphy_componentPort));
                registerValueNode(ad_propinstance.Value, ad_propinstance);
            }

            foreach (var ad_connectorInstance in ad_componentinstance.ConnectorInstance)
            {
                _idConnectorMap.Add(ad_connectorInstance.ID, ad_connectorInstance); // FIXME could be dup

                var cyphy_component = this.avmidComponentMap[ad_componentinstance.ComponentID];
                var cyphy_componentConnector = cyphy_component.AllChildren.OfType<CyPhy.Connector>()
                    .Where(x => ((MgaFCO)x.Impl).StrAttrByName["ID"] == ad_connectorInstance.IDinComponentModel).FirstOrDefault();
                if (cyphy_componentConnector == null)
                {
                    throw new ApplicationException("adm error: component instance " + ad_componentinstance.ID + " has connector with IDinComponentModel "
                        + ad_connectorInstance.IDinComponentModel + " that has no matching Connector in the Component");
                }

                _avmCyPhyMLObjectMap.Add(ad_connectorInstance, new KeyValuePair<ISIS.GME.Common.Interfaces.Reference, ISIS.GME.Common.Interfaces.FCO>(cyphy_componentref, cyphy_componentConnector));
            }

            foreach (var ad_port in ad_componentinstance.PortInstance)
            {
                registerPort(ad_port);

                var cyphy_component = this.avmidComponentMap[ad_componentinstance.ComponentID];
                var cyphy_componentConnector = cyphy_component.AllChildren.OfType<CyPhy.Port>()
                    .Where(x => ((MgaFCO)x.Impl).StrAttrByName["ID"] == ad_port.IDinComponentModel).FirstOrDefault();
                if (cyphy_componentConnector == null)
                {
                    throw new ApplicationException("adm error: component instance " + ad_componentinstance.ID + " has connector with IDinComponentModel "
                        + ad_port.IDinComponentModel + " that has no matching Connector in the Component");
                }
                _avmCyPhyMLObjectMap.Add(ad_port, new KeyValuePair<ISIS.GME.Common.Interfaces.Reference, ISIS.GME.Common.Interfaces.FCO>(cyphy_componentref, cyphy_componentConnector));
            }
        }
Exemplo n.º 6
0
 private void processMux(CyPhyML.DesignContainer designContainer, avm.ValueFlowMux ad_mux)
 {
     _avmValueNodeIDMap.Add(ad_mux.ID, new KeyValuePair<avm.ValueNode, object>(null, ad_mux));
 }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
 private CyPhy.ComponentAssembly CreateComponentAssemblyRoot(avm.Design ad_import)
 {
     CyPhy.ComponentAssemblies cyphy_cas;
     CyPhy.RootFolder rf = CyPhyClasses.RootFolder.GetRootFolder((MgaProject)project);
     cyphy_cas = rf.Children.ComponentAssembliesCollection.Where(d => d.Name == typeof(CyPhyClasses.ComponentAssemblies).Name).FirstOrDefault();
     if (cyphy_cas == null)
     {
         cyphy_cas = CyPhyClasses.ComponentAssemblies.Create(rf);
         cyphy_cas.Name = typeof(CyPhyClasses.ComponentAssemblies).Name;
     }
     CyPhy.ComponentAssembly cyphy_container = CyPhyClasses.ComponentAssembly.Create(cyphy_cas);
     // container.Name = ad_import.Name; RootContainer has a name too
     // TODO: check ad_import.SchemaVersion
     int designID;
     if (int.TryParse(ad_import.DesignID, out designID))
     {
         cyphy_container.Attributes.ID = designID;
     }
     return cyphy_container;
 }
Exemplo n.º 9
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);
                    }
                }
            }
        }
        //private bool CallElaborator(
        //    MgaProject project,
        //    MgaFCO currentobj,
        //    MgaFCOs selectedobjs,
        //    int param,
        //    bool expand = true)
        //{
        //    bool result = false;
        //    try
        //    {
        //        GMEConsole.Info.WriteLine("Elaborating model...");
        //        var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter();
        //        elaborator.Initialize(project);
        //        int verbosity = 128;
        //        result = elaborator.RunInTransaction(project, currentobj, selectedobjs, verbosity);

        //        GMEConsole.Info.WriteLine("Elaboration is done.");
        //    }
        //    catch (Exception ex)
        //    {
        //        GMEConsole.Error.WriteLine("Exception occurred in Elaborator : {0}", ex.ToString());
        //        result = false;
        //    }

        //    return result;
        //}

        public bool CheckForDuplicateIDs(avm.TestBench d)
        {
            //String str = d.Serialize();
            String str = XSD2CSharp.AvmXmlSerializer.Serialize(d);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(str);
            XmlNode root = doc.DocumentElement;

            var ls_EncounteredIDs = new List<String>();
            foreach (XmlAttribute node in root.SelectNodes("//@ID"))
            {
                ls_EncounteredIDs.Add(node.Value);
            }

            // Get all duplicate IDs that aren't empty/whitespace
            var duplicates = ls_EncounteredIDs.Where(s => !String.IsNullOrWhiteSpace(s))
                                              .GroupBy(s => s)
                                              .Where(g => g.Count() > 1)
                                              .Select(g => g.Key)
                                              .ToList();
            if (duplicates.Any())
            {
                String msg = "Duplicate IDs found in exported design: ";
                foreach (var dupe in duplicates)
                    msg += String.Format("{0}\"{1}\", ", Environment.NewLine, dupe);

                if (GMEConsole != null)
                    GMEConsole.Error.WriteLine(msg);
                return true;
            }

            return false;
        }
        public static void SerializeAvmComponent(avm.Component avmComponent, String s_outFilePath)
        {
            avmComponent.SchemaVersion = "2.5";

            FileStream stream = new FileStream(s_outFilePath, FileMode.Create);
            using (stream)
            {
                XSD2CSharp.AvmXmlSerializer.Serialize(avmComponent, stream);
                stream.Close();
            }
        }
        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()];
            }

            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 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);

                cyphy_constraint.Attributes.X = constraint.X.ToString();
                cyphy_constraint.Attributes.Y = constraint.Y.ToString();
                cyphy_constraint.Attributes.Layer = d_LayerEnumMap[constraint.Layer];
                if (constraint.RotationSpecified)
                {
                    cyphy_constraint.Attributes.Rotation = d_RotationEnumMap[constraint.Rotation];
                }
                if (string.IsNullOrWhiteSpace(constraint.ConstraintTarget) == false)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (avmId2ComponentInstance.TryGetValue(constraint.ConstraintTarget, out compInstance))
                    {
                        CyPhyClasses.ApplyExactLayoutConstraint.Connect(cyphy_constraint, compInstance);
                    }
                }
            }
            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;
                }
                foreach (var compId in constraint.ConstraintTarget)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (avmId2ComponentInstance.TryGetValue(compId, out compInstance))
                    {
                        CyPhyClasses.ApplyRangeLayoutConstraint.Connect(cyphy_constraint, compInstance);
                    }
                }
            }
            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();
                }
                foreach (var compId in constraint.ConstraintTarget)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (avmId2ComponentInstance.TryGetValue(compId, out compInstance))
                    {
                        CyPhyClasses.ApplyRelativeLayoutConstraint.Connect(cyphy_constraint, compInstance);
                    }
                }
                if (string.IsNullOrWhiteSpace(constraint.Origin) == false)
                {
                    CyPhyML.ComponentRef compInstance;
                    if (avmId2ComponentInstance.TryGetValue(constraint.Origin, out compInstance))
                    {
                        CyPhyClasses.RelativeLayoutConstraintOrigin.Connect(compInstance, cyphy_constraint);
                    }
                }
            }

            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);
            }

        }
Exemplo n.º 13
0
        /* Copy end */

        /* Copying/Adapting from CyPhy2ComponentModel C# Proj*/
        public static void SerializeAvmComponent(avm.Component avmComponent, String s_outFilePath)
        {
            StreamWriter streamWriter = new StreamWriter(s_outFilePath);
            using (streamWriter)
            {
                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Component), getAVMClasses());

                serializer.Serialize(streamWriter, avmComponent);
                streamWriter.Close();
            }
        }
        private static CyPhy.Components DetermineAndEnsureFolderForComponent(CyPhy.RootFolder rootFolder, avm.Component ac_import)
        {
            // Get or create a root Components folder. Components will go in here, unless they have a classification.
            CyPhy.Components cyPhyMLComponentsFolder = rootFolder.Children.ComponentsCollection
                                                                 .FirstOrDefault(cf => cf.Name.Equals(ImportedComponentsFolderName));
            if (cyPhyMLComponentsFolder == null)
            {
                cyPhyMLComponentsFolder = CyPhyClasses.Components.Create(rootFolder);
                cyPhyMLComponentsFolder.Name = ImportedComponentsFolderName;
            }

            // Check for classifications. If the component has 1 or more classifications, then
            // the first one will be used to find/build a corresponding folder structure for this component.
            if (ac_import.Classifications.Count > 0 && 
                !String.IsNullOrWhiteSpace(ac_import.Classifications.FirstOrDefault()))
            {
                var firstClass = ac_import.Classifications.FirstOrDefault();

                // Create an iterator and initialize it on the root Components folder.
                CyPhy.Components folIter = cyPhyMLComponentsFolder;
                foreach (var folName in firstClass.Split('.'))
                {
                    // Find a child folder with this name
                    var tmp = folIter.Children.ComponentsCollection
                                              .FirstOrDefault(cf => cf.Name.Equals(folName));

                    // If no folder by that name, create one.
                    if (tmp == null)
                    {
                        tmp = CyPhyClasses.Components.Create(folIter);
                        tmp.Name = folName;
                    }

                    // Set this folder as the current, and move to the next category.
                    folIter = tmp;
                }

                cyPhyMLComponentsFolder = folIter;
            }
            return cyPhyMLComponentsFolder;
        }
Exemplo n.º 15
0
        private CyPhy.DesignContainer CreateDesignSpaceRoot(avm.Design ad_import)
        {
            CyPhy.DesignSpace ds;
            CyPhy.RootFolder rf = CyPhyClasses.RootFolder.GetRootFolder((MgaProject)project);
            ds = rf.Children.DesignSpaceCollection.Where(d => d.Name == "DesignSpaces").FirstOrDefault();
            if (ds == null)
            {
                ds = CyPhyClasses.DesignSpace.Create(rf);
                ds.Name = "DesignSpaces";
            }

            CyPhy.DesignContainer cyphy_container = CyPhyClasses.DesignContainer.Create(ds);
            // container.Name = ad_import.Name; RootContainer has a name too
            int designID;
            if (int.TryParse(ad_import.DesignID, out designID))
            {
                cyphy_container.Attributes.ID = designID;
            }
            cyphy_container.Attributes.ContainerType = CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Compound;
            return cyphy_container;
        }
 private void CheckAndWarnOnSchemaVersion(avm.Component ac_import)
 {
     if (!String.IsNullOrWhiteSpace(ac_import.SchemaVersion))
     {
         double version;
         if (double.TryParse(ac_import.SchemaVersion, out version))
         {
             if (version == ExpectedSchemaVersion)
             {
                 // Okay.
             }
             else
             {
                 Logger.WriteWarning("{0} has SchemaVersion of {1}. This version of CyPhy expects version {2}. Component may not import correctly.", ac_import.Name, version, ExpectedSchemaVersion);
             }
         }
         else
         {
             Logger.WriteWarning("{0} has an unknown SchemaVersion of {1}. This version of CyPhy expects version {2}. Component may not import correctly.", ac_import.Name, ac_import.SchemaVersion, ExpectedSchemaVersion);
         }
     }
     else
     {
         Logger.WriteWarning("{0} has an unknown SchemaVersion. This version of CyPhy expects version {1}. Component may not import correctly.", ac_import.Name, ExpectedSchemaVersion);
     }
 }
Exemplo n.º 17
0
        public static CyPhy.TestBenchType Convert(avm.TestBench avmTestBench, IMgaProject project)
        {
            if (avmTestBench == null)
                throw new ArgumentNullException("avmTestBench");

            var rootFolder = CyPhyClasses.RootFolder.GetRootFolder((MgaProject)project);
            var testBenchFolder = rootFolder.Children.TestingCollection.Where(d => d.Name == "TestBenches").FirstOrDefault();

            #region Create TestBenchesFolder
            
            if (testBenchFolder == null)
            {
                testBenchFolder = CyPhyClasses.Testing.Create(rootFolder);
                testBenchFolder.Name = "TestBenches";
            }

            #endregion

            #region Create TestBench

            var cyphyTestBench = CyPhyClasses.TestBench.Create(testBenchFolder);
            cyphyTestBench.Name = avmTestBench.Name;


            #endregion

            #region Create TopLevelSystemUnderTest

            var avmSystemUnderTest = avmTestBench.TopLevelSystemUnderTest;
            CyPhy.TopLevelSystemUnderTest cyphySystemUnderTest = null;
            TestBenchPrimitiveWrapper cyphySystemUnderTestReferred = null;
            if (avmSystemUnderTest != null)
            {
                cyphySystemUnderTest = CyPhyClasses.TopLevelSystemUnderTest.Create(cyphyTestBench);
                SetLayoutData(avmSystemUnderTest, cyphySystemUnderTest.Impl);
                if (!string.IsNullOrEmpty(avmSystemUnderTest.DesignID))
                {
                    // Looking for the referred component assembly
                    var allComponentAssembly = GetAllComponentAssemblies(rootFolder.Children.ComponentAssembliesCollection);
                    var componentAssembly = allComponentAssembly.FirstOrDefault(x=>x.Attributes.ConfigurationUniqueID == avmSystemUnderTest.DesignID);
                    if (componentAssembly != null)
                    {
                        cyphySystemUnderTest.GenericReferred = componentAssembly;
                        cyphySystemUnderTest.Name = componentAssembly.Name;
                        cyphySystemUnderTestReferred = new TestBenchPrimitiveWrapper(componentAssembly);
                    }
                }
            }

            #endregion

            #region Create Parameters

            var parameterCache = new List<Tuple<avm.Parameter, CyPhy.Parameter>>();
            foreach (var avmParameter in avmTestBench.Parameter)
            {
                var cyphyTestBenchParameter = CyPhyClasses.Parameter.Create(cyphyTestBench);
                cyphyTestBenchParameter.Name = avmParameter.Name;
                cyphyTestBenchParameter.Attributes.Description = avmParameter.Notes;
                cyphyTestBenchParameter.Attributes.ID = avmParameter.ID;
                SetLayoutData(avmParameter, cyphyTestBenchParameter.Impl);

                parameterCache.Add(new Tuple<avm.Parameter, CyPhy.Parameter>(avmParameter, cyphyTestBenchParameter));

                #region Set attribute values

                var avmValue = avmParameter.Value;
                if (avmValue != null)
                {
                    CyPhyClasses.Parameter.AttributesClass.DataType_enum cyphyDataType;

                    // TODO: else give a warning
                    if (ConvertCyPhyDataTypeEnum(avmValue.DataType, out cyphyDataType))
                    {
                        cyphyTestBenchParameter.Attributes.DataType = cyphyDataType;
                    }

                    cyphyTestBenchParameter.Attributes.Dimension = avmValue.Dimensions;

                    var avmValueExpression = avmValue.ValueExpression;
                    if (avmValueExpression != null && avmValueExpression is avm.ParametricValue)
                    {
                        var avmParametricValue = (avm.ParametricValue)avmValueExpression;
                        
                        var avmAssignedValue = avmParametricValue.AssignedValue as FixedValue;
                        var avmDefault = avmParametricValue.Default as FixedValue;
                        var avmMaximum = avmParametricValue.Maximum as FixedValue;
                        var avmMinimum = avmParametricValue.Minimum as FixedValue;

                        if (avmAssignedValue!=null && avmAssignedValue.Value!=null)
                            cyphyTestBenchParameter.Attributes.Value = avmAssignedValue.Value;
                        if (avmDefault!=null && avmDefault.Value!=null)
                            cyphyTestBenchParameter.Attributes.DefaultValue = avmDefault.Value;
                        
                        if (avmMinimum!=null && !string.IsNullOrEmpty(avmMinimum.Value) && avmMaximum!=null && !string.IsNullOrEmpty(avmMaximum.Value))
                            cyphyTestBenchParameter.Attributes.Range = String.Format("{0}..{1}",avmMinimum.Value,avmMaximum.Value);
                    }
                }

                #endregion
            }

            #endregion

            #region Create Metrics

            var metricCache = new List<Tuple<avm.Metric, CyPhy.Metric>>();
            foreach (var avmMetric in avmTestBench.Metric)
            {
                var cyphyTestBenchMetric = CyPhyClasses.Metric.Create(cyphyTestBench);

                cyphyTestBenchMetric.Name = avmMetric.Name;
                cyphyTestBenchMetric.Attributes.Description = avmMetric.Notes;
                SetLayoutData(avmMetric, cyphyTestBenchMetric.Impl);

                metricCache.Add(new Tuple<avm.Metric, CyPhy.Metric>(avmMetric, cyphyTestBenchMetric));
            }

            #endregion

            #region Create valueflows

            // Start with TopLevelSystemUnderTest
            if (avmSystemUnderTest != null && cyphySystemUnderTest != null)
            {
                /*
                // Parameters and properties
                foreach (var avmParameter in avmSystemUnderTest.PropertyInstance.Where(x=>x.Value!=null))
                {
                    // Target of valueflow
                    if (avmParameter.Value.ValueExpression is DerivedValue)
                    {
                        var derivedValue = (DerivedValue)avmParameter.Value.ValueExpression;
                        // Look for the parameter instance
                        dynamic cyphyValueflowSrc = cyphySystemUnderTestReferred.ParameterCollection.FirstOrDefault(x => x.Attributes.ID == avmParameter.IDinSourceModel);

                        // Maybe it is a property
                        if (cyphyValueflowSrc == null)
                        {
                            cyphyValueflowSrc = cyphySystemUnderTestReferred.PropertyCollection.FirstOrDefault(x => x.Attributes.ID == avmParameter.IDinSourceModel);
                        }

                        // TODO: Else warning
                        if (cyphyValueflowSrc != null)
                        {
                            var cachePair = parameterCache.FirstOrDefault(x=>x.Item1.Value.ID == derivedValue.ValueSource);
                            if (cachePair != null)
                            {
                                var cyphyValueflowDst = cachePair.Item2;
                                var srcRef = ((CyPhy.ValueFlowTarget)cyphyValueflowSrc).ParentContainer is CyPhyClasses.TestBench ? null : cyphySystemUnderTest;
                                var dstRef = ((CyPhy.ValueFlowTarget)cyphyValueflowDst).ParentContainer is CyPhyClasses.TestBench ? null : cyphySystemUnderTest;
                                // Doesnt work
                                CyPhyClasses.ValueFlow.Connect((CyPhy.ValueFlowTarget)cyphyValueflowSrc, (CyPhy.ValueFlowTarget)cyphyValueflowDst, srcRef, dstRef, cyphyTestBench);
                                //CyPhyClasses.ValueFlow.ConnectGeneric((CyPhy.ValueFlowTarget)cyphyValueflowDst, (CyPhy.ValueFlowTarget)cyphyValueflowSrc, null, null, cyphyTestBench);
                            }
                        }
                    }
                }
                 */ 
            }

            #endregion

            return cyphyTestBench;
        }