private void RunMultipageLayout()
        {
            // parse the pageWidth and pageHeight parameters
            double pageWidth;
            double pageHeight;

            if (!Double.TryParse(pageWidthTextBox.Text, out pageWidth))
            {
                pageWidth = 800;
            }
            if (!Double.TryParse(pageHeightTextBox.Text, out pageHeight))
            {
                pageHeight = 800;
            }

            // get the core layout
            string coreLayoutKey = coreLayoutComboBox.SelectedItem as string;

            if (coreLayoutKey != null && coreLayouts.ContainsKey(coreLayoutKey))
            {
                coreLayout = coreLayouts[coreLayoutKey];
            }
            else
            {
                coreLayout = coreLayouts["Hierarchic"];
            }

            // a data provider for the node, edge, and label IDs:
            // this data provider returns the node/edge/label instances themselves

            var multiPageLayoutData = new MultiPageLayoutData
            {
                NodeIds      = { Delegate = node => node },
                EdgeIds      = { Delegate = edge => edge },
                NodeLabelIds = { Delegate = label => label },
                EdgeLabelIds = { Delegate = label => label },
                AbortHandler = abortHandler = new AbortHandler()
            };

            // apply the multi page layout
            // multiPageLayout contains a list with the single page graphs
            MultiPageLayout multiPageLayout = new MultiPageLayout(coreLayout)
            {
                MaximumPageSize = new YDimension(pageWidth, pageHeight),
                LayoutCallback  = new DelegateLayoutCallback(result => BeginInvoke(new Action(() => {
                    ApplyLayoutResult(result, pageWidth, pageHeight);
                    abortHandler = null;
                    ShowLoadingIndicator(false);
                    // force to update the command state
                    CommandManager.InvalidateRequerySuggested();
                })))
            };

            // execute layout in thread to prevent ui blocking
            new Thread(() => {
                try {
                    modelGraph.ApplyLayout(multiPageLayout, multiPageLayoutData);
                } catch (AlgorithmAbortedException) {
                    // layout was aborted
                    BeginInvoke(new Action(() => {
                        // reset abortHandler and loading indicator in the view thread
                        abortHandler = null;
                        ShowLoadingIndicator(false);
                    }));
                }
            }).Start();
        }
예제 #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the sheet layout.
		/// </summary>
		/// <param name="attributes">The attributes.</param>
		/// <param name="defaultMultiPageLayout">The default multi page layout, whether simplex,
		/// duplex or booklet.</param>
		/// <returns>multi page layout value from the XML file, or the default value if not
		/// specified</returns>
		/// ------------------------------------------------------------------------------------
		private MultiPageLayout GetSheetLayout(XmlAttributeCollection attributes,
			MultiPageLayout defaultMultiPageLayout)
		{
			XmlNode sheetLayoutAttrib = attributes.GetNamedItem("SheetLayout");

			if (sheetLayoutAttrib != null && sheetLayoutAttrib.Value != string.Empty)
			{
				try
				{
					return (MultiPageLayout)Enum.Parse(typeof(MultiPageLayout),
						sheetLayoutAttrib.Value, true);
				}
				catch
				{
					string message;
#if DEBUG
					message = "Error reading TePublications.xml: Unrecognized SheetLayout attribute: " +
						"SheetLayout=\"" + sheetLayoutAttrib.Value + "\"";
#else
					message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
#endif
					throw new Exception(message);
				}
			}
			return defaultMultiPageLayout;
		}