//************************************************************************* // Constructor: LayoutUserSettingsDialog() // /// <overloads> /// Initializes a new instance of the <see /// cref="LayoutUserSettingsDialog" /> class. /// </overloads> /// /// <summary> /// Initializes a new instance of the <see /// cref="LayoutUserSettingsDialog" /> class with a LayoutUserSettings /// object. /// </summary> /// /// <param name="layoutUserSettings"> /// The object being edited. /// </param> //************************************************************************* public LayoutUserSettingsDialog( LayoutUserSettings layoutUserSettings ) : this() { Debug.Assert(layoutUserSettings != null); layoutUserSettings.AssertValid(); m_oLayoutUserSettings = layoutUserSettings; // Instantiate an object that saves and retrieves the user settings for // this dialog. Note that the object automatically saves the settings // when the form closes. m_oLayoutUserSettingsDialogUserSettings = new LayoutUserSettingsDialogUserSettings(this); DoDataExchange(false); AssertValid(); }
CreateLayout ( LayoutUserSettings oLayoutUserSettings ) { Debug.Assert(oLayoutUserSettings != null); AssertValid(); LayoutManager oLayoutManager = new LayoutManager(); oLayoutManager.Layout = oLayoutUserSettings.Layout; IAsyncLayout oLayout = oLayoutManager.CreateLayout(); oLayoutUserSettings.TransferToLayout(oLayout); // Don't use binning, even if the user is using binning in the // NodeXLControl. oLayout.UseBinning = false; return(oLayout); }
//************************************************************************* // Constructor: LayoutUserSettingsDialog() // /// <overloads> /// Initializes a new instance of the <see /// cref="LayoutUserSettingsDialog" /> class. /// </overloads> /// /// <summary> /// Initializes a new instance of the <see /// cref="LayoutUserSettingsDialog" /> class with a LayoutUserSettings /// object. /// </summary> /// /// <param name="layoutUserSettings"> /// The object being edited. /// </param> //************************************************************************* public LayoutUserSettingsDialog ( LayoutUserSettings layoutUserSettings ) : this() { Debug.Assert(layoutUserSettings != null); layoutUserSettings.AssertValid(); m_oLayoutUserSettings = layoutUserSettings; // Instantiate an object that saves and retrieves the user settings for // this dialog. Note that the object automatically saves the settings // when the form closes. m_oLayoutUserSettingsDialogUserSettings = new LayoutUserSettingsDialogUserSettings(this); DoDataExchange(false); AssertValid(); }
CreateSubgraphImagesAsync ( IGraph graph, ICollection <IVertex> selectedVertices, Decimal levels, Boolean saveToFolder, String folder, Size imageSizePx, ImageFormat imageFormat, Boolean createThumbnails, Size thumbnailSizePx, Boolean selectedVerticesOnly, Boolean selectVertex, Boolean selectIncidentEdges, GeneralUserSettings generalUserSettings, LayoutUserSettings layoutUserSettings ) { Debug.Assert(graph != null); Debug.Assert(selectedVertices != null); Debug.Assert(levels >= 0); Debug.Assert(Decimal.Remainder(levels, 0.5M) == 0M); Debug.Assert(!saveToFolder || !String.IsNullOrEmpty(folder)); Debug.Assert(!saveToFolder || imageSizePx.Width > 0); Debug.Assert(!saveToFolder || imageSizePx.Height > 0); Debug.Assert(!createThumbnails || thumbnailSizePx.Width > 0); Debug.Assert(!createThumbnails || thumbnailSizePx.Height > 0); Debug.Assert(generalUserSettings != null); AssertValid(); const String MethodName = "CreateSubgraphImagesAsync"; if (this.IsBusy) { throw new InvalidOperationException(String.Format( "{0}:{1}: An asynchronous operation is already in progress." , this.ClassName, MethodName )); } // Wrap the arguments in an object that can be passed to // BackgroundWorker.RunWorkerAsync(). CreateSubgraphImagesAsyncArgs oCreateSubgraphImagesAsyncArgs = new CreateSubgraphImagesAsyncArgs(); oCreateSubgraphImagesAsyncArgs.Graph = graph; oCreateSubgraphImagesAsyncArgs.SelectedVertices = selectedVertices; oCreateSubgraphImagesAsyncArgs.Levels = levels; oCreateSubgraphImagesAsyncArgs.SaveToFolder = saveToFolder; oCreateSubgraphImagesAsyncArgs.Folder = folder; oCreateSubgraphImagesAsyncArgs.ImageSizePx = imageSizePx; oCreateSubgraphImagesAsyncArgs.ImageFormat = imageFormat; oCreateSubgraphImagesAsyncArgs.CreateThumbnails = createThumbnails; oCreateSubgraphImagesAsyncArgs.ThumbnailSizePx = thumbnailSizePx; oCreateSubgraphImagesAsyncArgs.SelectedVerticesOnly = selectedVerticesOnly; oCreateSubgraphImagesAsyncArgs.SelectVertex = selectVertex; oCreateSubgraphImagesAsyncArgs.SelectIncidentEdges = selectIncidentEdges; oCreateSubgraphImagesAsyncArgs.GeneralUserSettings = generalUserSettings; oCreateSubgraphImagesAsyncArgs.Layout = CreateLayout(layoutUserSettings); // Note: the NodeXLVisual object can't be created yet, because it must // be created on the same thread that uses it. It will get created by // BackgroundWorker_DoWork(). oCreateSubgraphImagesAsyncArgs.NodeXLVisual = null; // Create a BackgroundWorker and handle its events. m_oBackgroundWorker = new BackgroundWorker(); m_oBackgroundWorker.WorkerReportsProgress = true; m_oBackgroundWorker.WorkerSupportsCancellation = true; m_oBackgroundWorker.DoWork += new DoWorkEventHandler( BackgroundWorker_DoWork); m_oBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged); m_oBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler( BackgroundWorker_RunWorkerCompleted); m_oBackgroundWorker.RunWorkerAsync(oCreateSubgraphImagesAsyncArgs); }
//************************************************************************* // Method: ApplyLayoutUserSettings() // /// <summary> /// Applies the user's layout settings to the NodeXLControl. /// </summary> /// /// <param name="oLayoutUserSettings"> /// The user's layout settings. /// </param> //************************************************************************* protected void ApplyLayoutUserSettings( LayoutUserSettings oLayoutUserSettings ) { Debug.Assert(oLayoutUserSettings != null); AssertValid(); // Make sure the two layout managers are in sync. Debug.Assert(m_oLayoutManagerForToolStripSplitButton.Layout == m_oLayoutManagerForContextMenu.Layout); // Either layout manager will work; arbitrarily use one of them to // create a layout. IAsyncLayout oLayout = m_oLayoutManagerForToolStripSplitButton.CreateLayout(); oLayoutUserSettings.TransferToLayout(oLayout); oNodeXLControl.Layout = oLayout; }
//************************************************************************* // Method: LayoutManager_LayoutChanged() // /// <summary> /// Handles all LayoutChanged events. /// </summary> /// /// <param name="sender"> /// Standard event argument. /// </param> /// /// <param name="e"> /// Standard event argument. /// </param> //************************************************************************* protected void LayoutManager_LayoutChanged( object sender, EventArgs e ) { AssertValid(); if (m_bHandlingLayoutChanged) { // Prevent an endless loop when the other layout manager's Layout // property is set below. return; } m_bHandlingLayoutChanged = true; // The user just selected a layout via one of the Layout menus. // Synchronize the layout managers that manage those menus. if (sender == m_oLayoutManagerForToolStripSplitButton) { m_oRibbon.Layout = m_oLayoutManagerForContextMenu.Layout = m_oLayoutManagerForToolStripSplitButton.Layout; } else if (sender == m_oLayoutManagerForContextMenu) { m_oRibbon.Layout = m_oLayoutManagerForToolStripSplitButton.Layout = m_oLayoutManagerForContextMenu.Layout; } else if (sender == m_oRibbon) { m_oLayoutManagerForContextMenu.Layout = m_oLayoutManagerForToolStripSplitButton.Layout = m_oRibbon.Layout; } else { Debug.Assert(false); } // Save the new layout. LayoutUserSettings oLayoutUserSettings = new LayoutUserSettings(); oLayoutUserSettings.Layout = m_oLayoutManagerForToolStripSplitButton.Layout; oLayoutUserSettings.Save(); ApplyLayoutUserSettings(oLayoutUserSettings); // If the layout was just changed from Null to something else and the // X and Y columns were autofilled, the X and Y autofill results need // to be cleared. if (!this.LayoutIsNull) { PerWorkbookSettings oPerWorkbookSettings = this.PerWorkbookSettings; AutoFillWorkbookResults oAutoFillWorkbookResults = oPerWorkbookSettings.AutoFillWorkbookResults; if (oAutoFillWorkbookResults.VertexXResults.ColumnAutoFilled) { oAutoFillWorkbookResults.VertexXResults = new AutoFillNumericRangeColumnResults(); oAutoFillWorkbookResults.VertexYResults = new AutoFillNumericRangeColumnResults(); // The PerWorkbookSettings object doesn't persist its settings // to the workbook unless one of its own properties is set. oPerWorkbookSettings.AutoFillWorkbookResults = oAutoFillWorkbookResults; UpdateAxes(oPerWorkbookSettings); } } m_bHandlingLayoutChanged = false; }
//************************************************************************* // Constructor: TaskPane() // /// <summary> /// Initializes a new instance of the <see cref="TaskPane" /> class. /// </summary> /// /// <param name="thisWorkbook"> /// The workbook. /// </param> /// /// <param name="ribbon"> /// The application's ribbon. /// </param> //************************************************************************* public TaskPane( ThisWorkbook thisWorkbook, Ribbon ribbon ) { Debug.Assert(thisWorkbook != null); Debug.Assert(ribbon != null); InitializeComponent(); m_oWorkbook = thisWorkbook.InnerObject; m_oRibbon = ribbon; // The WpfImageUtil uses the screen DPI in its image handling. Graphics oGraphics = this.CreateGraphics(); WpfImageUtil.ScreenDpi = oGraphics.DpiX; oGraphics.Dispose(); // Get the template version from the per-workbook settings. PerWorkbookSettings oPerWorkbookSettings = this.PerWorkbookSettings; m_iTemplateVersion = oPerWorkbookSettings.TemplateVersion; m_bHandlingLayoutChanged = false; m_iEnableGraphControlsCount = 0; m_oEdgeRowIDDictionary = null; m_oVertexRowIDDictionary = null; m_oSaveGraphImageFileDialog = null; m_oDynamicFilterDialog = null; GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings(); LayoutUserSettings oLayoutUserSettings = new LayoutUserSettings(); LayoutType eInitialLayout = oLayoutUserSettings.Layout; // Instantiate an object that populates the sbLayout // ToolStripSplitButton and handles its LayoutChanged event. m_oLayoutManagerForToolStripSplitButton = new LayoutManagerForToolStripSplitButton(); m_oLayoutManagerForToolStripSplitButton.AddItems(this.sbLayout); m_oLayoutManagerForToolStripSplitButton.Layout = eInitialLayout; // Instantiate an object that populates the msiContextLayout // context menu and handles the Clicked events on the child menu items. m_oLayoutManagerForContextMenu = new LayoutManagerForMenu(); m_oLayoutManagerForContextMenu.AddMenuItems(this.msiContextLayout); m_oLayoutManagerForContextMenu.Layout = eInitialLayout; m_oLayoutManagerForToolStripSplitButton.LayoutChanged += new EventHandler(this.LayoutManager_LayoutChanged); m_oLayoutManagerForContextMenu.LayoutChanged += new EventHandler(this.LayoutManager_LayoutChanged); thisWorkbook.VisualAttributeSetInWorkbook += new EventHandler(ThisWorkbook_VisualAttributeSetInWorkbook); thisWorkbook.CollapseOrExpandGroups += new CollapseOrExpandGroupsEventHandler( ThisWorkbook_CollapseOrExpandGroups); thisWorkbook.WorksheetContextMenuManager.RequestVertexCommandEnable += new RequestVertexCommandEnableEventHandler( WorksheetContextMenuManager_RequestVertexCommandEnable); thisWorkbook.WorksheetContextMenuManager.RequestEdgeCommandEnable += new RequestEdgeCommandEnableEventHandler( WorksheetContextMenuManager_RequestEdgeCommandEnable); thisWorkbook.WorksheetContextMenuManager.RunVertexCommand += new RunVertexCommandEventHandler( WorksheetContextMenuManager_RunVertexCommand); thisWorkbook.WorksheetContextMenuManager.RunEdgeCommand += new RunEdgeCommandEventHandler( WorksheetContextMenuManager_RunEdgeCommand); // There is no Closing event on the TaskPane and no parent form whose // Closing event can be handled. Instead, using the Shutdown event on // the workbook to perform closing tasks. thisWorkbook.Shutdown += new EventHandler(ThisWorkbook_Shutdown); m_oRibbon.Layout = eInitialLayout; m_oRibbon.RibbonControlsChanged += new RibbonControlsChangedEventHandler( Ribbon_RibbonControlsChanged); m_oRibbon.RunRibbonCommand += new RunRibbonCommandEventHandler( Ribbon_RunRibbonCommand); CreateNodeXLControl(oGeneralUserSettings); CreateGraphZoomAndScaleControl(); oNodeXLControl.GraphScale = ( new GraphZoomAndScaleUserSettings() ).GraphScale; ApplyGeneralUserSettings(oGeneralUserSettings); ApplyLayoutUserSettings(oLayoutUserSettings); this.ShowGraphLegend = m_oRibbon.ShowGraphLegend; UpdateAutoFillResultsLegend(oPerWorkbookSettings); UpdateDynamicFiltersLegend(); UpdateAxes(oPerWorkbookSettings); AssertValid(); }
//************************************************************************* // Method: EditLayoutUserSettings() // /// <summary> /// Shows the dialog that lets the user edit his layout settings. /// </summary> //************************************************************************* protected void EditLayoutUserSettings() { AssertValid(); if (oNodeXLControl.IsLayingOutGraph) { return; } LayoutUserSettings oLayoutUserSettings = new LayoutUserSettings(); LayoutUserSettingsDialog oLayoutUserSettingsDialog = new LayoutUserSettingsDialog(oLayoutUserSettings); if (oLayoutUserSettingsDialog.ShowDialog() == DialogResult.OK) { oLayoutUserSettings.Save(); ApplyLayoutUserSettings(oLayoutUserSettings); oNodeXLControl.DrawGraph(); } }
//************************************************************************* // Method: CreateLayout() // /// <summary> /// Creates a layout to use when laying out the subgraphs. /// </summary> /// /// <param name="oLayoutUserSettings"> /// User settings for layouts. /// </param> /// /// <returns> /// The layout to use. /// </returns> //************************************************************************* protected IAsyncLayout CreateLayout( LayoutUserSettings oLayoutUserSettings ) { Debug.Assert(oLayoutUserSettings != null); AssertValid(); LayoutManager oLayoutManager = new LayoutManager(); oLayoutManager.Layout = oLayoutUserSettings.Layout; IAsyncLayout oLayout = oLayoutManager.CreateLayout(); oLayoutUserSettings.TransferToLayout(oLayout); // Don't use binning, even if the user is using binning in the // NodeXLControl. oLayout.UseBinning = false; return (oLayout); }
//************************************************************************* // Method: CreateSubgraphImagesAsync() // /// <summary> /// Asynchronously creates images of a subgraph for each of a graph's /// vertices and saves the images to disk. /// </summary> /// /// <param name="graph"> /// The graph to use. /// </param> /// /// <param name="selectedVertices"> /// Collection of the vertices in <paramref name="graph" /> that were /// selected by the user in the workbook from which the graph was created. /// Can be empty but not null. /// </param> /// /// <param name="levels"> /// The number of levels of adjacent vertices to include in each subgraph. /// Must be a multiple of 0.5. If 0, a subgraph includes just the vertex; /// if 1, it includes the vertex and its adjacent vertices; if 2, it /// includes the vertex, its adjacent vertices, and their adjacent /// vertices; and so on. The difference between N.5 and N.0 is that N.5 /// includes any edges connecting the outermost vertices to each other, /// whereas N.0 does not. 1.5, for example, includes any edges that /// connect the vertex's adjacent vertices to each other, whereas 1.0 /// includes only those edges that connect the adjacent vertices to the /// vertex. /// </param> /// /// <param name="saveToFolder"> /// true to save subgraph images to a folder. /// </param> /// /// <param name="folder"> /// The folder to save subgraph images to. Used only if <paramref /// name="saveToFolder" /> is true. /// </param> /// /// <param name="imageSizePx"> /// The size of each subgraph image saved to a folder, in pixels. Used /// only if <paramref name="saveToFolder" /> is true. /// </param> /// /// <param name="imageFormat"> /// The format of each subgraph image saved to a folder. Used only if /// <paramref name="saveToFolder" /> is true. /// </param> /// /// <param name="createThumbnails"> /// true to save thumbnail images to a temporary folder. /// </param> /// /// <param name="thumbnailSizePx"> /// The size of each thumbnail image, in pixels. Used only if <paramref /// name="createThumbnails" /> is true. /// </param> /// /// <param name="selectedVerticesOnly"> /// true to create subgraph images for the vertices in <paramref /// name="selectedVertices" /> only, false to create them for all images. /// </param> /// /// <param name="selectVertex"> /// true to select the vertex around which each subgraph is created. /// </param> /// /// <param name="selectIncidentEdges"> /// true to select the incident edges of the vertex around which each /// subgraph is created. /// </param> /// /// <param name="generalUserSettings"> /// The user's general user settings. /// </param> /// /// <param name="layoutUserSettings"> /// The user's layout user settings. /// </param> /// /// <remarks> /// When image creation completes, the <see /// cref="ImageCreationCompleted" /> event fires. /// /// <para> /// If thumbnail images are created, they are saved to a temporary folder. /// Information about the thumbnail images can be found in the <see /// cref="TemporaryImages" /> object stored in the <see /// cref="RunWorkerCompletedEventArgs.Result" /> propery of the <see /// cref="RunWorkerCompletedEventArgs" /> returned by the <see /// cref="ImageCreationCompleted" /> event. /// </para> /// /// <para> /// To cancel the analysis, call <see cref="CancelAsync" />. /// </para> /// /// </remarks> //************************************************************************* public void CreateSubgraphImagesAsync( IGraph graph, ICollection<IVertex> selectedVertices, Decimal levels, Boolean saveToFolder, String folder, Size imageSizePx, ImageFormat imageFormat, Boolean createThumbnails, Size thumbnailSizePx, Boolean selectedVerticesOnly, Boolean selectVertex, Boolean selectIncidentEdges, GeneralUserSettings generalUserSettings, LayoutUserSettings layoutUserSettings ) { Debug.Assert(graph != null); Debug.Assert(selectedVertices != null); Debug.Assert(levels >= 0); Debug.Assert(Decimal.Remainder(levels, 0.5M) == 0M); Debug.Assert( !saveToFolder || !String.IsNullOrEmpty(folder) ); Debug.Assert( !saveToFolder || imageSizePx.Width > 0); Debug.Assert( !saveToFolder || imageSizePx.Height > 0); Debug.Assert( !createThumbnails || thumbnailSizePx.Width > 0); Debug.Assert( !createThumbnails || thumbnailSizePx.Height > 0); Debug.Assert(generalUserSettings != null); AssertValid(); const String MethodName = "CreateSubgraphImagesAsync"; if (this.IsBusy) { throw new InvalidOperationException( String.Format( "{0}:{1}: An asynchronous operation is already in progress." , this.ClassName, MethodName ) ); } // Wrap the arguments in an object that can be passed to // BackgroundWorker.RunWorkerAsync(). CreateSubgraphImagesAsyncArgs oCreateSubgraphImagesAsyncArgs = new CreateSubgraphImagesAsyncArgs(); oCreateSubgraphImagesAsyncArgs.Graph = graph; oCreateSubgraphImagesAsyncArgs.SelectedVertices = selectedVertices; oCreateSubgraphImagesAsyncArgs.Levels = levels; oCreateSubgraphImagesAsyncArgs.SaveToFolder = saveToFolder; oCreateSubgraphImagesAsyncArgs.Folder = folder; oCreateSubgraphImagesAsyncArgs.ImageSizePx = imageSizePx; oCreateSubgraphImagesAsyncArgs.ImageFormat = imageFormat; oCreateSubgraphImagesAsyncArgs.CreateThumbnails = createThumbnails; oCreateSubgraphImagesAsyncArgs.ThumbnailSizePx = thumbnailSizePx; oCreateSubgraphImagesAsyncArgs.SelectedVerticesOnly = selectedVerticesOnly; oCreateSubgraphImagesAsyncArgs.SelectVertex = selectVertex; oCreateSubgraphImagesAsyncArgs.SelectIncidentEdges = selectIncidentEdges; oCreateSubgraphImagesAsyncArgs.GeneralUserSettings = generalUserSettings; oCreateSubgraphImagesAsyncArgs.Layout = CreateLayout(layoutUserSettings); // Note: the NodeXLVisual object can't be created yet, because it must // be created on the same thread that uses it. It will get created by // BackgroundWorker_DoWork(). oCreateSubgraphImagesAsyncArgs.NodeXLVisual = null; // Create a BackgroundWorker and handle its events. m_oBackgroundWorker = new BackgroundWorker(); m_oBackgroundWorker.WorkerReportsProgress = true; m_oBackgroundWorker.WorkerSupportsCancellation = true; m_oBackgroundWorker.DoWork += new DoWorkEventHandler( BackgroundWorker_DoWork); m_oBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged); m_oBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler( BackgroundWorker_RunWorkerCompleted); m_oBackgroundWorker.RunWorkerAsync(oCreateSubgraphImagesAsyncArgs); }