Exemple #1
0
        public override void visit(ComponentAssembly obj)
        {
            CodeGenerator.Logger.WriteDebug(
                "SpiceVisitor::visit({0})",
                obj.Name);

            // create a signal container for this assembly
            var siginfo_obj = new Spice.SignalContainer()
            {
                name  = obj.Name,
                gmeid = obj.Impl.ID
            };

            ObjectSiginfoMap.Add(obj, siginfo_obj);
            var siginfo_parent = this.siginfo_obj;

            if (obj.Parent != null && ObjectSiginfoMap.ContainsKey(obj.Parent))
            {
                siginfo_parent = ObjectSiginfoMap[obj.Parent] as Spice.SignalContainer;
            }
            siginfo_parent.signals.Add(siginfo_obj);

            var spiceObjs = obj.Impl.Children.SPICEModelCollection;
            var spiceObj  = CyPhyBuildVisitor.GetSpiceModel(obj, spiceObjs);

            if (spiceObj == null) // no spice model in this component, skip from generating
            {
                return;
            }
            GenerateSpice(obj, spiceObj);
        }
Exemple #2
0
 public override void visit(ComponentAssembly obj)
 {
     if (obj.Parent != null)
     {
         obj.CanvasX += obj.Parent.CanvasX;
         obj.CanvasY += obj.Parent.CanvasY;
     }
 }
Exemple #3
0
        private List <Component> CollectGroundNodes(ComponentAssembly obj)
        {
            var gnds = obj.ComponentInstances.Where(t =>
                                                    Grounds.Any(GetSpiceType(t).Item2.Contains)
                                                    ).ToList();
            var cgnds = obj.ComponentAssemblyInstances.SelectMany(ca => CollectGroundNodes(ca)).ToList();

            return(gnds.Union(cgnds).ToList());
        }
Exemple #4
0
        public override void visit(ComponentAssembly obj)
        {
            var layoutFile = (obj.Impl.Impl as GME.MGA.MgaFCO).RegistryValue["layoutFile"];
            int ancestorsWithLayoutJson = Layout.LayoutGenerator.getAncestorModels((GME.MGA.MgaFCO)obj.Impl.Impl).Where(parent => parent.RegistryValue["layoutFile"] != null).Count();

            // we only care about the top-most layout.json
            if (layoutFile != null && ancestorsWithLayoutJson == 0)
            {
                var pathLayoutFile = Path.Combine(obj.Impl.GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE), layoutFile);
                var managedGUID    = CyPhy2Schematic.Layout.LayoutGenerator.GetComponentAssemblyManagedGuid(obj.Impl.Impl as GME.MGA.MgaModel);
                var layoutParser   = new Layout.LayoutParser(pathLayoutFile, CodeGenerator.Logger, CodeGenerator)
                {
                    parentInstanceGUID = string.IsNullOrEmpty(managedGUID) == false ? managedGUID: CyPhy2Schematic.Layout.LayoutGenerator.GetComponentAssemblyChainGuid(obj.Impl.Impl as GME.MGA.MgaModel),
                    parentGUID         = CyPhy2Schematic.Layout.LayoutGenerator.GetComponentAssemblyID(obj.Impl.Impl as GME.MGA.MgaModel)
                };
                Logger.WriteDebug("Design \"{0}\" is using layoutFile \"{1}\". Parent GUID : {2}", obj.Name, layoutFile, layoutParser.parentInstanceGUID ?? "[null]");
                layoutParser.BuildMaps();
                CodeGenerator.preRouted.Add(obj, layoutParser);
            }
        }
