Exemple #1
0
 /// <summary>Initializes a new instance of the <see cref="GraphViewLayout"/> class.</summary>
 /// <param name="isAutoZoomActive">If set to <c>true</c> auto zoom is active.</param>
 /// <param name="zoomFactor">The zoom factor.</param>
 /// <param name="graphDocument">The graph document.</param>
 /// <param name="viewPortsUpperLeftInRootLayerCoord">Vector from the upper left corner of the graph to the upper left corner of the view port.</param>
 public GraphViewLayout(bool isAutoZoomActive, double zoomFactor, GraphDocument graphDocument, PointD2D viewPortsUpperLeftInRootLayerCoord)
 {
     _isAutoZoomActive = isAutoZoomActive;
     _zoomFactor       = zoomFactor;
     _positionOfViewportsUpperLeftCornerInRootLayerCoordinates = viewPortsUpperLeftInRootLayerCoord;
     _graphDocument = graphDocument;
 }
Exemple #2
0
        /// <summary>
        /// Creates a brand new graph which has an x-y plot layer. The graph is not named, nor is it already part of the project.
        /// </summary>
        /// <param name="propertyContext">The property context. Can be retrieved for instance from the table the plot is initiated or the folder.</param>
        /// <returns>The created graph.</returns>
        private static GraphDocument CreateBuiltinGraph(IReadOnlyPropertyBag propertyContext)
        {
            if (null == propertyContext)
            {
                propertyContext = PropertyExtensions.GetPropertyContextOfProject();
            }

            var graph = new Altaxo.Graph.Gdi.GraphDocument();

            TemplateBase.AddStandardPropertiesToGraph(graph, propertyContext);
            graph.RootLayer.Location.CopyFrom(propertyContext.GetValue(Altaxo.Graph.Gdi.GraphDocument.PropertyKeyDefaultRootLayerSize)); // apply the default location from the property in the path

            var layer = new Altaxo.Graph.Gdi.XYPlotLayer(graph.RootLayer, new Altaxo.Graph.Gdi.CS.G2DPolarCoordinateSystem());

            layer.Scales[0] = new Scales.AngularDegreeScale()
            {
                TickSpacing = new Scales.Ticks.AngularDegreeTickSpacing()
            };

            layer.CreateDefaultAxes(propertyContext);

            layer.AxisStyles[CSLineID.X1].AxisLineStyle.FirstDownMajorTicks = false;
            layer.AxisStyles[CSLineID.X1].AxisLineStyle.FirstDownMinorTicks = false;
            layer.AxisStyles[CSLineID.Y0].AxisLineStyle.FirstUpMajorTicks   = false;
            layer.AxisStyles[CSLineID.Y0].AxisLineStyle.FirstUpMinorTicks   = false;

            graph.RootLayer.Layers.Add(layer);

            return(graph);
        }
Exemple #3
0
        /// <summary>
        /// This function will delete a graph document and close all corresponding views.
        /// </summary>
        /// <param name="graph">The graph document to delete.</param>
        /// <param name="force">If true, the graph document is deleted without safety question,
        /// if false, the user is ask before the graph document is deleted.</param>
        public void DeleteGraphDocument(Altaxo.Graph.Gdi.GraphDocument graph, bool force)
        {
            if (!force &&
                System.Windows.Forms.DialogResult.No == System.Windows.Forms.MessageBox.Show(
                    Current.MainWindow,
                    "Are you sure to remove the graph document and the corresponding views?", "Attention", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning))
            {
                return;
            }

            // close all windows
            List <IViewContent> foundContent = SearchContentForDocument(graph, int.MaxValue);

            foreach (IViewContent content in foundContent)
            {
                content.WorkbenchWindow.CloseWindow(true);
            }

            Current.Project.GraphDocumentCollection.Remove(graph);



            // the following sequence is related to a bug encountered when closing a tabbed window by the program:
            // the active view content is not updated because the dockpanel lost the focus
            // to circumvent this, we focus on a new viewcontent, in this case the first one
            SelectFirstAvailableView();
        }
