示例#1
0
        public CyPhy2CADPCB_Settings RetrieveWorkflowSettings(CyPhy2CADPCB_Settings settings, CyPhy.ComponentAssembly ca)
        {
            var validvisualizers = new List <String> {
                "step", "stp", "stl", "mix"
            };

            if (String.IsNullOrWhiteSpace(settings.visualizerType))
            {
                Logger.WriteWarning("VisualizerType workflow parameter is not set. Defaulting to STEP models.");
                settings.visualizerType = "STEP";
            }
            if (!validvisualizers.Any(s => settings.visualizerType.ToLower().Contains(s)))
            {
                Logger.WriteError("CyPhy2CADPCB Visualizer Format Type not set to valid format. " +
                                  "The visualizer currently only supports STEP & STL files.");
                this.result.Success = false;
                return(null);
            }
            if (settings.runLayout == "false" || String.IsNullOrWhiteSpace(settings.runLayout))
            {
                if (!String.IsNullOrWhiteSpace(settings.layoutFilePath) && settings.useSavedLayout == "true")
                {
                    Logger.WriteError("Conflicting interpreter settings: useSavedLayout is set to True, but " +
                                      "layoutFilePath is also specified.");
                    this.result.Success = false;
                    return(null);
                }
                else if (String.IsNullOrWhiteSpace(settings.layoutFilePath) && settings.useSavedLayout == "true")
                {
                    string caDesignPath = ca.GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE,
                                                              this.mainParameters.ProjectDirectory);
                    string layoutPath = Path.Combine(this.mainParameters.ProjectDirectory,
                                                     ca.Attributes.Path, settings.layoutFile);
                    if (!File.Exists(layoutPath))
                    {
                        Logger.WriteError("Interpreter setting useSavedLayout is set to True, but no {0} " +
                                          "file was found in component assembly directory {1}.",
                                          settings.layoutFile, ca.Attributes.Path);
                        this.result.Success = false;
                        return(null);
                    }
                    settings.layoutFilePath = layoutPath;
                }
            }
            else
            {
                if (!String.IsNullOrWhiteSpace(settings.layoutFilePath) || settings.useSavedLayout == "true")
                {
                    Logger.WriteError("Conflicting interpreter settings: runLayout is set to True, but " +
                                      "either useSavedLayout == True or layoutFilePath is specified.");
                    this.result.Success = false;
                    return(null);
                }
            }
            return(settings);
        }
示例#2
0
        private CyPhy2CADPCB_Settings InitializeSettingsFromWorkflow(CyPhy2CADPCB_Settings settings)
        {
            // Seed with settings from workflow.
            String str_WorkflowParameters = "";

            try
            {
                MgaGateway.PerformInTransaction(delegate
                {
                    var testBench          = CyPhyClasses.TestBench.Cast(this.mainParameters.CurrentFCO);
                    var workflowRef        = testBench.Children.WorkflowRefCollection.FirstOrDefault();
                    var workflow           = workflowRef.Referred.Workflow;
                    var taskCollection     = workflow.Children.TaskCollection;
                    var myTask             = taskCollection.FirstOrDefault(t => t.Attributes.COMName == this.ComponentProgID);
                    str_WorkflowParameters = myTask.Attributes.Parameters;
                },
                                                transactiontype_enum.TRANSACTION_NON_NESTED,
                                                abort: true
                                                );

                Dictionary <string, string> dict_WorkflowParameters = (Dictionary <string, string>)
                                                                      Newtonsoft.Json.JsonConvert.DeserializeObject(str_WorkflowParameters, typeof(Dictionary <string, string>));

                if (dict_WorkflowParameters != null)
                {
                    settings = new CyPhy2CADPCB_Settings();
                    foreach (var property in settings.GetType().GetProperties()
                             .Where(p => p.GetCustomAttributes(typeof(WorkflowConfigItemAttribute), false).Any())
                             .Where(p => dict_WorkflowParameters.ContainsKey(p.Name)))
                    {
                        if (dict_WorkflowParameters[property.Name] == null)
                        {
                            property.SetValue(settings, dict_WorkflowParameters[property.Name], null);
                        }
                        else
                        {
                            property.SetValue(settings, dict_WorkflowParameters[property.Name].ToLower(), null);
                        }
                    }
                }
            }
            catch (NullReferenceException)
            {
                Logger.WriteInfo("Could not find workflow object for CyPhy2CADPCB interpreter.");
            }
            catch (Newtonsoft.Json.JsonReaderException)
            {
                Logger.WriteWarning("Workflow Parameter has invalid Json String: {0}", str_WorkflowParameters);
            }

            return(settings);
        }
