예제 #1
0
        //*************************************************************************
        //  Constructor: GeneralUserSettingsDialog()
        //
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="GeneralUserSettingsDialog" /> class.
        /// </summary>
        ///
        /// <param name="generalUserSettings">
        /// The object being edited.
        /// </param>
        ///
        /// <param name="workbook">
        /// Workbook containing the graph data.
        /// </param>
        //*************************************************************************

        public GeneralUserSettingsDialog
        (
            GeneralUserSettings generalUserSettings,
            Microsoft.Office.Interop.Excel.Workbook workbook
        )
        {
            Debug.Assert(generalUserSettings != null);
            Debug.Assert(workbook != null);
            generalUserSettings.AssertValid();

            m_oGeneralUserSettings = generalUserSettings;
            m_oWorkbook            = workbook;
            m_oAxisFont            = m_oGeneralUserSettings.AxisFont;
            m_oLabelUserSettings   = m_oGeneralUserSettings.LabelUserSettings;

            // Instantiate an object that saves and retrieves the position of this
            // dialog.  Note that the object automatically saves the settings when
            // the form closes.

            m_oGeneralUserSettingsDialogUserSettings =
                new GeneralUserSettingsDialogUserSettings(this);

            InitializeComponent();

            nudEdgeWidth.Minimum =
                (Decimal)EdgeWidthConverter.MinimumWidthWorkbook;

            nudEdgeWidth.Maximum =
                (Decimal)EdgeWidthConverter.MaximumWidthWorkbook;

            nudSelectedEdgeWidth.Minimum =
                (Decimal)EdgeWidthConverter.MinimumWidthWorkbook;

            nudSelectedEdgeWidth.Maximum =
                (Decimal)EdgeWidthConverter.MaximumWidthWorkbook;

            nudRelativeArrowSize.Minimum =
                (Decimal)EdgeDrawer.MinimumRelativeArrowSize;

            nudRelativeArrowSize.Maximum =
                (Decimal)EdgeDrawer.MaximumRelativeArrowSize;

            nudVertexRadius.Minimum = nudVertexImageSize.Minimum =
                (Decimal)VertexRadiusConverter.MinimumRadiusWorkbook;

            nudVertexRadius.Maximum = nudVertexImageSize.Maximum =
                (Decimal)VertexRadiusConverter.MaximumRadiusWorkbook;

            (new VertexShapeConverter()).PopulateComboBox(cbxVertexShape, false);

            nudVertexAlpha.Minimum = nudEdgeAlpha.Minimum =
                (Decimal)AlphaConverter.MinimumAlphaWorkbook;

            nudVertexAlpha.Maximum = nudEdgeAlpha.Maximum =
                (Decimal)AlphaConverter.MaximumAlphaWorkbook;

            DoDataExchange(false);

            AssertValid();
        }