Exemple #4
0
 /// <summary>
 /// Plots the currently selected data columns of a worksheet.
 /// </summary>
 /// <param name="dg">The worksheet controller where the columns are selected in.</param>
 public static void PlotLinePolar(GUI.WorksheetController dg)
 {
     Altaxo.Graph.Gdi.GraphDocument graph = new Altaxo.Graph.Gdi.GraphDocument();
     Altaxo.Graph.Gdi.XYPlotLayer   layer = new Altaxo.Graph.Gdi.XYPlotLayer(graph.DefaultLayerPosition, graph.DefaultLayerSize, new Altaxo.Graph.Gdi.CS.G2DPolarCoordinateSystem());
     layer.CreateDefaultAxes();
     graph.Layers.Add(layer);
     Current.Project.GraphDocumentCollection.Add(graph);
     IGraphController gc = Plot(dg.DataTable, dg.SelectedDataColumns, graph, PlotStyle_Line, GroupStyle_Color_Line);
 }
Exemple #5
0
        private void RescaleAllLayers(Altaxo.Graph.Gdi.GraphDocument doc)
        {
            var layers = TreeNodeExtensions.TakeFromFirstLeavesToHere(doc.RootLayer).OfType <Altaxo.Graph.Gdi.XYPlotLayer>();

            foreach (var layer in layers)
            {
                layer.OnUserRescaledAxes();
            }
        }
Exemple #6
0
        /// <summary>
        /// Initializes the values associated with the graph before resizing.
        /// </summary>
        /// <param name="doc">The document.</param>
        public void InitializeOldValues(Altaxo.Graph.Gdi.GraphDocument doc)
        {
            OldRootLayerSize = doc.RootLayer.Size;
            var oldFont = Altaxo.Graph.Gdi.GraphDocument.GetDefaultFont(doc.GetPropertyContext());

            OldStandardFontFamily = oldFont.FontFamilyName;
            OldStandardFontSize   = oldFont.Size;
            OldLineThickness      = Altaxo.Graph.Gdi.GraphDocument.GetDefaultPenWidth(doc.GetPropertyContext());
            OldMajorTickLength    = Altaxo.Graph.Gdi.GraphDocument.GetDefaultMajorTickLength(doc.GetPropertyContext());
        }
Exemple #7
0
        /// <summary>
        /// Plots selected data columns of a table.
        /// </summary>
        /// <param name="table">The source table.</param>
        /// <param name="selectedColumns">The data columns of the table that should be plotted.</param>
        /// <param name="templatePlotStyle">The plot style which is the template for all plot items.</param>
        /// <param name="groupStyles">The group styles for the newly built plot item collection.</param>
        public static IGraphController Plot(DataTable table,
                                            IAscendingIntegerCollection selectedColumns,
                                            G2DPlotStyleCollection templatePlotStyle,
                                            PlotGroupStyleCollection groupStyles)
        {
            Altaxo.Graph.Gdi.GraphDocument graph = new Altaxo.Graph.Gdi.GraphDocument();
            Altaxo.Graph.Gdi.XYPlotLayer   layer = new Altaxo.Graph.Gdi.XYPlotLayer(graph.DefaultLayerPosition, graph.DefaultLayerSize);
            layer.CreateDefaultAxes();
            graph.Layers.Add(layer);
            Current.Project.GraphDocumentCollection.Add(graph);

            return(Plot(table, selectedColumns, graph, templatePlotStyle, groupStyles));
        }
Exemple #8
0
        /// <summary>
        /// Shows the resize graph dialog and if Ok, the graph is resized afterwards.
        /// </summary>
        /// <param name="doc">The graph document to resize.</param>
        public static void ShowResizeGraphDialog(Altaxo.Graph.Gdi.GraphDocument doc)
        {
            var resizeOptions = null == _lastUsedInstance ? new ResizeGraphOptions() : (ResizeGraphOptions)_lastUsedInstance.Clone();

            resizeOptions.InitializeOldValues(doc);

            var controller = (IMVCAController)Current.Gui.GetControllerAndControl(new object[] { resizeOptions }, typeof(IMVCANController));

            if (Current.Gui.ShowDialog(controller, "Resize graph"))
            {
                resizeOptions = (ResizeGraphOptions)controller.ModelObject;
                resizeOptions.ResizeGraph(doc);
                _lastUsedInstance = resizeOptions;
            }
        }
Exemple #9
0
        /// <summary>
        /// Opens a view that shows the graph <code>graph</code>. If no view for the graph can be found,
        /// a new default view is created.
        /// </summary>
        /// <param name="graph">The graph for which a view must be found.</param>
        /// <returns>The view content for the provided graph.</returns>
        public object OpenOrCreateGraphForGraphDocument(Altaxo.Graph.Gdi.GraphDocument graph)
        {
            // if a content exist that show that graph, activate that content
            List <IViewContent> foundContent = SearchContentForDocument(graph, 1);

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


            // otherwise create a new graph view
            return(CreateNewGraph(graph));
        }
