Exemple #1
0
        /// <summary>
        /// Exports a table into an Ascii file.
        /// </summary>
        /// <param name="filename">The filename used to export the file.</param>
        /// <param name="table">The table to export.</param>
        /// <param name="separator">The separator char used to export the table. Normally, you should use a tabulator here.</param>
        public static void ExportAscii(string filename, Altaxo.Data.DataTable table, char separator)
        {
            var options = new AsciiExportOptions();

            options.SetSeparator(separator);
            ExportAscii(filename, table, options);
        }
        public void EhView_CopyParameterNVV()
        {
            System.Windows.Forms.DataObject dao = new System.Windows.Forms.DataObject();
            Altaxo.Data.TextColumn          txt = new Altaxo.Data.TextColumn();
            Altaxo.Data.DoubleColumn        col = new Altaxo.Data.DoubleColumn();
            Altaxo.Data.DoubleColumn        var = new Altaxo.Data.DoubleColumn();

            for (int i = 0; i < _doc.CurrentParameters.Count; i++)
            {
                txt[i] = _doc.CurrentParameters[i].Name;
                col[i] = _doc.CurrentParameters[i].Parameter;
                var[i] = _doc.CurrentParameters[i].Variance;
            }

            Altaxo.Data.DataTable tb = new Altaxo.Data.DataTable();
            tb.DataColumns.Add(txt, "Name", Altaxo.Data.ColumnKind.V, 0);
            tb.DataColumns.Add(col, "Value", Altaxo.Data.ColumnKind.V, 0);
            tb.DataColumns.Add(var, "Variance", Altaxo.Data.ColumnKind.V, 0);
            Altaxo.Worksheet.Commands.EditCommands.WriteAsciiToClipBoardIfDataCellsSelected(
                tb, new Altaxo.Collections.AscendingIntegerCollection(),
                new Altaxo.Collections.AscendingIntegerCollection(),
                new Altaxo.Collections.AscendingIntegerCollection(),
                dao);
            System.Windows.Forms.Clipboard.SetDataObject(dao, true);
        }
Exemple #3
0
        public override void Run(Altaxo.Worksheet.GUI.WorksheetController ctrl)
        {
            Altaxo.Data.DataTable dataTable = ctrl.DataTable;
            if (ctrl.SelectedPropertyColumns.Count == 0)
            {
                return;
            }
            m_Column = dataTable.PropertyColumns[ctrl.SelectedPropertyColumns[0]];

            IScriptText script = (IScriptText)dataTable.PropertyColumns.ColumnScripts[m_Column];

            if (script == null)
            {
                script = new PropertyColumnScript();
            }

            object[] args = new object[] { script, new ScriptExecutionHandler(this.EhScriptExecution) };
            if (Current.Gui.ShowDialog(args, "PropertyColumnScript of " + m_Column.Name))
            {
                if (null != dataTable.PropertyColumns.ColumnScripts[m_Column])
                {
                    dataTable.PropertyColumns.ColumnScripts[m_Column] = (IColumnScriptText)args[0];
                }
                else
                {
                    dataTable.PropertyColumns.ColumnScripts.Add(m_Column, args[0]);
                }
            }

            this.m_Column = null;
        }
Exemple #4
0
 public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
 {
     Altaxo.Data.DataTable s = (Altaxo.Data.DataTable)obj;
     info.AddValue("Name", s._tableName);           // name of the Table
     info.AddValue("DataCols", s._dataColumns);
     info.AddValue("PropCols", s._propertyColumns); // the property columns of that table
 }
Exemple #5
0
		public override void Run()
		{
			var conn = new OriginConnection();
			conn.Connect(true);
			if (!conn.IsConnected())
				return;

			var list = new List<Tuple<string, Origin.WorksheetPage>>();
			ListAllWorksheetsInFolderAndSubfolders(conn.Application.RootFolder, string.Empty, list);

			int count = conn.Application.WorksheetPages.Count;
			for (int i = 0; i < list.Count; i++)
			{
				var path = list[i].Item1;
				var page = list[i].Item2;
				string name = page.Name;
				string lname = page.LongName;

				var newTable = new Altaxo.Data.DataTable();
				newTable.Name = path + (string.IsNullOrEmpty(lname) ? name : lname);
				string err = WorksheetActions.GetTable(page, newTable);
				if (null == err)
				{
					Current.ProjectService.CreateNewWorksheet(newTable);
				}
				else
				{
					Current.Gui.ErrorMessageBox(err);
				}
			}

			conn.Disconnect(false, null, false);
		}
Exemple #6
0
            public virtual void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
            {
                Altaxo.Data.DataTable s = (Altaxo.Data.DataTable)obj;
                info.AddValue("Name", s._tableName);           // name of the Table
                info.AddValue("DataCols", s._dataColumns);
                info.AddValue("PropCols", s._propertyColumns); // the property columns of that table

                // new in version 1
                info.AddValue("TableScript", s._tableScript);

                // new in version 2 - Add table properties
                int numberproperties = s._tableProperties == null ? 0 : s._tableProperties.Keys.Count;

                info.CreateArray("TableProperties", numberproperties);
                if (s._tableProperties != null)
                {
                    foreach (string propkey in s._tableProperties.Keys)
                    {
                        if (propkey.StartsWith("tmp/"))
                        {
                            continue;
                        }
                        info.CreateElement("e");
                        info.AddValue("Key", propkey);
                        object val = s._tableProperties[propkey];
                        info.AddValue("Value", info.IsSerializable(val) ? val : null);
                        info.CommitElement();
                    }
                }
                info.CommitArray();
            }
Exemple #7
0
        /// <summary>
        /// Exports a table to Ascii using a stream. The stream is <b>not</b> closed at the end of this function.
        /// </summary>
        /// <param name="myStream">The stream the table should be exported to.</param>
        /// <param name="table">The table that is to be exported.</param>
        /// <param name="separator">The separator char that separates the items from each other.</param>
        public static void ExportAscii(System.IO.Stream myStream, Altaxo.Data.DataTable table, char separator)
        {
            var options = new AsciiExportOptions();

            options.SetSeparator(separator);
            ExportAscii(myStream, table, options);
        }
Exemple #8
0
 /// <summary>
 /// Exports a table into an Ascii file.
 /// </summary>
 /// <param name="filename">The filename used to export the file.</param>
 /// <param name="table">The table to export.</param>
 /// <param name="options">The Ascii export options used for export.</param>
 public static void ExportAscii(string filename, Altaxo.Data.DataTable table, AsciiExportOptions options)
 {
     using (var myStream = new System.IO.FileStream(filename, System.IO.FileMode.Create))
     {
         ExportAscii(myStream, table, options);
         myStream.Close();
     }
 }
Exemple #9
0
        public bool ExecuteWithBackgroundDialogAndSuspendNotifications(Altaxo.Data.DataTable myTable)
        {
            var reporter = new Altaxo.Main.Services.ExternalDrivenBackgroundMonitor();
            var t        = new System.Threading.Thread(() => ExecuteWithSuspendedNotifications(myTable, reporter));

            t.Start();
            return(Current.Gui.ShowBackgroundCancelDialog(1000, t, reporter));
        }
Exemple #10
0
        /// <summary>
        /// Exports a table into an Ascii file.
        /// </summary>
        /// <param name="filename">The filename used to export the file.</param>
        /// <param name="table">The table to export.</param>
        /// <param name="separator">The separator char used to export the table. Normally, you should use a tabulator here.</param>
        static public void ExportAscii(string filename, Altaxo.Data.DataTable table, char separator)
        {
            System.IO.FileStream myStream = new System.IO.FileStream(filename, System.IO.FileMode.Create);

            ExportAscii(myStream, table, separator);

            myStream.Close();
        }
Exemple #11
0
            public void GetObjectData(object obj, System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
            {
                Altaxo.Data.DataTable s = (Altaxo.Data.DataTable)obj;

                info.AddValue("Name", s._tableName);           // name of the Table
                info.AddValue("DataCols", s.DataColumns);      // the data columns of that table
                info.AddValue("PropCols", s._propertyColumns); // the property columns of that table
            }
Exemple #12
0
        /// <summary>
        /// Creates a view content for a table.
        /// </summary>
        /// <param name="table">The table which should be viewed.</param>
        /// <returns>The view content for the provided table.</returns>
        public Altaxo.Worksheet.GUI.IWorksheetController CreateNewWorksheet(Altaxo.Data.DataTable table)
        {
            if (table.ParentObject == null)
            {
                this.CurrentOpenProject.DataTableCollection.Add(table);
            }

            return(CreateNewWorksheet(table, this.CurrentOpenProject.CreateNewTableLayout(table)));
        }
Exemple #13
0
            public object SetObjectData(object obj, System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.ISurrogateSelector selector)
            {
                Altaxo.Data.DataTable s = (Altaxo.Data.DataTable)obj;

                s._tableName       = info.GetString("Name");
                s._dataColumns     = (DataColumnCollection)info.GetValue("DataCols", typeof(DataColumnCollection));
                s._propertyColumns = (DataColumnCollection)info.GetValue("PropCols", typeof(DataColumnCollection));

                return(s);
            }
Exemple #14
0
        public static void Duplicate(WorksheetController ctrl)
        {
            Altaxo.Data.DataTable clonedTable = (Altaxo.Data.DataTable)ctrl.DataTable.Clone();


            // find a new name for the cloned table and add it to the DataTableCollection
            clonedTable.Name = Data.DataTableCollection.GetParentDataTableCollectionOf(ctrl.DataTable).FindNewTableName();
            Data.DataTableCollection.GetParentDataTableCollectionOf(ctrl.DataTable).Add(clonedTable);
            Current.ProjectService.CreateNewWorksheet(clonedTable);
        }
Exemple #15
0
        /// <summary>
        /// Creates the controller for the Galactic SPC file export dialog.
        /// </summary>
        /// <param name="table">The data table which is about to be exported.</param>
        /// <param name="selectedRows">The selected rows of the data table.</param>
        /// <param name="selectedColumns">The selected columns of the data table.</param>
        public ExportGalacticSpcFileDialogController(
            Altaxo.Data.DataTable table,
            IAscendingIntegerCollection selectedRows,
            IAscendingIntegerCollection selectedColumns)
        {
            m_Table           = table;
            m_SelectedRows    = selectedRows;
            m_SelectedColumns = selectedColumns;

            InitializeElements();
        }
Exemple #16
0
        public Altaxo.Worksheet.WorksheetLayout CreateNewTableLayout(Altaxo.Data.DataTable table)
        {
            if (!_dataTables.Contains(table))
            {
                _dataTables.Add(table);
            }

            var layout = new Altaxo.Worksheet.WorksheetLayout(table);

            _tableLayouts.Add(layout);
            return(layout);
        }
        public void Remove(Altaxo.Data.DataTable theTable)
        {
            if (m_TablesByName.ContainsValue(theTable))
            {
                m_TablesByName.Remove(theTable.Name);
                theTable.ParentChanged -= new Main.ParentChangedEventHandler(this.EhTableParentChanged);
                theTable.NameChanged   -= new Main.NameChangedEventHandler(this.EhTableNameChanged);
                theTable.ParentObject   = null;
            }

            this.SelfChanged(ChangedEventArgs.IfTableRemoved);
        }
Exemple #18
0
        /// <summary>
        /// Exports a table to Ascii using a stream. The stream is <b>not</b> closed at the end of this function.
        /// </summary>
        /// <param name="myStream">The stream the table should be exported to.</param>
        /// <param name="table">The table that is to be exported.</param>
        /// <param name="separator">The separator char that separates the items from each other.</param>
        static public void ExportAscii(System.IO.Stream myStream, Altaxo.Data.DataTable table, char separator)
        {
            StreamWriter strwr = new StreamWriter(myStream, System.Text.Encoding.Default); // Change to Unicode or quest encoding by a dialog box

            ExportDataColumnNames(strwr, table, separator);

            ExportPropertyColumns(strwr, table.PropCols, table.DataColumns.ColumnCount, separator);

            ExportDataColumns(strwr, table.DataColumns, separator);

            strwr.Flush();
        }
Exemple #19
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                Altaxo.Data.DataTable s = null != o ? (Altaxo.Data.DataTable)o : new Altaxo.Data.DataTable();

                s._tableName   = info.GetString("Name");
                s._dataColumns = (DataColumnCollection)info.GetValue("DataCols", s);
                s._dataColumns.ParentObject     = s;
                s._propertyColumns              = (DataColumnCollection)info.GetValue("PropCols", s);
                s._propertyColumns.ParentObject = s;

                return(s);
            }
Exemple #20
0
        /// <summary>
        /// Executes the script. If no instance of the script object exists, a error message will be stored and the return value is false.
        /// If the script object exists, the data change notifications will be switched of (for all tables).
        /// Then the Execute function of this script object is called. Afterwards, the data changed notifications are switched on again.
        /// </summary>
        /// <param name="myTable">The data table this script is working on.</param>
        /// <returns>True if executed without exceptions, otherwise false.</returns>
        /// <remarks>If exceptions were thrown during execution, the exception messages are stored
        /// inside the column script and can be recalled by the Errors property.</remarks>
        public bool ExecuteWithSuspendedNotifications(Altaxo.Data.DataTable myTable)
        {
            bool bSucceeded = true;

            Altaxo.Data.DataTableCollection myDataSet = null;

            // first, test some preconditions
            if (null == m_ScriptObject)
            {
                m_Errors = new string[1] {
                    "Script Object is null"
                };
                return(false);
            }

            myDataSet = Altaxo.Data.DataTableCollection.GetParentDataTableCollectionOf(myTable);

            if (null != myDataSet)
            {
                myDataSet.Suspend();
            }
            else if (null != myTable)
            {
                myTable.Suspend();
            }

            try
            {
                ((Altaxo.Calc.TableScriptExeBase)m_ScriptObject).Execute(myTable);
            }
            catch (Exception ex)
            {
                bSucceeded  = false;
                m_Errors    = new string[1];
                m_Errors[0] = ex.ToString();
            }
            finally
            {
                if (null != myDataSet)
                {
                    myDataSet.Resume();
                }
                else if (null != myTable)
                {
                    myTable.Resume();
                }
            }

            return(bSucceeded);
        }
