Common functionality for 2D and 3D Table types.
        // use static factory methods!
        private GnuPlot(Table table)
        {
            try {
                using (FileStream fs = new FileStream (BinaryFile, FileMode.Create, FileAccess.Write))
                using (BinaryWriter bw = new BinaryWriter (fs)) {
                    Table3D t3D = table as Table3D;
                    if (t3D != null)
                        WriteGnuPlotBinary (bw, t3D);
                    else
                        WriteGnuPlotBinary (bw, (Table2D)table);
                }
            } catch (Exception ex) {
                throw new GnuPlotException ("Could not create temporary binary data file for GnuPlot:\n" + BinaryFile + "\n\n" + ex.Message);
            }

            try {
                StartProcess (table);
            } catch (System.ComponentModel.Win32Exception ex) {
                // from MSDN
                // These are the Win32 error code for file not found or access denied.
                const int ERROR_FILE_NOT_FOUND = 2;
                const int ERROR_ACCESS_DENIED = 5;

                switch (ex.NativeErrorCode) {
                case ERROR_FILE_NOT_FOUND:
                    throw new GnuPlotProcessException ("Could not find gnuplot executable path:\n" + exePath + "\n\n" + ex.Message);
                case ERROR_ACCESS_DENIED:
                    throw new GnuPlotProcessException ("Access denied, no permission to start gnuplot process!\n" + ex.Message);
                default:
                    throw new GnuPlotProcessException ("Unknown error. Could not start gnuplot process.\n" + ex.Message);
                }
            }
        }
        public override void SetNodeContentTypeChanged(TreeIter iter, Tables.Denso.Table table)
        {
            var t = (Table3D)table;

            store.SetValue(iter, (int)ColumnNr3D.Type, (int)t.TableType);
            store.SetValue(iter, (int)ColumnNr3D.Zmin, t.Zmin);
            store.SetValue(iter, (int)ColumnNr3D.Zavg, t.Zavg);
            store.SetValue(iter, (int)ColumnNr3D.Zmax, t.Zmax);
            if (iconsVisible)
            {
                CreateSetNewIcon(iter, t);
            }
        }
Exemple #3
0
    void OnExportTableAsCSVActionActivated(object sender, System.EventArgs e)
    {
        if (data.RomLoaded == false)
        {
            return;
        }

        Tables.Denso.Table table = CurrentTable;
        if (table == null)
        {
            return;
        }

        if (table is Tables.Denso.Table3D)
        {
            ErrorMsg("Error", "Creating CSV for 3D table not implemented yet.");
            return;
        }

        string filenameSuggested = string.IsNullOrEmpty(table.Title) ? "table" : table.Title;

        filenameSuggested += ".csv";
        // TODO another var to remember export dir
        if (svgDirectory == null && data.Rom.Path != null)
        {
            svgDirectory = System.IO.Path.GetDirectoryName(data.Rom.Path);
        }

        var fc = new Gtk.FileChooserDialog("Export data as CSV file", this, FileChooserAction.Save, Gtk.Stock.Cancel, ResponseType.Cancel, Gtk.Stock.Save, ResponseType.Accept);

        try {
            FileFilter filter = new FileFilter();
            filter.Name = "CSV files";
            filter.AddPattern("*.csv");
            fc.AddFilter(filter);

            filter      = new FileFilter();
            filter.Name = "All files";
            filter.AddPattern("*");
            fc.AddFilter(filter);

            fc.DoOverwriteConfirmation = true;
            fc.SetCurrentFolder(svgDirectory);
            fc.CurrentName = filenameSuggested;
            if (fc.Run() == (int)ResponseType.Accept)
            {
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fc.Filename, false, System.Text.Encoding.UTF8)) {
                    ((Tables.Denso.Table2D)table).WriteCSV(sw);
                }
            }
            // remember used dir
            svgDirectory = System.IO.Path.GetDirectoryName(fc.Filename);
        } catch (GnuPlotException ex) {
            ErrorMsg("Error creating CSV file", ex.Message);
        } catch (System.IO.IOException ex) {
            ErrorMsg("IO Exception", ex.Message);
        } catch (Exception ex) {
            // Access to path denied...
            ErrorMsg("Error", ex.Message);
        } finally {
            // Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
            if (fc != null)
            {
                fc.Destroy();
            }
        }
    }
Exemple #4
0
        void MergeCommon(Table original, Table newTable)
        {
            // ref not possible because of properties
            original.Category = UpdateString (original.Category, newTable.Category);
            original.Title = UpdateString (original.Title, newTable.Title);
            original.Description = UpdateString (original.Description, newTable.Description);

            original.NameX = UpdateString (original.NameX, newTable.NameX);

            original.UnitX = UpdateString (original.UnitX, newTable.UnitX);
            original.UnitY = UpdateString (original.UnitY, newTable.UnitY);

            if (original.TableType != newTable.TableType)
                original.ChangeTypeToAndReload (newTable.TableType, romStream);
        }
