public CyPhyBuildVisitor(string projectDirectory, CodeGenerator.Mode mode)  // this is a singleton object and the constructor will be called once
 {
     Components = new Dictionary<string, Component>();
     ComponentInstanceGUIDs = new Dictionary<string, Component>();
     Ports = new Dictionary<string, Port>();
     Components.Clear();
     ComponentInstanceGUIDs.Clear();
     Ports.Clear();
     this.ProjectDirectory = projectDirectory;
     this.mode = mode;
 }
Example #2
0
        /// <summary>
        /// This function does the job. CyPhy2Schematic translation.
        /// </summary>
        private void WorkInMainTransaction()
        {
            var    config                = (this.mainParameters.config as CyPhy2Schematic_Settings);
            string placementDotBat       = "placement.bat";
            string placementOnlyExactBat = "placement.bat --only-consider-exact-constraints";
            string placeonlyDotBat       = "placeonly.bat";

            this.result.Success = true;

            GetIDsOfEverything(this.mainParameters.CurrentFCO);

            // Call Elaborator
            var elaboratorSuccess = this.CallElaborator(this.mainParameters.Project,
                                                        this.mainParameters.CurrentFCO,
                                                        this.mainParameters.SelectedFCOs,
                                                        this.mainParameters.StartModeParam);

            this.UpdateSuccess("Elaborator", elaboratorSuccess);

            Schematic.CodeGenerator.Mode mode = Schematic.CodeGenerator.Mode.EDA;

            ISet <IMgaObject> selectedSpiceModels = null;

            if (config.doSpice != null)
            {
                FidelitySelectionRules xpaths = FidelitySelectionRules.DeserializeSpiceFidelitySelection(this.mainParameters.CurrentFCO);
                if (xpaths != null && xpaths.rules.Count > 0)
                {
                    var testBench = TonkaClasses.TestBench.Cast(this.mainParameters.CurrentFCO);
                    var ca        = testBench.Children.ComponentAssemblyCollection.FirstOrDefault();
                    if (ca == null)
                    {
                        Logger.WriteFailed("No valid component assembly in testbench {0}", testBench.Name);
                        return;
                    }
                    selectedSpiceModels = new HashSet <IMgaObject>(new MgaObjectCompararer());
                    Dictionary <XElement, Tonka.SPICEModel> map = new Dictionary <XElement, Tonka.SPICEModel>();
                    foreach (var e in FidelitySelectionRules.SelectElements(FidelitySelectionRules.CreateForAssembly(ca, map), xpaths))
                    {
                        selectedSpiceModels.Add(map[e].Impl);
                    }
                }


                this.result.RunCommand = "runspice.bat";
                mode = Schematic.CodeGenerator.Mode.SPICE;
            }
            else if (config.doSpiceForSI != null)
            {
                this.result.RunCommand = "runspice.bat";
                mode = Schematic.CodeGenerator.Mode.SPICE_SI;
            }
            else
            {
                mode = Schematic.CodeGenerator.Mode.EDA;
                if (config.doChipFit != null)
                {
                    Boolean chipFitViz = false;
                    if (Boolean.TryParse(config.showChipFitVisualizer, out chipFitViz) &&
                        chipFitViz)
                    {
                        this.result.RunCommand = "chipfit.bat chipfit_display";
                    }
                    else
                    {
                        this.result.RunCommand = "chipFit.bat";
                    }
                }
                else if (config.doPlaceRoute != null)
                {
                    this.result.RunCommand = placementDotBat;
                    if (config.onlyConsiderExactConstraints)
                    {
                        this.result.RunCommand = placementOnlyExactBat;
                    }
                }
                else if (config.doPlaceOnly != null)
                {
                    this.result.RunCommand = placeonlyDotBat;
                }
                else
                {
                    this.result.RunCommand = "cmd /c dir";
                }
            }

            bool successTranslation = true;

            try
            {
                var schematicCodeGenerator = new Schematic.CodeGenerator(this.mainParameters, mode, (MgaTraceability)result.Traceability, mgaIdToDomainIDs, selectedSpiceModels);
                schematicCodeGenerator.Logger = Logger;
                this.schematicCodeGenerator   = schematicCodeGenerator;

                var gcResult = schematicCodeGenerator.GenerateCode();

                // MOT-782: Prevent autorouting if we've placed components off the board.
                if ((gcResult.bonesFound) && (this.result.RunCommand == placementDotBat))
                // FIXME placeonlyDotBat should work with only exact constraints   || this.result.RunCommand == placementOnlyExactBat))
                {
                    // Found a bone, MOT-782.
                    Logger.WriteWarning("Skipping EAGLE autorouting, since components not found in layout.json were placed off the board.");

                    this.result.RunCommand = placeonlyDotBat;
                    config.doPlaceOnly     = config.doPlaceRoute;
                    config.doPlaceRoute    = null;
                }

                if (mode == Schematic.CodeGenerator.Mode.EDA &&
                    (config.doPlaceRoute != null || config.doPlaceOnly != null))
                {
                    this.result.RunCommand += gcResult.runCommandArgs;
                }

                successTranslation = true;
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex.Message);
                Logger.WriteDebug(ex.ToString());
                successTranslation = false;
            }
            finally
            {
                CyPhyBuildVisitor.ComponentInstanceGUIDs = null;
                CyPhyBuildVisitor.Components             = null;
                CyPhyBuildVisitor.Ports = null;
                CodeGenerator.partNames = null;
            }
            this.UpdateSuccess("Schematic translation", successTranslation);
        }
        /// <summary>
        /// This function does the job. CyPhy2Schematic translation.
        /// </summary>
        private void WorkInMainTransaction()
        {
            var config = (this.mainParameters.config as CyPhy2Schematic_Settings);

            this.result.Success = true;
            Schematic.CodeGenerator.Mode mode = Schematic.CodeGenerator.Mode.EDA;

            if (config.doSpice != null)
            {
                this.result.RunCommand = "runspice.bat";
                mode = Schematic.CodeGenerator.Mode.SPICE;
            }
            else if (config.doSpiceForSI != null)
            {
                this.result.RunCommand = "runspice.bat";
                mode = Schematic.CodeGenerator.Mode.SPICE_SI;
            }
            else
            {
                mode = Schematic.CodeGenerator.Mode.EDA;
                if (config.doChipFit != null)
                {
                    Boolean chipFitViz = false;
                    if (Boolean.TryParse(config.showChipFitVisualizer, out chipFitViz)
                        && chipFitViz)
                    {
                        this.result.RunCommand = "chipfit.bat chipfit_display";
                    }
                    else
                    {
                        this.result.RunCommand = "chipFit.bat";
                    }
                }
                else if (config.doPlaceRoute != null)
                {
                    this.result.RunCommand = "placement.bat";
                }
                else if (config.doPlaceOnly != null)
                {
                    this.result.RunCommand = "placeonly.bat";
                }
                else
                {
                    this.result.RunCommand = "dir";
                }
            }

            // Call Elaborator
            var elaboratorSuccess = this.CallElaborator(this.mainParameters.Project,
                                                        this.mainParameters.CurrentFCO, 
                                                        this.mainParameters.SelectedFCOs,
                                                        this.mainParameters.StartModeParam);
            this.UpdateSuccess("Elaborator", elaboratorSuccess);

            bool successTranslation = true;
            try
            {
                Schematic.CodeGenerator.Logger = Logger;
                var schematicCodeGenerator = new Schematic.CodeGenerator(this.mainParameters, mode);
                
                var gcResult = schematicCodeGenerator.GenerateCode();
                
                if (mode == Schematic.CodeGenerator.Mode.EDA &&
                    (config.doPlaceRoute != null || config.doPlaceOnly != null))
                {
                    this.result.RunCommand += gcResult.runCommandArgs;
                }
                
                successTranslation = true;
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex.ToString());
                successTranslation = false;
            }
            this.UpdateSuccess("Schematic translation", successTranslation);
        }
        public CyPhyConnectVisitor(CodeGenerator.Mode mode)
        {
            VisitedPorts = new Dictionary<string, Port>();
            VisitedPorts.Clear();

            this.mode = mode;
            switch (mode)
            {
                case CodeGenerator.Mode.EDA:
                    SchematicModelType = typeof(Tonka.EDAModel);
                    break;
                case CodeGenerator.Mode.SPICE:
                case CodeGenerator.Mode.SPICE_SI:
                    SchematicModelType = typeof(Tonka.SPICEModel);
                    break;
                default:
                    throw new NotSupportedException(String.Format("Mode {0} is not supported.", mode.ToString()));
            }
        }