Exemple #10
0
        /// <summary>
        /// Creates a new view content for a graph document.
        /// </summary>
        /// <param name="graph">The graph document.</param>
        /// <returns>The view content for the provided graph document.</returns>
        public Altaxo.Graph.GUI.IGraphController CreateNewGraph(Altaxo.Graph.Gdi.GraphDocument graph)
        {
            if (graph == null)
            {
                graph = this.CurrentOpenProject.CreateNewGraphDocument();
            }

            Altaxo.Gui.SharpDevelop.SDGraphViewContent ctrl = new Altaxo.Gui.SharpDevelop.SDGraphViewContent(graph);

            Altaxo.Graph.GUI.GraphView view = new Altaxo.Graph.GUI.GraphView();

            ctrl.Controller.View = view;

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

            return(ctrl.Controller);
        }
		/// <summary>
		/// Creates a brand new graph which has an x-y plot layer. The graph is not named, nor is it already part of the project.
		/// </summary>
		/// <param name="propertyContext">The property context. Can be retrieved for instance from the table the plot is initiated or the folder.</param>
		/// <returns>The created graph.</returns>
		private static GraphDocument CreateBuiltinGraph(IReadOnlyPropertyBag propertyContext)
		{
			if (null == propertyContext)
				propertyContext = PropertyExtensions.GetPropertyContextOfProject();

			Altaxo.Graph.Gdi.GraphDocument graph = new Altaxo.Graph.Gdi.GraphDocument();
			TemplateBase.AddStandardPropertiesToGraph(graph, propertyContext);
			graph.RootLayer.Location.CopyFrom(propertyContext.GetValue(Altaxo.Graph.Gdi.GraphDocument.PropertyKeyDefaultRootLayerSize));  // apply the default location from the property in the path

			Altaxo.Graph.Gdi.XYPlotLayer layer = new Altaxo.Graph.Gdi.XYPlotLayer(graph.RootLayer, new Altaxo.Graph.Gdi.CS.G2DPolarCoordinateSystem());
			layer.Scales[0] = new Scales.AngularDegreeScale() { TickSpacing = new Scales.Ticks.AngularDegreeTickSpacing() };

			layer.CreateDefaultAxes(propertyContext);

			layer.AxisStyles[CSLineID.X1].AxisLineStyle.FirstDownMajorTicks = false;
			layer.AxisStyles[CSLineID.X1].AxisLineStyle.FirstDownMinorTicks = false;
			layer.AxisStyles[CSLineID.Y0].AxisLineStyle.FirstUpMajorTicks = false;
			layer.AxisStyles[CSLineID.Y0].AxisLineStyle.FirstUpMinorTicks = false;

			graph.RootLayer.Layers.Add(layer);

			return graph;
		}