예제 #2
0
        CreateNodeXLVisual
        (
            GeneralUserSettings oGeneralUserSettings
        )
        {
            Debug.Assert(oGeneralUserSettings != null);
            AssertValid();

            NodeXLVisual oNodeXLVisual = new NodeXLVisual();

            GraphDrawer oGraphDrawer = oNodeXLVisual.GraphDrawer;

            VertexDrawer oVertexDrawer = oGraphDrawer.VertexDrawer;

            EdgeDrawer oEdgeDrawer = oGraphDrawer.EdgeDrawer;

            oGeneralUserSettings.TransferToGraphDrawer(oGraphDrawer);

            // Override some of the user's settings.

            oVertexDrawer.Shape       = VertexShape.Disk;
            oVertexDrawer.Radius      = 2.0;
            oEdgeDrawer.Width         = 1;
            oEdgeDrawer.SelectedWidth = 1;

            return(oNodeXLVisual);
        }
        //*************************************************************************
        //  Constructor: GeneralUserSettingsDialog()
        //
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="GeneralUserSettingsDialog" /> class.
        /// </summary>
        ///
        /// <param name="generalUserSettings">
        /// The object being edited.
        /// </param>
        ///
        /// <param name="workbook">
        /// Workbook containing the graph data.
        /// </param>
        //*************************************************************************
        public GeneralUserSettingsDialog(
            GeneralUserSettings generalUserSettings,
            Microsoft.Office.Interop.Excel.Workbook workbook
            )
        {
            Debug.Assert(generalUserSettings != null);
            Debug.Assert(workbook != null);
            generalUserSettings.AssertValid();

            m_oGeneralUserSettings = generalUserSettings;
            m_oWorkbook = workbook;
            m_oAxisFont = m_oGeneralUserSettings.AxisFont;
            m_oLabelUserSettings = m_oGeneralUserSettings.LabelUserSettings;

            // Instantiate an object that saves and retrieves the position of this
            // dialog.  Note that the object automatically saves the settings when
            // the form closes.

            m_oGeneralUserSettingsDialogUserSettings =
            new GeneralUserSettingsDialogUserSettings(this);

            InitializeComponent();

            nudEdgeWidth.Minimum =
            (Decimal)EdgeWidthConverter.MinimumWidthWorkbook;

            nudEdgeWidth.Maximum =
            (Decimal)EdgeWidthConverter.MaximumWidthWorkbook;

            nudSelectedEdgeWidth.Minimum =
            (Decimal)EdgeWidthConverter.MinimumWidthWorkbook;

            nudSelectedEdgeWidth.Maximum =
            (Decimal)EdgeWidthConverter.MaximumWidthWorkbook;

            nudRelativeArrowSize.Minimum =
            (Decimal)EdgeDrawer.MinimumRelativeArrowSize;

            nudRelativeArrowSize.Maximum =
            (Decimal)EdgeDrawer.MaximumRelativeArrowSize;

            nudVertexRadius.Minimum = nudVertexImageSize.Minimum =
            (Decimal)VertexRadiusConverter.MinimumRadiusWorkbook;

            nudVertexRadius.Maximum = nudVertexImageSize.Maximum =
            (Decimal)VertexRadiusConverter.MaximumRadiusWorkbook;

            ( new VertexShapeConverter() ).PopulateComboBox(cbxVertexShape, false);

            nudVertexAlpha.Minimum = nudEdgeAlpha.Minimum =
            (Decimal)AlphaConverter.MinimumAlphaWorkbook;

            nudVertexAlpha.Maximum = nudEdgeAlpha.Maximum =
            (Decimal)AlphaConverter.MaximumAlphaWorkbook;

            DoDataExchange(false);

            AssertValid();
        }
예제 #4
0
        CreateGraphDrawingContext
        (
            Rectangle oSubgraphRectangle,
            Int32 iMargin,
            GeneralUserSettings oGeneralUserSettings
        )
        {
            Debug.Assert(iMargin >= 0);
            Debug.Assert(oGeneralUserSettings != null);
            AssertValid();

            return(new GraphDrawingContext(
                       WpfGraphicsUtil.RectangleToRect(oSubgraphRectangle), iMargin,
                       WpfGraphicsUtil.ColorToWpfColor(oGeneralUserSettings.BackColor)
                       ));
        }
예제 #5
0
        btnGeneralUserSettings_Click
        (
            object sender,
            EventArgs e
        )
        {
            AssertValid();

            // The GeneralUserSettings are normally edited from the TaskPane, not
            // the Ribbon, so this event handler differs from the others.

            GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings();

            GeneralUserSettingsDialog oGeneralUserSettingsDialog =
                new GeneralUserSettingsDialog(oGeneralUserSettings,
                                              m_oThisWorkbook.InnerObject);

            if (oGeneralUserSettingsDialog.ShowDialog() == DialogResult.OK)
            {
                oGeneralUserSettings.Save();
            }
        }
예제 #6
0
        //*************************************************************************
        //  Method: ThisWorkbook_New()
        //
        /// <summary>
        /// Handles the New event on the workbook.
        /// </summary>
        //*************************************************************************
        private void ThisWorkbook_New()
        {
            AssertValid();

            // Get the graph directedness for new workbooks and store it in the
            // per-workbook settings.

            GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings();

            this.PerWorkbookSettings.GraphDirectedness =
            oGeneralUserSettings.NewWorkbookGraphDirectedness;
        }
예제 #7
0
        //*************************************************************************
        //  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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        //*************************************************************************
        //  Method: EditGeneralUserSettings()
        //
        /// <summary>
        /// Shows the dialog that lets the user edit his general settings.
        /// </summary>
        //*************************************************************************
        protected void EditGeneralUserSettings()
        {
            AssertValid();

            if (oNodeXLControl.IsLayingOutGraph)
            {
            return;
            }

            GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings();

            GeneralUserSettingsDialog oGeneralUserSettingsDialog =
            new GeneralUserSettingsDialog(oGeneralUserSettings, m_oWorkbook);

            if (oGeneralUserSettingsDialog.ShowDialog() == DialogResult.OK)
            {
            oGeneralUserSettings.Save();
            ApplyGeneralUserSettings(oGeneralUserSettings);
            oNodeXLControl.DrawGraph();
            }
        }
