示例#1
0
 public void SwitchAndExecute(OutputKind kind, ExportAs export)   // this may be invoked from work thread, so execute it on main thread
 {
     if (kind == OutputKind.Text)
     {
         Device.BeginInvokeOnMainThread(async() => {
             textOutputButton.IsEnabled = false;
             overlapping.RaiseChild(backdrop);
             overlapping.RaiseChild(editor.AsView());
             graphOutputButton.IsEnabled = true;
             scoreOutputButton.IsEnabled = true;
         });
     }
     else if (kind == OutputKind.Graph)
     {
         Device.BeginInvokeOnMainThread(async() => {
             graphOutputButton.IsEnabled = false;
             overlapping.RaiseChild(backdrop);
             overlapping.RaiseChild(plot);
             textOutputButton.IsEnabled  = true;
             scoreOutputButton.IsEnabled = true;
         });
     }
     else if (kind == OutputKind.Score)
     {
         Device.BeginInvokeOnMainThread(async() => {
             scoreOutputButton.IsEnabled = false;
             overlapping.RaiseChild(backdrop);
             overlapping.RaiseChild(score);
             textOutputButton.IsEnabled  = true;
             graphOutputButton.IsEnabled = true;
         });
     }
     KGui.gui.GuiOutputSetText("");
     Exec.Execute_Exporter(true, export);
 }
示例#2
0
        public static Dictionary <ExportAs, bool> exporterMutex = new Dictionary <ExportAs, bool>(); // only run one of each kind of export at once

        public static void Execute_Exporter(bool forkWorker, ExportAs exportAs)
        {
            if (forkWorker)
            {
                lock (exporterMutex) {
                    if (exporterMutex.ContainsKey(exportAs) && exporterMutex[exportAs] == true)
                    {
                        return;
                    }
                    else
                    {
                        exporterMutex[exportAs] = true;
                    }
                }
                Thread thread = new Thread(() => Execute_Exporter_Worker(exportAs));
                thread.SetApartmentState(ApartmentState.STA); // required to use the clipboard
                thread.Start();
            }
            else
            {
                Execute_Exporter_Worker(exportAs);
            }
        }
示例#3
0
 public System.Action action;  // this may be invoked from work thread
 public OutputAction(OutputPage page, string name, OutputKind kind, ExportAs export)
 {
     this.name   = name;
     this.kind   = kind;
     this.action = async() => { page.SwitchAndExecute(kind, export); };
 }