Exemple #5
0
        public override void visit(TestBench obj)
        {
            Logger.WriteDebug("CyPhyBuildVisitor::visit({0})", obj.Impl.Path);

            var testBench = obj.Impl;
            var ca        = testBench.Children.ComponentAssemblyCollection.FirstOrDefault();

            if (ca == null)
            {
                Logger.WriteFailed("No valid component assembly in testbench {0}", obj.Name);
                return;
            }
            var componentAssembly_obj = new ComponentAssembly(ca);

            obj.ComponentAssemblies.Add(componentAssembly_obj);
            this.systemUnderTest = componentAssembly_obj.SystemUnderTest = componentAssembly_obj;
            componentAssembly_obj.selectedSpiceModels = selectedSpiceModels;

            var tcs = testBench.Children.TestComponentCollection;

            foreach (var tc in tcs)
            {
                var component_obj = new Component(tc);
                component_obj.SystemUnderTest = this.systemUnderTest;
                obj.TestComponents.Add(component_obj);
                CyPhyBuildVisitor.Components.Add(tc.ID, component_obj);   // Add to global component list, are these instance ID-s or component type ID-s?
            }

            foreach (var param in testBench.Children.ParameterCollection)
            {
                var param_obj = new Parameter()
                {
                    Name  = param.Name,
                    Value = param.Attributes.Value
                };
                obj.Parameters.Add(param_obj);
            }

            // solver parameters - currently using Dymola Solver object
            var solver = testBench.Children.SolverSettingsCollection.FirstOrDefault();

            if (solver != null)
            {
                obj.SolverParameters.Add("SpiceAnalysis", solver.Attributes.ToolSpecificAnnotations);
            }

            Dictionary <string, string> properties = testBench.Children.PropertyCollection.ToDictionary(param => param.Name, param => param.Attributes.Value);
            string spiceAnalysisType;

            if (properties.TryGetValue("Spice Analysis Type", out spiceAnalysisType))
            {
                if (spiceAnalysisType == "Transient Analysis")
                {
                    string stepSize = "0.0001";
                    properties.TryGetValue("Spice Step Size", out stepSize);
                    string endTime = "1";
                    properties.TryGetValue("Spice End Time", out endTime);
                    string startTime = "0";
                    properties.TryGetValue("Spice Start Time", out startTime);
                    obj.SolverParameters["SpiceAnalysis"] = String.Format(".TRAN {0} {1} {2}", stepSize, endTime, startTime);
                }
                else
                {
                    throw new ApplicationException(string.Format("Unsupported Spice Analysis Type '{0}'", spiceAnalysisType));
                }
            }
        }
Exemple #6
0
        // This class computes the layout of the flat schematic diagram starting from GME hierarchical diagrams
        public override void upVisit(ComponentAssembly obj)
        {
            SortedList <Tuple <float, float>, object> nodes = new SortedList <Tuple <float, float>, object>();

            // we have already visited all child nodes, and know their extents (canvasWidth and canvasHeight)
            // now sort all child objects by their GME object location, and use the GME location as their initial position
            foreach (var ca in obj.ComponentAssemblyInstances)
            {
                var   allAspect = ca.Impl.Aspects.Where(a => a.Name.Equals("All")).FirstOrDefault();
                float x         = (allAspect != null) ? ((float)allAspect.X) / gme2Eagle : defSize;
                float y         = (allAspect != null) ? ((float)allAspect.Y) / gme2Eagle : defSize;
                ca.CanvasX = (float)Math.Round(x / gridSize) * gridSize;
                ca.CanvasY = (float)Math.Round(y / gridSize) * gridSize;
                Tuple <float, float> location = new Tuple <float, float>(ca.CanvasX, ca.CanvasY);
                if (nodes.ContainsKey(location))
                {
                    Logger.WriteWarning("Component Assembly {1}.{0} overlaps with another in model",
                                        ca.Name, ca.Parent.Name);
                    var xOry = (new Random()).Next(0, 1);
                    location = new Tuple <float, float>(ca.CanvasX + xOry * (gridSize / 2),
                                                        ca.CanvasY + (gridSize / 2) * (1 - xOry));
                }
                nodes.Add(location, ca);
            }
            foreach (var ca in obj.ComponentInstances)
            {
                var   allAspect = ca.Impl.Aspects.Where(a => a.Name.Equals("All")).FirstOrDefault();
                float x         = allAspect != null ? ((float)allAspect.X) / gme2Eagle : defSize;
                float y         = allAspect != null ? ((float)allAspect.Y) / gme2Eagle : defSize;
                ca.CanvasX = (float)Math.Round(x / gridSize) * gridSize;
                ca.CanvasY = (float)Math.Round(y / gridSize) * gridSize;
                Tuple <float, float> location = new Tuple <float, float>(ca.CanvasX, ca.CanvasY);
                if (nodes.ContainsKey(location))
                {
                    Logger.WriteWarning("Component {1}.{0} overlaps with another in model",
                                        ca.Name, ca.Parent.Name);
                    var xOry = (new Random()).Next(0, 1);
                    location = new Tuple <float, float>(ca.CanvasX + xOry * (gridSize / 2),
                                                        ca.CanvasY + (gridSize / 2) * (1 - xOry));
                }

                nodes.Add(location, ca);
            }

            object[] nodeArr   = nodes.Values.ToArray();
            float    maxWidth  = 0;
            float    maxHeight = 0;

            for (int i = 0; i < nodes.Count; i++)
            {
                var node = nodeArr[i];
                var nx   = node is Component ? (node as Component).CanvasX : (node as ComponentAssembly).CanvasX;
                var ny   = node is Component ? (node as Component).CanvasY : (node as ComponentAssembly).CanvasY;

                for (int j = 0; j < i; j++)
                {
                    var   nodePre = nodeArr[j];
                    float npxw, npyh;
                    if (nodePre is Component)
                    {
                        var c = nodePre as Component;
                        npxw = c.CanvasX + c.CanvasWidth;
                        npyh = c.CanvasY + c.CanvasHeight;
                    }
                    else
                    {
                        var c = nodePre as ComponentAssembly;
                        npxw = c.CanvasX + c.CanvasWidth;
                        npyh = c.CanvasY + c.CanvasHeight;
                    }
                    if ((nx - symSpace) <= npxw && (ny - symSpace) <= npyh)        // overlap
                    {
                        if (j % 2 == 0)
                        {
                            nx = npxw + symSpace;
                        }
                        else
                        {
                            ny = npyh + symSpace;
                        }
                    }
                }
                float nxw, nyh;
                if (node is Component)
                {
                    var c = node as Component;
                    c.CanvasX = nx;
                    c.CanvasY = ny;
                    nxw       = nx + c.CanvasWidth;
                    nyh       = ny + c.CanvasHeight;
                    Logger.WriteDebug("Placing Node {0} in Assembly {1}: @ {2},{3}",
                                      c.Name, obj.Name, nx, ny);
                }
                else
                {
                    var c = node as ComponentAssembly;
                    c.CanvasX = nx;
                    c.CanvasY = ny;
                    nxw       = nx + c.CanvasWidth;
                    nyh       = ny + c.CanvasHeight;
                }
                maxWidth  = Math.Max(maxWidth, nxw);
                maxHeight = Math.Max(maxHeight, nyh);
            }
            // set the size of this container
            obj.CanvasWidth  = (float)Math.Round(maxWidth / (2.0f * gridSize)) * 2.0f * gridSize;
            obj.CanvasHeight = (float)Math.Round(maxHeight / (2.0f * gridSize)) * 2.0f * gridSize;
        }