예제 #10
0
        //*************************************************************************
        //  Method: CreateNodeXLControl()
        //
        /// <summary>
        /// Creates a NodeXLControl, hooks up its events, and assigns it as the
        /// child of an ElementHost.
        /// </summary>
        ///
        /// <param name="oGeneralUserSettings">
        /// The user's general settings.
        /// </param>
        //*************************************************************************
        protected void CreateNodeXLControl(
            GeneralUserSettings oGeneralUserSettings
            )
        {
            Debug.Assert(oGeneralUserSettings != null);

            // AssertValid();

            // Control hierarchy:
            //
            // 1. ehElementHost contains a NodeXLWithAxesControl.
            //
            // 2. The NodeXLWithAxesControl contains an ExcelTemplateNodeXLControl.
            //
            // 3. The ExcelTemplateNodeXLControl is derived from NodeXLControl.

            oNodeXLControl = new ExcelTemplateNodeXLControl();

            m_oNodeXLWithAxesControl = new NodeXLWithAxesControl(oNodeXLControl);
            m_oNodeXLWithAxesControl.ShowAxes = oGeneralUserSettings.ShowGraphAxes;

            oNodeXLControl.SelectionChanged +=
            new System.EventHandler(this.oNodeXLControl_SelectionChanged);

            oNodeXLControl.VerticesMoved += new VerticesMovedEventHandler(
            this.oNodeXLControl_VerticesMoved);

            oNodeXLControl.GraphMouseUp += new GraphMouseButtonEventHandler(
            this.oNodeXLControl_GraphMouseUp);

            oNodeXLControl.LayingOutGraph += new System.EventHandler(
            this.oNodeXLControl_LayingOutGraph);

            oNodeXLControl.GraphLaidOut += new AsyncCompletedEventHandler(
            this.oNodeXLControl_GraphLaidOut);

            ehNodeXLControlHost.Child = m_oNodeXLWithAxesControl;
        }
예제 #11
0
        //*************************************************************************
        //  Method: ApplyGeneralUserSettings()
        //
        /// <summary>
        /// Applies the user's general settings to the NodeXLControl.
        /// </summary>
        ///
        /// <param name="oGeneralUserSettings">
        /// The user's general settings.
        /// </param>
        //*************************************************************************
        protected void ApplyGeneralUserSettings(
            GeneralUserSettings oGeneralUserSettings
            )
        {
            Debug.Assert(oGeneralUserSettings != null);
            AssertValid();

            oGeneralUserSettings.TransferToNodeXLWithAxesControl(
            m_oNodeXLWithAxesControl);
        }