示例#3
0
        public IInterpreterConfiguration DoGUIConfiguration(IInterpreterPreConfiguration preconfig, IInterpreterConfiguration previousConfig)
        {
            CyPhy2CADPCB_Settings settings = (previousConfig as CyPhy2CADPCB_Settings);

            if (settings.runLayout == "false" || String.IsNullOrWhiteSpace(settings.runLayout))
            {
                if (String.IsNullOrWhiteSpace(settings.layoutFilePath) && (settings.useSavedLayout == "false" || String.IsNullOrWhiteSpace(settings.useSavedLayout)))
                {
                    // Prompt the user for what layout JSON file they want to use.
                    DialogResult dr;
                    using (OpenFileDialog ofd = new OpenFileDialog())
                    {
                        ofd.CheckFileExists = true;
                        ofd.DefaultExt      = "*.json";
                        ofd.Multiselect     = false;
                        ofd.Filter          = "JSON file (*.json)|*.json";
                        dr = ofd.ShowDialog();
                        if (dr == DialogResult.OK)
                        {
                            settings.layoutFilePath = ofd.FileName;
                        }
                        else
                        {
                            // User cancelled
                            return(null);
                        }
                    }

                    if (String.IsNullOrWhiteSpace(settings.visualizerType))
                    {
                        settings.visualizerType = "STEP";
                    }
                }
            }

            return(settings);
        }
示例#4
0
        public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            if (this.enabled == false)
            {
                return;
            }

            try
            {
                // Need to call this interpreter in the same way as the MasterInterpreter will call it.
                // initialize main parameters
                var parameters = new InterpreterMainParameters()
                {
                    Project        = project,
                    CurrentFCO     = currentobj,
                    SelectedFCOs   = selectedobjs,
                    StartModeParam = param
                };

                this.mainParameters         = parameters;
                parameters.ProjectDirectory = project.GetRootDirectoryPath();

                // set up the output directory
                MgaGateway.PerformInTransaction(delegate
                {
                    string outputDirName = project.Name;
                    if (currentobj != null)
                    {
                        outputDirName = currentobj.Name;
                    }

                    var outputDirAbsPath = Path.GetFullPath(Path.Combine(
                                                                parameters.ProjectDirectory,
                                                                "results",
                                                                outputDirName));

                    parameters.OutputDirectory = outputDirAbsPath;

                    if (Directory.Exists(outputDirAbsPath))
                    {
                        Logger.WriteWarning("Output directory {0} already exists. Unexpected behavior may result.", outputDirAbsPath);
                    }
                    else
                    {
                        Directory.CreateDirectory(outputDirAbsPath);
                    }
                });

                PreConfigArgs preConfigArgs = new PreConfigArgs()
                {
                    ProjectDirectory = parameters.ProjectDirectory,
                    Project          = parameters.Project
                };

                // call the preconfiguration with no parameters and get preconfig
                var preConfig = this.PreConfig(preConfigArgs);

                // get previous GUI config
                var settings_ = META.ComComponent.DeserializeConfiguration(parameters.ProjectDirectory,
                                                                           typeof(CyPhy2CADPCB_Settings),
                                                                           this.ComponentProgID);
                CyPhy2CADPCB_Settings settings = (settings_ != null) ? settings_ as CyPhy2CADPCB_Settings : new CyPhy2CADPCB_Settings();

                // Set configuration based on Workflow Parameters. This will override all [WorkflowConfigItem] members.
                settings = InitializeSettingsFromWorkflow(settings);

                // get interpreter config through GUI
                var config = this.DoGUIConfiguration(preConfig, settings);
                if (config == null)
                {
                    Logger.WriteWarning("Operation canceled by the user.");
                    return;
                }

                // if config is valid save it and update it on the file system
                META.ComComponent.SerializeConfiguration(parameters.ProjectDirectory, config, this.ComponentProgID);

                // assign the new configuration to mainParameters
                parameters.config = config;

                // call the main (ICyPhyComponent) function
                this.Main(parameters);
            }
            catch (Exception ex)
            {
                Logger.WriteError("Interpretation failed {0}<br>{1}", ex.Message, ex.StackTrace);
            }
            finally
            {
                DisposeLogger();
                MgaGateway   = null;
                project      = null;
                currentobj   = null;
                selectedobjs = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }