Exemple #1
0
        private static Tuple <string, NonlinearFitDocument, string, XYPlotLayer> SelectFitDocument(Altaxo.Gui.Graph.Gdi.Viewing.IGraphController ctrl)
        {
            XYPlotLayer activeLayer = null;

            // is a nonlinear fit function plot item selected ?
            var funcPlotItem = ctrl.SelectedRealObjects.OfType <XYNonlinearFitFunctionPlotItem>().FirstOrDefault();

            if (null != funcPlotItem)
            {
                activeLayer = Altaxo.Main.AbsoluteDocumentPath.GetRootNodeImplementing <XYPlotLayer>(funcPlotItem);
                return(new Tuple <string, NonlinearFitDocument, string, XYPlotLayer>(string.Empty, funcPlotItem.FitDocumentCopy, funcPlotItem.FitDocumentIdentifier, activeLayer)); // if a fit function plot item was selected, then use the fit document of this item
            }

            // is a normal plot item selected ?
            // ------------------------------------------------------------------------------------
            var columnPlotItem = ctrl.SelectedRealObjects.OfType <XYColumnPlotItem>().FirstOrDefault();

            if (null != columnPlotItem)
            {
                return(SelectFitDocument(ctrl, columnPlotItem));
            }

            // is the active layer an XY-plot layer ? Or do we have any XY-plot-layer ?
            // ------------------------------------------------------------------------------------
            activeLayer = (ctrl.ActiveLayer as XYPlotLayer);
            if (null != activeLayer)
            {
                var result = SelectFitDocument(ctrl, activeLayer);
                if (result.Item2 != null)
                {
                    return(result);
                }
            } // null != activeLayer

            activeLayer = TreeNodeExtensions.TakeFromHereToFirstLeaves(ctrl.Doc.RootLayer).OfType <XYPlotLayer>().FirstOrDefault();
            if (null != activeLayer)
            {
                var result = SelectFitDocument(ctrl, activeLayer);
                if (result.Item2 != null)
                {
                    return(result);
                }
                else
                {
                    var localdoc = (ctrl.Doc.GetGraphProperty(FitDocumentPropertyName) as Calc.Regression.Nonlinear.NonlinearFitDocument) ??
                                   (Altaxo.Calc.Regression.Nonlinear.NonlinearFitDocument)_lastFitDocument?.Clone() ??
                                   new Altaxo.Calc.Regression.Nonlinear.NonlinearFitDocument();

                    return(new Tuple <string, NonlinearFitDocument, string, XYPlotLayer>(null, localdoc, null, activeLayer));
                }
            } // null != activeLayer

            // no idea what to fit - there is not even an XY plot layer
            return(new Tuple <string, NonlinearFitDocument, string, XYPlotLayer>("The graph has no XYPlotLayer to host any fit function", null, null, null));
        }
Exemple #2
0
        private static Tuple <string, NonlinearFitDocument, string, XYPlotLayer> SelectFitDocument(Gui.Graph.Gdi.Viewing.IGraphController ctrl, XYPlotLayer activeLayer)
        {
            if (null == activeLayer)
            {
                throw new ArgumentNullException(nameof(activeLayer));
            }

            // try to use the first nonlinear function plot item of the active layer
            // ------------------------------------------------------------------------------------
            {
                var plotItem = TreeNodeExtensions.TakeFromHereToFirstLeaves((IGPlotItem)activeLayer.PlotItems).OfType <XYNonlinearFitFunctionPlotItem>().FirstOrDefault();
                if (null != plotItem)
                {
                    return(new Tuple <string, NonlinearFitDocument, string, XYPlotLayer>(string.Empty, plotItem.FitDocumentCopy, plotItem.FitDocumentIdentifier, activeLayer));
                }
            }

            // try to use the active plot item of the active layer
            // ------------------------------------------------------------------------------------

            if (ctrl.CurrentPlotNumber >= 0)
            {
                var plotItem = activeLayer.PlotItems.Flattened[ctrl.CurrentPlotNumber] as XYColumnPlotItem;
                return(SelectFitDocument(ctrl, plotItem));
            }

            // try to use the first plot item of the active layer
            // ------------------------------------------------------------------------------------
            {
                var plotItem = TreeNodeExtensions.TakeFromHereToFirstLeaves((IGPlotItem)activeLayer.PlotItems).OfType <XYColumnPlotItem>().FirstOrDefault();
                if (null != plotItem)
                {
                    return(SelectFitDocument(ctrl, plotItem));
                }
            }

            return(new Tuple <string, NonlinearFitDocument, string, XYPlotLayer>(null, null, null, null));
        }
Exemple #3
0
        private static Tuple <string, NonlinearFitDocument, string, XYPlotLayer> SelectFitDocument(Gui.Graph.Gdi.Viewing.IGraphController ctrl, XYColumnPlotItem columnPlotItem)
        {
            if (null == columnPlotItem)
            {
                throw new ArgumentNullException(nameof(columnPlotItem));
            }

            var        activeLayer             = Altaxo.Main.AbsoluteDocumentPath.GetRootNodeImplementing <XYPlotLayer>(columnPlotItem);
            DataColumn columPlotItemDataColumn = columnPlotItem.Data.YColumn.GetUnderlyingDataColumnOrDefault();

            if (null != columPlotItemDataColumn)
            {
                // try to find a nonlinear function plot item whose dependent variable equals to the y of the column plot item
                foreach (var funcItem in TreeNodeExtensions.TakeFromHereToFirstLeaves((IGPlotItem)activeLayer.PlotItems).OfType <XYNonlinearFitFunctionPlotItem>())
                {
                    if (object.ReferenceEquals(columPlotItemDataColumn, funcItem.DependentVariableColumn.GetUnderlyingDataColumnOrDefault()))
                    {
                        return(new Tuple <string, NonlinearFitDocument, string, XYPlotLayer>(string.Empty, funcItem.FitDocumentCopy, funcItem.FitDocumentIdentifier, activeLayer));
                    }
                }
            }
            // Get a new fit document from the selected xy plot item
            return(GetNewFitDocumentFor(columnPlotItem, ctrl));
        }