public static bool IsGraphTemplateSuitable(GraphDocument graphTemplate, out string problemDescription)
        {
            // Make sure that the graph contains an XYPlotLayer

            if (0 == graphTemplate.RootLayer.Layers.Count)
            {
                problemDescription = "The graph does not contain any layers besides the root layer.";
                return(false);
            }

            var xyzlayer = (XYZPlotLayer)TreeNodeExtensions.AnyBetweenHereAndLeaves <HostLayer>(graphTemplate.RootLayer, x => x is XYZPlotLayer);

            if (null == xyzlayer)
            {
                problemDescription = "The graph does not contain any x-y-z plot layer.";
                return(false);
            }

            if (!(xyzlayer.CoordinateSystem is CS.G3DCartesicCoordinateSystem))
            {
                problemDescription = "The first x-y-z plot layer found does not contain a cartesic coordinate system.";
                return(false);
            }

            problemDescription = null;
            return(true);
        }
Пример #2
0
        private void RescaleAllLayers(Altaxo.Graph.Graph3D.GraphDocument doc)
        {
            var layers = TreeNodeExtensions.TakeFromFirstLeavesToHere(doc.RootLayer).OfType <Altaxo.Graph.Graph3D.XYZPlotLayer>();

            foreach (var layer in layers)
            {
                layer.OnUserRescaledAxes();
            }
        }
Пример #3
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));
        }
        private FitFunctionLeafNode SelectFitFunction(IFitFunction func)
        {
            var selNode = (FitFunctionLeafNode)TreeNodeExtensions.AnyBetweenHereAndLeaves(_fitFunctionsRoot, (node) => node is FitFunctionLeafNode dln && dln.FunctionType is DocumentFitFunctionInformation dffi && func.Equals(dffi.FitFunction));

            if (null != selNode)
            {
                selNode.IsExpanded = true;
                selNode.IsSelected = true;
            }

            return(selNode);
        }
Пример #5
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));
        }
Пример #6
0
        //------------------------------------------------------------------------------------------------------------------------
        private static IList <IProjectFile> GetProjectFiles(DocumentManager documentManager, IDeclaredElement declaredElement)
        {
            IList <IProjectFile> results = new List <IProjectFile>();

            foreach (var declaration in declaredElement.GetDeclarations())
            {
                DocumentRange documentRange = declaration.GetNavigationRange();
                if (!documentRange.IsValid())
                {
                    documentRange = TreeNodeExtensions.GetDocumentRange(declaration);
                }

                if (documentRange.IsValid())
                {
                    IProjectFile projectFile = documentManager.TryGetProjectFile(documentRange.Document);
                    if (projectFile != null)
                    {
                        results.Add(projectFile);
                    }
                }
            }
            return(results);
        }
Пример #7
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));
        }