예제 #12
0
        //*************************************************************************
        //  Method: ReadWorkbook()
        //
        /// <summary>
        /// Transfers data from the workbook to the NodeXLControl and optionally
        /// lays out the graph.
        /// </summary>
        ///
        /// <param name="bLayOutGraph">
        /// true to lay out the graph.
        /// </param>
        //*************************************************************************
        protected void ReadWorkbook(
            Boolean bLayOutGraph
            )
        {
            AssertValid();

            if (oNodeXLControl.IsLayingOutGraph)
            {
            return;
            }

            if (
            !this.NonEmptyWorkbookRead
            && this.LayoutIsNull
            && !ShowLayoutTypeIsNullNotification()
            )
            {
            return;
            }

            // This is in case another open workbook has modified the user
            // settings.

            GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings();
            ApplyGeneralUserSettings(oGeneralUserSettings);
            ApplyLayoutUserSettings( new LayoutUserSettings() );

            ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();

            oReadWorkbookContext.IgnoreVertexLocations = false;
            oReadWorkbookContext.GraphRectangle = this.GraphRectangle;
            oReadWorkbookContext.FillIDColumns = true;
            oReadWorkbookContext.ReadGroups = m_oRibbon.ReadGroups;
            oReadWorkbookContext.ReadVertexLabels = m_oRibbon.ReadVertexLabels;
            oReadWorkbookContext.ReadEdgeLabels = m_oRibbon.ReadEdgeLabels;
            oReadWorkbookContext.ReadVertexImages = true;

            oReadWorkbookContext.DefaultVertexImageSize =
            oGeneralUserSettings.VertexImageSize;

            oReadWorkbookContext.DefaultVertexShape =
            oGeneralUserSettings.VertexShape;

            // Populate the vertex worksheet.  This isn't strictly necessary, but
            // it does enable the vertex worksheet to be updated when the user
            // edits vertex attributes in the NodeXL graph.  (If the vertex
            // worksheet is missing, vertex attributes can still be edited in the
            // graph; the edits just won't get saved in the workbook.)

            oReadWorkbookContext.PopulateVertexWorksheet = true;

            WorkbookReader oWorkbookReader = new WorkbookReader();

            m_oEdgeRowIDDictionary = null;
            m_oVertexRowIDDictionary = null;

            EnableGraphControls(false);

            try
            {
            // Read the workbook into a Graph object.

            IGraph oGraph = oWorkbookReader.ReadWorkbook(
                m_oWorkbook, oReadWorkbookContext);

            // Save the edge and vertex dictionaries that were created by
            // WorkbookReader.

            m_oEdgeRowIDDictionary = oReadWorkbookContext.EdgeRowIDDictionary;

            m_oVertexRowIDDictionary =
                oReadWorkbookContext.VertexRowIDDictionary;

            // Load the NodeXLControl with the resulting graph.

            oNodeXLControl.Graph = oGraph;

            // Collapse any groups that are supposed to be collapsed.

            CollapseOrExpandGroups(GetGroupNamesToCollapse(oGraph), true,
                false);

            // Enable tooltips only if tooltips were specified in the workbook.

            oNodeXLControl.ShowVertexToolTips = oGraph.ContainsKey(
                ReservedMetadataKeys.ToolTipSet);

            // If the dynamic filter dialog is open, read the dynamic filter
            // columns it filled in.

            if (m_oDynamicFilterDialog != null)
            {
                ReadDynamicFilterColumns(false);
                ReadFilteredAlpha(false);
            }

            oNodeXLControl.DrawGraph(bLayOutGraph);

            PerWorkbookSettings oPerWorkbookSettings =
                this.PerWorkbookSettings;

            UpdateAutoFillResultsLegend(oPerWorkbookSettings);
            UpdateDynamicFiltersLegend();
            UpdateAxes(oPerWorkbookSettings);
            }
            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.

            tsbReadWorkbook.Text = msiContextReadWorkbook.Text =
            m_oRibbon.ReadWorkbookButtonText =
            "Refresh Graph";
        }
예제 #13
0
        //*************************************************************************
        //  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();
        }
예제 #14
0
        //*************************************************************************
        //  Method: Ribbon_Close()
        //
        /// <summary>
        /// Handles the Close event on the ribbon.
        /// </summary>
        ///
        /// <param name="sender">
        /// Standard event argument.
        /// </param>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        //*************************************************************************
        private void Ribbon_Close(
            object sender,
            EventArgs e
            )
        {
            AssertValid();

            // Set the general user settings directly controlled by the ribbon.

            GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings();

            oGeneralUserSettings.ClusterAlgorithm = this.ClusterAlgorithm;
            oGeneralUserSettings.ReadGroups = this.ReadGroups;
            oGeneralUserSettings.ReadVertexLabels = this.ReadVertexLabels;
            oGeneralUserSettings.ReadEdgeLabels = this.ReadEdgeLabels;
            oGeneralUserSettings.ShowGraphLegend = this.ShowGraphLegend;
            oGeneralUserSettings.ShowGraphAxes = this.ShowGraphAxes;

            oGeneralUserSettings.ClearTablesBeforeImport =
            this.ClearTablesBeforeImport;

            oGeneralUserSettings.Save();
        }