Exemple #5
0
        static void ParseCommon(XElement el, Table table)
        {
            // allow null values here when attributes don't exist
            table.Category = (string)el.Attribute (X_category);
            table.Title = (string)el.Attribute (X_name);

            XAttribute attr = el.Attribute (X_address);
            if (attr != null)
                table.Location = ParseHexInt ((string)attr, attr);
        }
        static void ScriptGnuplotCommon(StreamWriter sw, Table table)
        {
            // easy test:
            // sw.WriteLine ("plot sin(x), cos(x)"); return;

            sw.WriteLine ("set encoding utf8");
            WriteLine (sw, string.Format ("windowtitle=\"{0}\"", table.Title));
        }
        void StartProcess(Table table)
        {
            if (string.IsNullOrEmpty (exePath))
                throw new GnuPlotProcessException ("gnuplot executable path is empty!");

            process = new Process ();
            process.StartInfo.FileName = exePath;
            process.StartInfo.WorkingDirectory = System.Environment.CurrentDirectory;

            // StartInfo.UseShellExecute must be false in order to use stream redirection
            process.StartInfo.UseShellExecute = false;
            // Could write temp script file but using standard input is more elegant and allows more functionality..
            process.StartInfo.RedirectStandardInput = true;

            // --persist without stdinput method didn't work on Windows - gnuplot window closes immediatly!?
            // --persist + using stdinput prints gnuplot commands into terminal text
            // process.StartInfo.Arguments = "--persist";

            //process.StartInfo.StandardInputEncoding = System.Text.Encoding.UTF8;

            // hide additional cmd window on Windows, useful for debugging (printing gnuplot vars etc.)
            process.StartInfo.CreateNoWindow = true;

            process.EnableRaisingEvents = true;
            process.Exited += HandleProcessExited;

            process.Start ();

            stdInputStream = process.StandardInput;

            ScriptGnuplotCommon (stdInputStream, table);

            Table3D t = table as Table3D;
            if (t != null)
                ScriptGnuplot3D (stdInputStream, t);
            else
                ScriptGnuplot2D (stdInputStream, (Table2D)table);

            stdInputStream.Flush ();
        }
 /// <summary>
 /// Create or close gnuplot for given table.
 /// </summary>
 /// <param name="table">
 /// A <see cref="Table"/>
 /// </param>
 public static void ToggleGnuPlot(Table table)
 {
     GnuPlot gnuPlot = GetExistingGnuPlot (table);
     if (gnuPlot == null) {
         gnuPlot = new GnuPlot (table);
         gnupDict.Add (table, gnuPlot);
     } else {
         gnuPlot.Quit ();
     }
 }
 /// <summary>
 /// Gets existing GnuPlot object if there is one.
 /// </summary>
 /// <param name="table">
 /// The <see cref="Table"/> object.
 /// </param>
 /// <returns>
 /// The <see cref="GnuPlot"/> reference or null.
 /// </returns>
 public static GnuPlot GetExistingGnuPlot(Table table)
 {
     GnuPlot gnuPlot;
     gnupDict.TryGetValue (table, out gnuPlot);
     return gnuPlot;
 }
Exemple #10
0
        /// <summary>
        /// Plots into SVG file.
        /// As this merely redraws into export file, the current view from the plot window will be used.
        /// </summary>
        /// <param name="table">
        /// A <see cref="Table"/>
        /// </param>
        public static void CreateSVG(Table table, string svgPath)
        {
            GnuPlot gnuPlot = GetExistingGnuPlot (table);
            if (gnuPlot == null)
                throw new GnuPlotException ("Need existing gnuplot window.");

            // Test creating empty file in order to get possible exception.
            // Otherwise no easy way to get feedback from gnuplot error.
            // Sort of Unix command 'touch'.
            File.WriteAllText (svgPath, string.Empty);

            CreateSVG (gnuPlot.stdInputStream, svgPath);
        }
Exemple #11
0
        // some x-axis is shared many times with both 2D and 3D tables
        public IList<Table> FindTablesSameAxisX(Table table)
        {
            var r = Enumerable2Dand3D ().Where (t => t.RangeX.Pos == table.RangeX.Pos).AsParallel ().ToList ();

            for (int i = 0; i < r.Count; i++) {
                Console.WriteLine ("#{0}: {1}", i, r [i]);
            }

            return r;
        }
Exemple #12
0
 public void ChangeTableType(Table table, Tables.TableType newType)
 {
     table.ChangeTypeToAndReload (newType, rom.Stream);
 }