Esempio n. 1
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);
            }
        }
Esempio n. 2
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);
            }
        }