Exemple #7
0
        public override void visit(ComponentAssembly obj)
        {
            Logger.WriteDebug("CyPhyBuildVisitor::visit({0})", obj.Impl.Path);

            var ca = obj.Impl;

            if (mode == CodeGenerator.Mode.SPICE || mode == CodeGenerator.Mode.SPICE_SI)
            {
                var spiceModels             = obj.Impl.Children.SPICEModelCollection;
                Tonka.SPICEModel spiceModel = GetSpiceModel(obj, spiceModels);

                if (spiceModel != null)
                {
                    GetSpiceModel(spiceModel, obj, isTestComponent: false);
                    foreach (var port in spiceModel.Children.SchematicModelPortCollection)
                    {
                        var port_obj = new Port(port)
                        {
                            Parent = obj,
                        };
                        obj.Ports.Add(port_obj);
                        CyPhyBuildVisitor.Ports.Add(port.ID, port_obj);
                        Logger.WriteInfo("Mapping Port <a href=\"mga:{0}\">{1}</a> with ID {2}", Traceability.GetID(port.Impl), port.Name, port.ID);
                    }
                }
            }


            // ------- ComponentAssemblies -------
            foreach (var innerComponentAssembly in ca.Children.ComponentAssemblyCollection)
            {
                var innerComponentAssembly_obj = new ComponentAssembly(innerComponentAssembly)
                {
                    Parent          = obj,
                    SystemUnderTest = this.systemUnderTest
                };
                obj.ComponentAssemblyInstances.Add(innerComponentAssembly_obj);
            }

            // ------- Components -------
            foreach (var component in ca.Children.ComponentCollection)
            {
                var component_obj = new Component(component)
                {
                    Parent          = obj,
                    SystemUnderTest = this.systemUnderTest
                };
                obj.ComponentInstances.Add(component_obj);
                CyPhyBuildVisitor.Components.Add(component.ID, component_obj);   // Add to global component list, component type ID-s?
                var componentInstanceGUID = Layout.LayoutGenerator.GetComponentID(component);
                //GME.CSharp.GMEConsole console = GME.CSharp.GMEConsole.CreateFromProject(component.Impl.Project);
                //console.Info.WriteLine(componentInstanceGUID);
                try
                {
                    CyPhyBuildVisitor.ComponentInstanceGUIDs.Add(componentInstanceGUID, component_obj);   // component instance guid-s?
                }
                catch (ArgumentException e)
                {
                    throw new ArgumentException(e.Message + " " + componentInstanceGUID);
                }
            }
        }
Exemple #8
0
 public virtual void upVisit(ComponentAssembly obj)
 {
 }