Exemple #21
0
        public Altaxo.Data.DataTable CreateNewTable(string worksheetName, bool bCreateDefaultColumns)
        {
            var dt1 = new Altaxo.Data.DataTable(worksheetName);

            if (bCreateDefaultColumns)
            {
                dt1.DataColumns.Add(new Altaxo.Data.DoubleColumn(), "A", Altaxo.Data.ColumnKind.X);
                dt1.DataColumns.Add(new Altaxo.Data.DoubleColumn(), "B");
            }

            DataTableCollection.Add(dt1);

            return(dt1);
        }
        public string GetName(int level)
        {
            IReadableColumn col = this.Document; // this may have the side effect that the object is tried to resolve, is this o.k.?

            if (col is Data.DataColumn)
            {
                Altaxo.Data.DataTable table = Altaxo.Data.DataTable.GetParentDataTableOf((DataColumn)col);
                string tablename            = table == null ? string.Empty : table.Name + "\\";
                string collectionname       = table == null ? string.Empty : (table.PropertyColumns.ContainsColumn((DataColumn)col) ? "PropCols\\" : "DataCols\\");
                if (level <= 0)
                {
                    return(((DataColumn)col).Name);
                }
                else if (level == 1)
                {
                    return(tablename + ((DataColumn)col).Name);
                }
                else
                {
                    return(tablename + collectionname + ((DataColumn)col).Name);
                }
            }
            else if (base._docNodePath != null)
            {
                string path = _docNodePath.ToString();
                int    idx  = 0;
                if (level <= 0)
                {
                    idx = path.LastIndexOf('/');
                    if (idx < 0)
                    {
                        idx = 0;
                    }
                    else
                    {
                        idx++;
                    }
                }

                return(path.Substring(idx));
            }
            else if (col != null)
            {
                return(col.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
Exemple #23
0
        /// <summary>
        /// Executes the script. If no instance of the script object exists, a error message will be stored and the return value is false.
        /// If the script object exists, the data change notifications will be switched of (for all tables).
        /// Then the Execute function of this script object is called. Afterwards, the data changed notifications are switched on again.
        /// </summary>
        /// <param name="myTable">The data table this script is working on.</param>
        /// <param name="reporter">Progress reporter that can be used by the script to report the progress of its work.</param>
        /// <returns>True if executed without exceptions, otherwise false.</returns>
        /// <remarks>If exceptions were thrown during execution, the exception messages are stored
        /// inside the column script and can be recalled by the Errors property.</remarks>
        public bool ExecuteWithSuspendedNotifications(Altaxo.Data.DataTable myTable, Altaxo.IProgressReporter reporter)
        {
            bool bSucceeded = true;

            Altaxo.Data.DataTableCollection myDataSet = null;

            if (null == _scriptObject && !_wasTriedToCompile)
            {
                Compile();
            }

            // first, test some preconditions
            if (null == _scriptObject)
            {
                _errors = ImmutableArray.Create(new CompilerDiagnostic(null, null, DiagnosticSeverity.Error, "Script Object is null"));
                return(false);
            }

            myDataSet = Altaxo.Data.DataTableCollection.GetParentDataTableCollectionOf(myTable);

            IDisposable suspendToken = null;

            if (null != myDataSet)
            {
                suspendToken = myDataSet.SuspendGetToken();
            }
            else if (null != myTable)
            {
                suspendToken = myTable.SuspendGetToken();
            }

            try
            {
                ((Altaxo.Calc.TableScriptExeBase)_scriptObject).Execute(myTable, reporter);
            }
            catch (Exception ex)
            {
                bSucceeded = false;
                _errors    = ImmutableArray.Create(new CompilerDiagnostic(null, null, DiagnosticSeverity.Error, ex.ToString()));
            }
            finally
            {
                if (null != suspendToken)
                {
                    suspendToken.Dispose();
                }
            }

            return(bSucceeded);
        }
        /// <summary>
        /// Exports to a single SPC spectrum from a single table column.
        /// </summary>
        /// <param name="filename">The name of the file where to export to.</param>
        /// <param name="table">The table from which to export.</param>
        /// <param name="columnnumber">The number of the table column that contains the data to export.</param>
        /// <param name="xcolumn">The x column that contains the x data.</param>
        /// <param name="selectedRows">The rows that where selected in the table, i.e. the rows which are exported. If this parameter is null
        /// or no rows are selected, then all data of a column will be exported.</param>
        /// <returns>Null if export was successfull, error description otherwise.</returns>
        public static string FromColumn(
            string filename,
            Altaxo.Data.DataTable table,
            int columnnumber,
            Altaxo.Data.INumericColumn xcolumn,
            IAscendingIntegerCollection selectedRows)
        {
            if (!(table.DataColumns[columnnumber] is Altaxo.Data.INumericColumn))
            {
                return(string.Format("Table column[{0}] ({1}) is not a numeric column!", columnnumber, table.DataColumns[columnnumber].FullName));
            }



            // test that all x and y cells have numeric values
            bool bUseSel     = null != selectedRows && selectedRows.Count > 0;
            int  spectrumlen = (bUseSel)? selectedRows.Count : table.DataColumns[columnnumber].Count;

            int i, j;

            for (j = 0; j < spectrumlen; j++)
            {
                i = bUseSel ? selectedRows[j] : j;

                if (xcolumn[i] == Double.NaN)
                {
                    return(string.Format("X column at index {i} has no numeric value!", i));
                }

                if (((Altaxo.Data.INumericColumn)table.DataColumns[columnnumber])[i] == Double.NaN)
                {
                    return(string.Format("Table cell [{0},{1}] (column {2}) has no numeric value!", columnnumber, i, table.DataColumns[columnnumber].FullName));
                }
            }


            // this first test was successfull, so start exporting now

            double[] xvalues = new double[spectrumlen];
            double[] yvalues = new double[spectrumlen];

            for (j = 0; j < spectrumlen; j++)
            {
                i          = bUseSel ? selectedRows[j] : j;
                xvalues[j] = xcolumn[i];
                yvalues[j] = ((Altaxo.Data.INumericColumn)table.DataColumns[columnnumber])[i];
            }
            return(FromArrays(xvalues, yvalues, filename));
        }
        public static string TwoDimCenteredFFT(Altaxo.AltaxoDocument mainDocument, GUI.WorksheetController dg)
        {
            int rows = dg.Doc.DataColumns.RowCount;
            int cols = dg.Doc.DataColumns.ColumnCount;

            // reserve two arrays (one for real part, which is filled with the table contents)
            // and the imaginary part - which is left zero here)

            double[] rePart;
            double[] imPart;

            string stringresult = TwoDimFFT(mainDocument, dg, out rePart, out imPart);

            if (stringresult != null)
            {
                return(stringresult);
            }

            Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("Fourieramplitude of " + dg.Doc.Name);

            // Fill the Table so that the zero frequency point is in the middle
            // this means for the point order:
            // for even number of points, i.e. 8 points, the frequencies are -3, -2, -1, 0, 1, 2, 3, 4  (the frequency 4 is the nyquist part)
            // for odd number of points, i.e. 9 points, the frequencies are -4, -3, -2, -1, 0, 1, 2, 3, 4 (for odd number of points there is no nyquist part)

            table.Suspend();
            int colsNegative = (cols - 1) / 2;      // number of negative frequency points
            int colsPositive = cols - colsNegative; // number of positive (or null) frequency points
            int rowsNegative = (rows - 1) / 2;
            int rowsPositive = rows - rowsNegative;

            for (int i = 0; i < cols; i++)
            {
                int sc = i < colsNegative ?  i + colsPositive : i - colsNegative;// source column index centered
                Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn();
                for (int j = 0; j < rows; j++)
                {
                    int sr = j < rowsNegative ? j + rowsPositive : j - rowsNegative; // source row index centered
                    col[j] = rePart[sc * rows + sr];
                }
                table.DataColumns.Add(col);
            }
            table.Resume();
            mainDocument.DataTableCollection.Add(table);
            // create a new worksheet without any columns
            Current.ProjectService.CreateNewWorksheet(table);

            return(null);
        }
Exemple #26
0
        /// <summary>
        /// Creates a view content for a table.
        /// </summary>
        /// <param name="table">The table which should be viewed.</param>
        /// <param name="layout">The layout for the table.</param>
        /// <returns>The view content for the provided table.</returns>
        public Altaxo.Worksheet.GUI.IWorksheetController CreateNewWorksheet(Altaxo.Data.DataTable table, Altaxo.Worksheet.WorksheetLayout layout)
        {
            layout.DataTable = table;
            Altaxo.Gui.SharpDevelop.SDWorksheetViewContent ctrl = new Altaxo.Gui.SharpDevelop.SDWorksheetViewContent(layout);
            Altaxo.Worksheet.GUI.WorksheetView             view = new Altaxo.Worksheet.GUI.WorksheetView();
            ctrl.Controller.View = view;


            if (null != Current.Workbench)
            {
                Current.Workbench.ShowView(ctrl);
            }

            return(ctrl.Controller);
        }
Exemple #27
0
 /// <summary>
 /// Imports ascii from a memory stream into a table. Returns null (!) if nothing is imported.
 /// </summary>
 /// <param name="stream">The stream to import ascii from. Is not (!) closed at the end of this function.</param>
 /// <returns>The table representation of the imported text, or null if nothing is imported.</returns>
 public static Altaxo.Data.DataTable Import(System.IO.Stream stream)
 {
     Altaxo.Data.DataTable table = new Altaxo.Data.DataTable();
     Altaxo.Serialization.Ascii.AsciiImporter      importer = new Altaxo.Serialization.Ascii.AsciiImporter(stream);
     Altaxo.Serialization.Ascii.AsciiImportOptions options  = importer.Analyze(20, new Altaxo.Serialization.Ascii.AsciiImportOptions());
     if (options != null)
     {
         importer.ImportAscii(options, table);
         return(table);
     }
     else
     {
         return(null);
     }
 }
Exemple #28
0
        /// <summary>
        /// Opens a view that shows the table <code>table</code>. If no view for the table can be found,
        /// a new default view is created for the table.
        /// </summary>
        /// <param name="table">The table for which a view must be found.</param>
        /// <returns>The view content for the provided table.</returns>
        private object OpenOrCreateWorksheetForTable_Unsynchronized(Altaxo.Data.DataTable table)
        {
            // if a content exist that show that table, activate that content
            var foundContent = GetViewContentsForDocument(table).FirstOrDefault();

            if (foundContent != null)
            {
                foundContent.IsVisible = true;
                foundContent.IsActive  = true;
                return(foundContent);
            }

            // otherwise create a new Worksheet
            return(CreateNewWorksheet_Unsynchronized(table));
        }
Exemple #29
0
        /// <summary>
        /// This will create a property column as text column with the names of the data columns.
        /// </summary>
        /// <param name="table">The data table.</param>
        public static void CreatePropertyColumnOfColumnNames(Altaxo.Data.DataTable table)
        {
            const string NameColumnName = "LongName";

            var col = (Altaxo.Data.TextColumn)table.PropertyColumns.EnsureExistence(NameColumnName, typeof(Altaxo.Data.TextColumn), Altaxo.Data.ColumnKind.Label, 0);

            using (var suspendToken = col.SuspendGetToken())
            {
                for (int i = table.DataColumnCount - 1; i >= 0; i--)
                {
                    col[i] = table.DataColumns.GetColumnName(i);
                }
                suspendToken.Resume();
            }
        }
Exemple #30
0
        /// <summary>
        /// Opens a view that shows the table <code>table</code>. If no view for the table can be found,
        /// a new default view is created for the table.
        /// </summary>
        /// <param name="table">The table for which a view must be found.</param>
        /// <returns>The view content for the provided table.</returns>
        public object OpenOrCreateWorksheetForTable(Altaxo.Data.DataTable table)
        {
            // if a content exist that show that table, activate that content
            List <IViewContent> foundContent = SearchContentForDocument(table, 1);

            if (foundContent.Count > 0)
            {
                foundContent[0].WorkbenchWindow.SelectWindow();
                return(foundContent[0]);
            }


            // otherwise create a new Worksheet
            return(CreateNewWorksheet(table));
        }
Exemple #31
0
        public static void ImportImage(Altaxo.Data.DataTable table)
        {
            ColorAmplitudeFunction colorfunc;

            System.IO.Stream myStream;
            OpenFileDialog   openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "Image files (*.bmp;*.jpg;*.png,*.tif)|*.bmp;*.jpg;*.png,*.tif|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = openFileDialog1.OpenFile()) != null)
                {
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(myStream);

                    int sizex = bmp.Width;
                    int sizey = bmp.Height;
                    //if(Format16bppGrayScale==bmp.PixelFormat)

                    colorfunc = new ColorAmplitudeFunction(ColorToBrightness);
                    // add here other function or the result of a dialog box

                    // now add new columns to the worksheet,
                    // the name of the columns should preferabbly simply
                    // the index in x direction

                    table.Suspend();
                    for (int i = 0; i < sizex; i++)
                    {
                        Altaxo.Data.DoubleColumn dblcol = new Altaxo.Data.DoubleColumn();
                        for (int j = sizey - 1; j >= 0; j--)
                        {
                            dblcol[j] = colorfunc(bmp.GetPixel(i, j));
                        }

                        table.DataColumns.Add(dblcol, table.DataColumns.FindUniqueColumnName(i.ToString())); // Spalte hinzufügen
                    } // end for all x coordinaates

                    table.Resume();

                    myStream.Close();
                    myStream = null;
                } // end if myStream was != null
            }
        }
Exemple #32
0
		public virtual void Dispose()
		{
			var view = ViewObject;
			this.ViewObject = null;
			if (view is IDisposable)
				((IDisposable)view).Dispose();

			if (null != _table)
			{
				_weakTableNameChangedHandler.Remove();
			}

			_table = null;
			_worksheetLayout = null; // removes also the event handler(s)
		}
			public WorksheetRenameValidator(DataTable table)
				: base("The worksheet name must not be empty! Please enter a valid name.")
			{
				_table = table;
			}
    public override void Run(Altaxo.Worksheet.GUI.WorksheetController ctrl)
    {
      m_Table = ctrl.DataTable;
      ExtractTableDataScript script = ctrl.DataTable.GetTableProperty(ExtractTableDataScriptPropertyName) as ExtractTableDataScript;

      if(script==null)
        script = new ExtractTableDataScript();

      object[] args = new object[]{script,new ScriptExecutionHandler(this.EhScriptExecution)};
      if(Current.Gui.ShowDialog(args, "WorksheetScript of " + m_Table.Name))
      {
        m_Table.SetTableProperty(ExtractTableDataScriptPropertyName, args[0]);
      }
    
      this.m_Table = null;
    }
 public WorksheetRenameValidator(Altaxo.Data.DataTable tab, WorksheetController ctrl)
   : base("The worksheet name must not be empty! Please enter a valid name.")
 {
   m_Table = tab;
   m_Ctrl = ctrl;
 }
    public void EhView_CopyParameterNVV()
    {
      System.Windows.Forms.DataObject dao = new System.Windows.Forms.DataObject();
      Altaxo.Data.TextColumn txt = new Altaxo.Data.TextColumn();
      Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn();
      Altaxo.Data.DoubleColumn var = new Altaxo.Data.DoubleColumn();

      for (int i = 0; i < _doc.CurrentParameters.Count; i++)
      {
        txt[i] = _doc.CurrentParameters[i].Name;
        col[i] = _doc.CurrentParameters[i].Parameter;
        var[i] = _doc.CurrentParameters[i].Variance;
      }

      Altaxo.Data.DataTable tb = new Altaxo.Data.DataTable();
      tb.DataColumns.Add(txt, "Name", Altaxo.Data.ColumnKind.V, 0);
      tb.DataColumns.Add(col, "Value", Altaxo.Data.ColumnKind.V, 0);
      tb.DataColumns.Add(var, "Variance", Altaxo.Data.ColumnKind.V, 0);
      Altaxo.Worksheet.Commands.EditCommands.WriteAsciiToClipBoardIfDataCellsSelected(
        tb, new Altaxo.Collections.AscendingIntegerCollection(),
        new Altaxo.Collections.AscendingIntegerCollection(),
        new Altaxo.Collections.AscendingIntegerCollection(),
        dao);
      System.Windows.Forms.Clipboard.SetDataObject(dao, true);
    }
 public WorksheetLayout(Altaxo.Data.DataTable table)
   : this()
 {
   m_DataTable = table;
 }
		/// <summary>
		/// Creates the controller for the Galactic SPC file export dialog.
		/// </summary>
		/// <param name="table">The data table which is about to be exported.</param>
		/// <param name="selectedRows">The selected rows of the data table.</param>
		/// <param name="selectedColumns">The selected columns of the data table.</param>
		public ExportGalacticSpcFileDialogController(
			Altaxo.Data.DataTable table,
			IAscendingIntegerCollection selectedRows,
			IAscendingIntegerCollection selectedColumns)
		{
			m_Table = table;
			m_SelectedRows = selectedRows;
			m_SelectedColumns = selectedColumns;

			InitializeElements();
		}
Exemple #39
0
		protected virtual void InternalInitializeWorksheetLayout(WorksheetLayout value)
		{
			if (null != _worksheetLayout)
				throw new ApplicationException("This controller is already controlling a layout");
			if (null != _table)
				throw new ApplicationException("This controller is already controlling a table");
			if (null == value)
				throw new ArgumentNullException("value");
			if (null == value.DataTable)
				throw new ApplicationException("The DataTable of the WorksheetLayout is null");

			_worksheetLayout = value;
			_table = _worksheetLayout.DataTable;
			var table = _table; // use local variable for anonymous method below
			_table.Changed += (_weakTableNameChangedHandler = new WeakEventHandler(this.EhTableNameChanged, x => table.Changed -= x));
			OnTitleNameChanged();
		}
    public static string TwoDimFFT(Altaxo.AltaxoDocument mainDocument, GUI.WorksheetController dg)
    {
      int rows = dg.Doc.DataColumns.RowCount;
      int cols = dg.Doc.DataColumns.ColumnCount;

      // reserve two arrays (one for real part, which is filled with the table contents)
      // and the imaginary part - which is left zero here)

      double[] rePart;
      double[] imPart;

      string stringresult = TwoDimFFT(mainDocument,dg,out rePart, out imPart);

      if(stringresult!=null)
        return stringresult;

      Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("Fourieramplitude of " + dg.Doc.Name);

      // Fill the Table
      table.Suspend();
      for(int i=0;i<cols;i++)
      {
        Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn();
        for(int j=0;j<rows;j++)
          col[j] = rePart[i*rows+j];
        
        table.DataColumns.Add(col);
      }
      table.Resume();
      mainDocument.DataTableCollection.Add(table);
      // create a new worksheet without any columns
      Current.ProjectService.CreateNewWorksheet(table);

      return null;
    }
 /// <summary>
 /// Imports ascii from a memory stream into a table. Returns null (!) if nothing is imported.
 /// </summary>
 /// <param name="stream">The stream to import ascii from. Is not (!) closed at the end of this function.</param>
 /// <returns>The table representation of the imported text, or null if nothing is imported.</returns>
 public static Altaxo.Data.DataTable Import(System.IO.Stream stream)
 {
   Altaxo.Data.DataTable table = new Altaxo.Data.DataTable();
   Altaxo.Serialization.Ascii.AsciiImporter importer = new Altaxo.Serialization.Ascii.AsciiImporter(stream);
   Altaxo.Serialization.Ascii.AsciiImportOptions options = importer.Analyze(20,new Altaxo.Serialization.Ascii.AsciiImportOptions());
   if(options!=null)
   {
     importer.ImportAscii(options,table);
     return table;
   }
   else
   {
     return null;
   }
 }
    } // end of function ImportAscii



    /// <summary>
    /// Imports ascii from a string into a table. Returns null (!) if nothing is imported.
    /// </summary>
    /// <param name="text">The text to import as ascii.</param>
    /// <returns>The table representation of the imported text, or null if nothing is imported.</returns>
    public static Altaxo.Data.DataTable Import(string text)
    {
      System.IO.MemoryStream memstream = new System.IO.MemoryStream();
      System.IO.TextWriter textwriter = new System.IO.StreamWriter(memstream);
      textwriter.Write(text);
      textwriter.Flush();
      memstream.Position = 0;

      Altaxo.Data.DataTable table = new Altaxo.Data.DataTable();
      Altaxo.Serialization.Ascii.AsciiImporter importer = new Altaxo.Serialization.Ascii.AsciiImporter(memstream);
      Altaxo.Serialization.Ascii.AsciiImportOptions options = importer.Analyze(20,new Altaxo.Serialization.Ascii.AsciiImportOptions());

      if(options!=null)
      {
        importer.ImportAscii(options,table);
        return table;
      }
      else
      {
        return null; 
      }
    }
Exemple #43
0
		public AltaxoTableConnector(Altaxo.Data.DataTable table)
		{
			_table = table;
		}
Exemple #44
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="table">The table.</param>
		/// <param name="layout">The layout of the table.</param>
		public TablePlusLayout(Altaxo.Data.DataTable table, Altaxo.Worksheet.WorksheetLayout layout)
		{
			_table = table;
			_layout = layout;
		}
		private void EhCurvePointsCopyTriggered()
		{
			var points = _view.CurvePoints;

			var dao = Current.Gui.GetNewClipboardDataObject();
			Altaxo.Data.DoubleColumn xcol = new Altaxo.Data.DoubleColumn();
			Altaxo.Data.DoubleColumn ycol = new Altaxo.Data.DoubleColumn();
			for (int i = 0; i < points.Count; i++)
			{
				xcol[i] = new DimensionfulQuantity(points[i].X, Units.Length.Point.Instance).AsValueIn(PositionEnvironment.Instance.DefaultUnit);
				ycol[i] = new DimensionfulQuantity(points[i].Y, Units.Length.Point.Instance).AsValueIn(PositionEnvironment.Instance.DefaultUnit);
			}

			Altaxo.Data.DataTable tb = new Altaxo.Data.DataTable();
			tb.DataColumns.Add(xcol, "XPosition", Altaxo.Data.ColumnKind.V, 0);
			tb.DataColumns.Add(ycol, "YPosition", Altaxo.Data.ColumnKind.V, 0);
			Altaxo.Worksheet.Commands.EditCommands.WriteAsciiToClipBoardIfDataCellsSelected(
				tb, new Altaxo.Collections.AscendingIntegerCollection(),
				new Altaxo.Collections.AscendingIntegerCollection(),
				new Altaxo.Collections.AscendingIntegerCollection(),
				dao);
			Current.Gui.SetClipboardDataObject(dao, true);
		}
 public TransposeWorksheetController(Altaxo.Data.DataTable table)
 {
   _table = table;
 }
    public static string TwoDimCenteredFFT(Altaxo.AltaxoDocument mainDocument, GUI.WorksheetController dg)
    {
      int rows = dg.Doc.DataColumns.RowCount;
      int cols = dg.Doc.DataColumns.ColumnCount;

      // reserve two arrays (one for real part, which is filled with the table contents)
      // and the imaginary part - which is left zero here)

      double[] rePart;
      double[] imPart;

      string stringresult = TwoDimFFT(mainDocument,dg,out rePart, out imPart);

      if(stringresult!=null)
        return stringresult;

      Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("Fourieramplitude of " + dg.Doc.Name);

      // Fill the Table so that the zero frequency point is in the middle
      // this means for the point order:
      // for even number of points, i.e. 8 points, the frequencies are -3, -2, -1, 0, 1, 2, 3, 4  (the frequency 4 is the nyquist part)
      // for odd number of points, i.e. 9 points, the frequencies are -4, -3, -2, -1, 0, 1, 2, 3, 4 (for odd number of points there is no nyquist part)

      table.Suspend();
      int colsNegative = (cols-1)/2; // number of negative frequency points
      int colsPositive = cols - colsNegative; // number of positive (or null) frequency points
      int rowsNegative= (rows-1)/2;
      int rowsPositive = rows - rowsNegative;
      for(int i=0;i<cols;i++)
      {
        int sc = i<colsNegative ?  i + colsPositive : i - colsNegative; // source column index centered  
        Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn();
        for(int j=0;j<rows;j++)
        {
          int sr = j<rowsNegative ? j + rowsPositive : j - rowsNegative; // source row index centered
          col[j] = rePart[sc*rows+sr];
        }
        table.DataColumns.Add(col);
      }
      table.Resume();
      mainDocument.DataTableCollection.Add(table);
      // create a new worksheet without any columns
      Current.ProjectService.CreateNewWorksheet(table);

      return null;
    }
    public override void Run(Altaxo.Worksheet.GUI.WorksheetController ctrl)
    {
      m_Table = ctrl.DataTable;
      
      IScriptText script = m_Table.TableScript;

      if(script==null)
        script = new TableScript();

      object[] args = new object[]{script,new Altaxo.Gui.Scripting.ScriptExecutionHandler(this.EhScriptExecution)};
      if(Current.Gui.ShowDialog(args, "WorksheetScript of " + m_Table.Name))
      {
        m_Table.TableScript = (TableScript)args[0];
      }

      this.m_Table = null;
      
    }
		public PredictionModelExporter(Altaxo.Data.DataTable table, int numberOfFactors)
		{
			_table = table;
			_memento = table.GetTableProperty("Content") as MultivariateContentMemento;
			_numberOfFactors = numberOfFactors;
		}