public LayoutControl() { InitializeComponent(); GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings(); oGeneralUserSettings.NotUseWorkbookSettings(); LayoutUserSettings oLayoutUserSettings = new LayoutUserSettings(); oLayoutUserSettings.NotUseWorkbookSettings(); LayoutType eInitialLayout = oLayoutUserSettings.Layout; // LayoutType eInitialLayout = LayoutType.FruchtermanReingold; // Instantiate an object that populates the tssbLayout // ToolStripSplitButton and handles its LayoutChanged event. m_oLayoutManagerForToolStripSplitButton = new LayoutManagerForToolStripSplitButton(); m_oLayoutManagerForToolStripSplitButton.AddItems(this.tssbLayout); m_oLayoutManagerForToolStripSplitButton.Layout = eInitialLayout; m_oLayoutManagerForToolStripSplitButton.LayoutChanged += new EventHandler( this.LayoutManagerForToolStripSplitButton_LayoutChanged); CreateNodeXLControl(); CreateGraphZoomAndScaleControl(); // ApplyGeneralUserSettings(oGeneralUserSettings); ApplyLayoutUserSettings(oLayoutUserSettings); AssertValid(); }
//************************************************************************* // 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); cbxBoxLayoutAlgorithm.PopulateWithEnumValues( typeof(BoxLayoutAlgorithm), true); cbxIntergroupEdgeStyle.PopulateWithEnumValues( typeof(IntergroupEdgeStyle), true); DoDataExchange(false); AssertValid(); }
CreateLayout ( LayoutUserSettings oLayoutUserSettings ) { Debug.Assert(oLayoutUserSettings != null); AssertValid(); LayoutManager oLayoutManager = new LayoutManager(); oLayoutManager.Layout = oLayoutUserSettings.Layout; ILayout oLayout = oLayoutManager.CreateLayout(); oLayoutUserSettings.TransferToLayout(oLayout); // Don't use groups or binning, even if the user is using one of those // in the NodeXLControl. oLayout.LayoutStyle = LayoutStyle.Normal; return(oLayout); }
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); oCreateSubgraphImagesAsyncArgs.Layout.Margin = Margin; // 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); }
//************************************************************************* // 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(); InitializeSplashScreen(); m_oThisWorkbook = thisWorkbook; 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; m_oReadabilityMetricsDialog = null; GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings(); LayoutUserSettings oLayoutUserSettings = new LayoutUserSettings(); LayoutType eInitialLayout = oLayoutUserSettings.Layout; // Instantiate an object that populates the tssbLayout // ToolStripSplitButton and handles its LayoutChanged event. m_oLayoutManagerForToolStripSplitButton = new LayoutManagerForToolStripSplitButton(); m_oLayoutManagerForToolStripSplitButton.AddItems(this.tssbLayout); 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.LayoutManagerForToolStripSplitButton_LayoutChanged); m_oLayoutManagerForContextMenu.LayoutChanged += new EventHandler(this.LayoutManagerForContextMenu_LayoutChanged); // The context menu for groups should be enabled only if the template // supports groups. MenuUtil.EnableToolStripMenuItems( m_iTemplateVersion > GroupManager.MinimumTemplateVersionForGroups, msiContextGroups); thisWorkbook.VisualAttributeSetInWorkbook += new EventHandler(ThisWorkbook_VisualAttributeSetInWorkbook); thisWorkbook.WorksheetContextMenuManager.RequestVertexCommandEnable += new RequestVertexCommandEnableEventHandler( WorksheetContextMenuManager_RequestVertexCommandEnable); thisWorkbook.WorksheetContextMenuManager.RequestEdgeCommandEnable += new RequestEdgeCommandEnableEventHandler( WorksheetContextMenuManager_RequestEdgeCommandEnable); m_oRibbon.Layout = eInitialLayout; CreateNodeXLControl(); CreateGraphZoomAndScaleControl(); ApplyGeneralUserSettings(oGeneralUserSettings); ApplyLayoutUserSettings(oLayoutUserSettings); // Don't show the legend now. If it is supposed to be shown, the // Ribbon, which is responsible for maintaining the visibility of the // legend, will send a NoParamCommand.ShowGraphLegend command to the // TaskPane later. this.ShowGraphLegend = false; UpdateAutoFillResultsLegend(oPerWorkbookSettings); UpdateDynamicFiltersLegend(); UpdateAxes(oPerWorkbookSettings); CommandDispatcher.CommandSent += new RunCommandEventHandler(this.CommandDispatcher_CommandSent); AssertValid(); }
OnLayoutChanged ( LayoutType eLayout ) { AssertValid(); if (m_bHandlingLayoutChanged) { // Prevent an endless loop when the layout managers are // synchronized. return; } m_bHandlingLayoutChanged = true; // Synchronize the layout managers. m_oRibbon.Layout = m_oLayoutManagerForToolStripSplitButton.Layout = m_oLayoutManagerForContextMenu.Layout = eLayout; // Save and apply the new layout. LayoutUserSettings oLayoutUserSettings = new LayoutUserSettings(); oLayoutUserSettings.Layout = eLayout; 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; }
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. ILayout oLayout = m_oLayoutManagerForToolStripSplitButton.CreateLayout(); oLayoutUserSettings.TransferToLayout(oLayout); oNodeXLControl.Layout = oLayout; }
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(); } }
OnLayoutChanged ( LayoutType eLayout ) { AssertValid(); if (m_bHandlingLayoutChanged) { // Prevent an endless loop when the layout managers are // synchronized. return; } m_bHandlingLayoutChanged = true; // Save and apply the new layout. LayoutUserSettings oLayoutUserSettings = new LayoutUserSettings(); oLayoutUserSettings.NotUseWorkbookSettings(); oLayoutUserSettings.Layout = eLayout; 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. m_bHandlingLayoutChanged = false; }
protected void ShowGraph(Boolean bLayOutGraph) { AssertValid(); if (m_oNodeXLControl.IsLayingOutGraph) { return; } GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings(); oGeneralUserSettings.NotUseWorkbookSettings(); LayoutUserSettings oLayoutUserSettings = new LayoutUserSettings(); oLayoutUserSettings.NotUseWorkbookSettings(); ApplyGeneralUserSettings(oGeneralUserSettings); ApplyLayoutUserSettings(oLayoutUserSettings); EnableGraphControls(false); try { IGraphAdapter oGraphAdapter = new SimpleGraphAdapter(); m_oNodeXLControl.Graph = oGraphAdapter.LoadGraphFromFile( "..\\..\\SampleGraph.txt"); //IGraph oGraph = oWorkbookReader.ReadWorkbook( // m_oWorkbook, oReadWorkbookContext); // Load the NodeXLControl with the resulting graph. //m_oNodeXLControl.Graph = oGraph; // Collapse any groups that are supposed to be collapsed. //CollapseOrExpandGroups(GetGroupNamesToCollapse(oGraph), true, // false); // Enable tooltips in case tooltips were specified in the workbook. m_oNodeXLControl.ShowVertexToolTips = true; // If the dynamic filter dialog is open, read the dynamic filter // columns it filled in. m_oNodeXLControl.DrawGraph(bLayOutGraph); } catch (Exception oException) { // If exceptions aren't caught here, Excel consumes them without // indicating that anything is wrong. This can result in the graph // controls remaining disabled, among other problems. ErrorUtil.OnException(oException); } finally { EnableGraphControls(true); } // Change the button text to indicate that if any of the buttons is // clicked again, the graph will be read again. tsbShowGraph.Text = "Refresh Graph"; }
ApplyLayoutUserSettings ( LayoutUserSettings oLayoutUserSettings ) { // Debug.Assert(oLayoutUserSettings != null); // AssertValid(); // Either layout manager will work; arbitrarily use one of them to // create a layout. ILayout oLayout = m_oLayoutManagerForToolStripSplitButton.CreateLayout(); oLayoutUserSettings.TransferToLayout(oLayout); m_oNodeXLControl.Layout = oLayout; }
CreateLayout ( LayoutUserSettings oLayoutUserSettings ) { Debug.Assert(oLayoutUserSettings != null); AssertValid(); LayoutManager oLayoutManager = new LayoutManager(); oLayoutManager.Layout = oLayoutUserSettings.Layout; ILayout oLayout = oLayoutManager.CreateLayout(); oLayoutUserSettings.TransferToLayout(oLayout); // Don't use groups or binning, even if the user is using one of those // in the NodeXLControl. oLayout.LayoutStyle = LayoutStyle.Normal; return (oLayout); }
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); oCreateSubgraphImagesAsyncArgs.Layout.Margin = Margin; // 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); }