예제 #15
0
        //*************************************************************************
        //  Constructor: Ribbon()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="Ribbon" /> class.
        /// </summary>
        //*************************************************************************
        public Ribbon()
        {
            InitializeComponent();

            // Populate the rddLayout RibbonDropDown.

            m_oLayoutManagerForRibbonDropDown =
            new LayoutManagerForRibbonDropDown();

            m_oLayoutManagerForRibbonDropDown.AddRibbonDropDownItems(
            this.rddLayout);

            m_oLayoutManagerForRibbonDropDown.LayoutChanged += new
            EventHandler(this.m_oLayoutManagerForRibbonDropDown_LayoutChanged);

            // Read the general user settings directly controlled by the ribbon.

            GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings();

            this.ClusterAlgorithm = oGeneralUserSettings.ClusterAlgorithm;
            this.ReadGroups = oGeneralUserSettings.ReadGroups;
            this.ReadVertexLabels = oGeneralUserSettings.ReadVertexLabels;
            this.ReadEdgeLabels = oGeneralUserSettings.ReadEdgeLabels;
            this.ShowGraphLegend = oGeneralUserSettings.ShowGraphLegend;
            this.ShowGraphAxes = oGeneralUserSettings.ShowGraphAxes;

            this.ClearTablesBeforeImport =
            oGeneralUserSettings.ClearTablesBeforeImport;

            AssertValid();
        }
예제 #16
0
        //*************************************************************************
        //  Method: btnGeneralUserSettings_Click()
        //
        /// <summary>
        /// Handles the Click event on the btnGeneralUserSettings button.
        /// </summary>
        ///
        /// <param name="sender">
        /// Standard event argument.
        /// </param>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        //*************************************************************************
        private void btnGeneralUserSettings_Click(
            object sender,
            EventArgs e
            )
        {
            AssertValid();

            // The GeneralUserSettings are normally edited from the TaskPane, not
            // the Ribbon, so this event handler differs from the others.

            GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings();

            GeneralUserSettingsDialog oGeneralUserSettingsDialog =
            new GeneralUserSettingsDialog(oGeneralUserSettings,
            m_oThisWorkbook.InnerObject);

            if (oGeneralUserSettingsDialog.ShowDialog() == DialogResult.OK)
            {
            oGeneralUserSettings.Save();
            }
        }
예제 #17
0
        //*************************************************************************
        //  Method: CreateGraphDrawingContext()
        //
        /// <summary>
        /// Creates a GraphDrawingContext object to use when drawing the subgraphs.
        /// </summary>
        ///
        /// <param name="oSubgraphRectangle">
        /// The subgraph rectangle.
        /// </param>
        ///
        /// <param name="iMargin">
        /// The graph margin.
        /// </param>
        ///
        /// <param name="oGeneralUserSettings">
        /// The user's general settings.
        /// </param>
        ///
        /// <returns>
        /// A GraphDrawingContext object to use when drawing the subgraphs.
        /// </returns>
        //*************************************************************************
        protected GraphDrawingContext CreateGraphDrawingContext(
            Rectangle oSubgraphRectangle,
            Int32 iMargin,
            GeneralUserSettings oGeneralUserSettings
            )
        {
            Debug.Assert(iMargin >= 0);
            Debug.Assert(oGeneralUserSettings != null);
            AssertValid();

            return ( new GraphDrawingContext(
            WpfGraphicsUtil.RectangleToRect(oSubgraphRectangle), iMargin,
            WpfGraphicsUtil.ColorToWpfColor(oGeneralUserSettings.BackColor)
            ) );
        }
예제 #18
0
        //*************************************************************************
        //  Method: CreateNodeXLVisual()
        //
        /// <summary>
        /// Creates a NodeXLVisual object to use to draw subgraphs.
        /// </summary>
        ///
        /// <param name="oGeneralUserSettings">
        /// The user's general settings.
        /// </param>
        ///
        /// <returns>
        /// A NodeXLVisual object to use to draw subgraphs.
        /// </returns>
        //*************************************************************************
        protected NodeXLVisual CreateNodeXLVisual(
            GeneralUserSettings oGeneralUserSettings
            )
        {
            Debug.Assert(oGeneralUserSettings != null);
            AssertValid();

            NodeXLVisual oNodeXLVisual = new NodeXLVisual();

            GraphDrawer oGraphDrawer = oNodeXLVisual.GraphDrawer;

            VertexDrawer oVertexDrawer = oGraphDrawer.VertexDrawer;

            EdgeDrawer oEdgeDrawer = oGraphDrawer.EdgeDrawer;

            oGeneralUserSettings.TransferToGraphDrawer(oGraphDrawer);

            // Override some of the user's settings.

            oVertexDrawer.Shape = VertexShape.Disk;
            oVertexDrawer.Radius = 2.0;
            oEdgeDrawer.Width = 1;
            oEdgeDrawer.SelectedWidth = 1;

            return (oNodeXLVisual);
        }