示例#4
0
        private static void Execute_Exporter_Worker(ExportAs exportAs)
        {
            try {
                var execution = lastExecution; // atomically copy it
                if (execution == null)
                {
                }
                else if (exportAs == ExportAs.None)
                {
                }
                else if (exportAs == ExportAs.ReactionScore)
                {
                }
                else if (exportAs == ExportAs.CRN)
                {
                    string hungarization = "";
                    //####Poliynomize
                    //Hungarize.HungarizeCRN(execution.lastCRN, execution.style);
                    KGui.gui.GuiOutputAppendText(execution.netlist.AllComments() + (execution.lastCRN != null ? execution.lastCRN.FormatNice(execution.style) : "") + hungarization + execution.ElapsedTime());
                }
                else if (exportAs == ExportAs.Evaluation)
                {
                    KGui.gui.GuiOutputAppendText(execution.netlist.AllComments() + Env.FormatTopLevel(execution.environment, execution.style) + execution.ElapsedTime());
                }
                else if (exportAs == ExportAs.ChemicalTrace)
                {
                    KGui.gui.GuiOutputAppendText(execution.netlist.Format(execution.style.RestyleAsTraceFull(false)) + execution.ElapsedTime());
                    //} else if (exportAs == ExportAs.FullTrace) {
                    //    KGui.gui.GuiOutputAppendText(execution.netlist.Format(execution.style.RestyleAsTraceFull(true)) + execution.ElapsedTime());
                }
                else if (exportAs == ExportAs.PDMPreactions)
                {
                    KGui.gui.GuiOutputAppendText(execution.netlist.AllComments() + Export.PDMP(execution.netlist, execution.style, sequential: true).HybridSystem(Export.Presentation.Reactions, execution.style));
                }
                else if (exportAs == ExportAs.PDMPequations)
                {
                    KGui.gui.GuiOutputAppendText(execution.netlist.AllComments() + Export.PDMP(execution.netlist, execution.style, sequential: true).HybridSystem(Export.Presentation.ODEs, execution.style));
                }
                else if (exportAs == ExportAs.PDMPstoichiometry)
                {
                    KGui.gui.GuiOutputAppendText(execution.netlist.AllComments() + Export.PDMP(execution.netlist, execution.style, sequential: true).HybridSystem(Export.Presentation.Stoichiometry, execution.style));

                    //} else if (exportAs == ExportAs.ReactionGraph) {
                    //    if (execution.graphCache.ContainsKey("ReactionGraph")) { }
                    //    else execution.graphCache["ReactionGraph"] = Export.ReactionGraph(execution.netlist.AllSpecies(), execution.netlist.AllReactions(), execution.style);
                    //    KGui.gui.GuiProcessGraph("ReactionGraph");
                    //} else if (exportAs == ExportAs.ComplexGraph) {
                    //    if (execution.graphCache.ContainsKey("ComplexGraph")) { }
                    //    else execution.graphCache["ComplexGraph"] = Export.ComplexGraph(execution.netlist.AllSpecies(), execution.netlist.AllReactions(), execution.style);
                    //    KGui.gui.GuiProcessGraph("ComplexGraph");
                }
                else if (exportAs == ExportAs.ProtocolGraph)
                {
                    if (execution.graphCache.ContainsKey("ProtocolGraph"))
                    {
                    }
                    else
                    {
                        execution.graphCache["ProtocolGraph"] = Export.ProtocolGraph(execution.netlist, execution.style);
                    }
                    KGui.gui.GuiProcessGraph("ProtocolGraph");
                }
                else if (exportAs == ExportAs.PDMPGraph)
                {
                    if (execution.graphCache.ContainsKey("PDMPGraphSequential"))
                    {
                    }
                    else
                    {
                        execution.graphCache["PDMPGraphSequential"] = Export.PDMPGraph(execution.netlist, execution.style, sequential: true);
                    }
                    KGui.gui.GuiProcessGraph("PDMPGraphSequential");

                    // Android/iOS only
                }
                else if (exportAs == ExportAs.SVG)
                {
                    KGui.gui.GuiOutputAppendText(Export.SnapToSVG(KGui.gui.GuiChartSize()));
                }
                else if (exportAs == ExportAs.SBML)
                {
                    KGui.gui.GuiOutputAppendText(Export.SBML());

                    // Windows/Mac only
                }
                else if (exportAs == ExportAs.MSRC_LBS)
                {
                    KGui.gui.GuiOutputAppendText(Export.MSRC_LBS());
                }
                else if (exportAs == ExportAs.MSRC_CRN)
                {
                    KGui.gui.GuiOutputAppendText(Export.MSRC_CRN());
                }
                else if (exportAs == ExportAs.ODE)
                {
                    KGui.gui.GuiOutputAppendText(Export.ODE());
                }
                else if (exportAs == ExportAs.SteadyState)
                {
                    KGui.gui.GuiOutputAppendText(Export.SteadyState());
                }
                else if (exportAs == ExportAs.Protocol)
                {
                    KGui.gui.GuiOutputAppendText(Export.Protocol(execution.netlist, new Style(varchar: defaultVarchar, new SwapMap(), map: new AlphaMap(), numberFormat: "G4", dataFormat: "symbol", exportTarget: ExportTarget.Standard, traceFull: false, chartOutput: false)));

                    //} else if (exportAs == ExportAs.PDMP_GraphViz) {
                    //    KGui.gui.GuiOutputAppendText(Export.PDMP(execution.netlist, execution.style, sequential: true).GraphViz(execution.style));
                    //} else if (exportAs == ExportAs.PDMP_Parallel) {
                    //    KGui.gui.GuiOutputAppendText(Export.PDMP(execution.netlist, execution.style, sequential: false).Format(execution.style));
                    //} else if (exportAs == ExportAs.PDMPGraph_Parallel) {
                    //    if (execution.graphCache.ContainsKey("PDMPGraphParallel")) { }
                    //    else execution.graphCache["PDMPGraphParallel"] = Export.PDMPGraph(execution.netlist, execution.style, sequential: false);
                    //    Gui.gui.ProcessGraph("PDMPGraphParallel");
                    //} else if (exportAs == ExportAs.PDMP_Parallel_GraphViz) {
                    //    KGui.gui.GuiOutputAppendText(Export.PDMP(execution.netlist, execution.style, sequential: false).GraphViz(execution.style));
                }
                else
                {
                };
            } catch (Error ex) { KGui.gui.GuiInputSetErrorSelection(-1, -1, 0, "Error", ex.Message); }
            lock (exporterMutex) { exporterMutex[exportAs] = false; }
        }
示例#5
0
 public System.Action action;  // this may be invoked from work thread
 public ExportAction(string name, ExportAs export, System.Action action)
 {
     this.name   = name;
     this.export = export;
     this.action = action;
 }