Exemple #12
0
        /// <summary>
        /// Resizes a graph according to the options stored in this instance.
        /// </summary>
        /// <param name="doc">The graph to resize..</param>
        public void ResizeGraph(Altaxo.Graph.Gdi.GraphDocument doc)
        {
            var context = doc.GetPropertyHierarchy();

            var oldFont = context.GetValue(Altaxo.Graph.Gdi.GraphDocument.PropertyKeyDefaultFont);

            // calculate new line thickness
            var oldLineThickness   = Altaxo.Graph.Gdi.GraphDocument.GetDefaultPenWidth(doc.GetPropertyHierarchy());
            var oldMajorTickLength = Altaxo.Graph.Gdi.GraphDocument.GetDefaultMajorTickLength(doc.GetPropertyHierarchy());

            var newFont = oldFont;

            if (!string.IsNullOrEmpty(NewStandardFontFamily))
            {
                newFont = newFont.WithFamily(NewStandardFontFamily);
            }
            if (NewStandardFontSize.HasValue)
            {
                newFont = newFont.WithSize(NewStandardFontSize.Value);
            }

            using (var token = doc.SuspendGetToken())
            {
                if (newFont != oldFont)
                {
                    doc.PropertyBagNotNull.SetValue(Altaxo.Graph.Gdi.GraphDocument.PropertyKeyDefaultFont, newFont);
                }

                // calculate new line thickness
                var newLineThickness = Altaxo.Graph.Gdi.GraphDocument.GetDefaultPenWidth(doc.GetPropertyHierarchy());
                if (UserDefinedLineThickness.HasValue)
                {
                    newLineThickness = UserDefinedLineThickness.Value;
                }
                // new major tick length
                var newMajorTickLength = Altaxo.Graph.Gdi.GraphDocument.GetDefaultMajorTickLength(doc.GetPropertyHierarchy());
                if (UserDefinedMajorTickLength.HasValue)
                {
                    newMajorTickLength = UserDefinedMajorTickLength.Value;
                }

                if (NewRootLayerSize.HasValue)
                {
                    doc.RootLayer.Size = NewRootLayerSize.Value;
                }

                var alreadyProcessedItems = new HashSet <object>(EqualityComparer <object> .Default); // because Gdi graphs have objects in the normal hierarchy as well as cached objects in the GraphObjects collection, we have to keep track of already processed items

                foreach (var node in doc.EnumerateFromHereToLeaves().OfType <Altaxo.Graph.IRoutedPropertyReceiver>())
                {
                    if (alreadyProcessedItems.Contains(node))
                    {
                        continue; // already processed
                    }
                    else
                    {
                        alreadyProcessedItems.Add(node);
                    }

                    // Font family
                    if (!string.IsNullOrEmpty(NewStandardFontFamily))
                    {
                        if (OptionResetAllFontsToStandardFont) // change all fonts to new font family
                        {
                            foreach (var prop in node.GetRoutedProperties("FontFamily"))
                            {
                                prop.PropertySetter(NewStandardFontFamily);
                            }
                        }
                        else // change FontFamily only if font was old standard font
                        {
                            foreach (var prop in node.GetRoutedProperties("FontFamily"))
                            {
                                if (!string.IsNullOrEmpty((string)prop.PropertyValue) && ((string)prop.PropertyValue) == OldStandardFontFamily)
                                {
                                    prop.PropertySetter(NewStandardFontFamily);
                                }
                            }
                        }
                    }

                    // Font size
                    if (NewStandardFontSize.HasValue && ActionForFontSize != ScalarSizeActions.None)
                    {
                        if (ActionForFontSize == ScalarSizeActions.ResetAllToStandardValue)
                        {
                            foreach (var prop in node.GetRoutedProperties("FontSize"))
                            {
                                prop.PropertySetter(NewStandardFontSize.Value);
                            }
                        }
                        else if (ActionForFontSize == ScalarSizeActions.RescaleByRatioNewToOldValue)
                        {
                            foreach (var prop in node.GetRoutedProperties("FontSize"))
                            {
                                if (newFont.Size != oldFont.Size)
                                {
                                    var oldValue = (double)prop.PropertyValue;
                                    var newValue = oldValue * newFont.Size / oldFont.Size;
                                    prop.PropertySetter(newValue);
                                }
                            }
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }

                    // Symbol size (the value to scale symbol size is used from the font size)
                    if (NewStandardFontSize.HasValue && ActionForSymbolSize != ScalarSizeActions.None)
                    {
                        if (ActionForSymbolSize == ScalarSizeActions.ResetAllToStandardValue)
                        {
                            foreach (var prop in node.GetRoutedProperties("SymbolSize"))
                            {
                                prop.PropertySetter(NewStandardFontSize.Value);
                            }
                        }
                        else if (ActionForSymbolSize == ScalarSizeActions.RescaleByRatioNewToOldValue)
                        {
                            foreach (var prop in node.GetRoutedProperties("SymbolSize"))
                            {
                                if (newFont.Size != oldFont.Size)
                                {
                                    var oldValue = (double)prop.PropertyValue;
                                    var newValue = oldValue * newFont.Size / oldFont.Size;
                                    prop.PropertySetter(newValue);
                                }
                            }
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }

                    // Line thickness

                    if (newLineThickness != oldLineThickness && ActionForLineThickness != ScalarSizeActions.None)
                    {
                        if (ActionForLineThickness == ScalarSizeActions.ResetAllToStandardValue)
                        {
                            foreach (var prop in node.GetRoutedProperties("StrokeWidth"))
                            {
                                prop.PropertySetter(newLineThickness);
                            }
                        }
                        else if (ActionForLineThickness == ScalarSizeActions.RescaleByRatioNewToOldValue)
                        {
                            if (newLineThickness != oldLineThickness)
                            {
                                foreach (var prop in node.GetRoutedProperties("StrokeWidth"))
                                {
                                    var oldValue = (double)prop.PropertyValue;
                                    var newValue = oldValue * newLineThickness / oldLineThickness;
                                    prop.PropertySetter(newValue);
                                }
                            }
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }

                    // Major tick length
                    if (newMajorTickLength != oldMajorTickLength && ActionForTickLength != ScalarSizeActions.None)
                    {
                        if (ActionForTickLength == ScalarSizeActions.ResetAllToStandardValue)
                        {
                            foreach (var prop in node.GetRoutedProperties("MajorTickLength"))
                            {
                                prop.PropertySetter(newMajorTickLength);
                            }
                        }
                        else if (ActionForTickLength == ScalarSizeActions.RescaleByRatioNewToOldValue)
                        {
                            if (newMajorTickLength != oldMajorTickLength)
                            {
                                foreach (var prop in node.GetRoutedProperties("MajorTickLength"))
                                {
                                    var oldValue = (double)prop.PropertyValue;
                                    var newValue = oldValue * newMajorTickLength / oldMajorTickLength;
                                    prop.PropertySetter(newValue);
                                }
                            }
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                } // foreach node
            }     // Resume
        }
Exemple #13
0
        public static void OpenWorksheetOrGraph(string filename)
        {
            object deserObject;

            Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info;
            using (System.IO.Stream myStream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
            {
                info = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo();
                info.BeginReading(myStream);
                deserObject = info.GetValue("Table", null);
                info.EndReading();
                myStream.Close();
            }

            // if it is a table, add it to the DataTableCollection
            if (deserObject is Altaxo.Data.DataTable)
            {
                Altaxo.Data.DataTable table = deserObject as Altaxo.Data.DataTable;
                if (table.Name == null || table.Name == string.Empty)
                {
                    table.Name = Current.Project.DataTableCollection.FindNewTableName();
                }
                else if (Current.Project.DataTableCollection.ContainsTable(table.Name))
                {
                    table.Name = Current.Project.DataTableCollection.FindNewTableName(table.Name);
                }

                Current.Project.DataTableCollection.Add(table);
                info.AnnounceDeserializationEnd(Current.Project); // fire the event to resolve path references

                Current.ProjectService.CreateNewWorksheet(table);
            }
            // if it is a table, add it to the DataTableCollection
            else if (deserObject is Altaxo.Worksheet.TablePlusLayout)
            {
                Altaxo.Worksheet.TablePlusLayout tableAndLayout = deserObject as Altaxo.Worksheet.TablePlusLayout;
                Altaxo.Data.DataTable            table          = tableAndLayout.Table;
                if (table.Name == null || table.Name == string.Empty)
                {
                    table.Name = Current.Project.DataTableCollection.FindNewTableName();
                }
                else if (Current.Project.DataTableCollection.ContainsTable(table.Name))
                {
                    table.Name = Current.Project.DataTableCollection.FindNewTableName(table.Name);
                }
                Current.Project.DataTableCollection.Add(table);

                if (tableAndLayout.Layout != null)
                {
                    Current.Project.TableLayouts.Add(tableAndLayout.Layout);
                }

                info.AnnounceDeserializationEnd(Current.Project); // fire the event to resolve path references

                tableAndLayout.Layout.DataTable = table;          // this is the table for the layout now

                Current.ProjectService.CreateNewWorksheet(table, tableAndLayout.Layout);
            }
            else if (deserObject is Altaxo.Graph.Gdi.GraphDocument)
            {
                Altaxo.Graph.Gdi.GraphDocument graph = deserObject as Altaxo.Graph.Gdi.GraphDocument;
                if (graph.Name == null || graph.Name == string.Empty)
                {
                    graph.Name = Current.Project.GraphDocumentCollection.FindNewName();
                }
                else if (Current.Project.GraphDocumentCollection.Contains(graph.Name))
                {
                    graph.Name = Current.Project.GraphDocumentCollection.FindNewName(graph.Name);
                }

                Current.Project.GraphDocumentCollection.Add(graph);
                info.AnnounceDeserializationEnd(Current.Project); // fire the event to resolve path references in the graph

                Current.ProjectService.CreateNewGraph(graph);
            }
        }