public static void Draw(Diagram diagram, Graphics g, Rectangle? clipRectangle) { using (DiagramGdiRenderer renderer = new DiagramGdiRenderer(g)) { renderer.Render(diagram, clipRectangle); } }
public DiagramExporter(Diagram diagram) { if (diagram == null) { throw new ArgumentNullException("diagram", "The diagram parameter cannot be null (or Nothing)."); } _diagram = diagram; }
public override void Render(Diagram diagram) { this.BeginItemsRender(); foreach (DiagramItem element in diagram.RootElements) { this.Render(element); } this.EndItemsRender(); }
public static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; bool streamToOutput = !string.IsNullOrEmpty(Options.OutputFile) || Options.OutputOnStdOut; if (Options.NoGUI || Options.RequestHelp || streamToOutput) { //if(!Options.IsRunningOnMono) //{ // if (GetConsoleWindow() == IntPtr.Zero) // ; // AllocConsole(); //} if (Options.RequestHelp || string.IsNullOrEmpty(Options.InputFile) || !streamToOutput || Options.RootElements.Count == 0 || Options.ExpandLevel < 0 || Options.Zoom < 10.0 || Options.Zoom > 1000.0) { string version = typeof(Program).Assembly.GetName().Version.ToString(); Log(usage, version, Path.GetFileName(Environment.GetCommandLineArgs()[0])); return; } Log("Loading the file: {0}\n", Options.InputFile); Schema schema = new Schema(); schema.RequestCredential += delegate(string url, string realm, int attemptCount, out string username, out string password) { username = password = ""; if(!string.IsNullOrEmpty(Options.Username)) { if (attemptCount > 1) return false; username = Options.Username; password = Options.Password; return true; } return false; }; schema.LoadSchema(Options.InputFile); if (schema.LoadError.Count > 0) { LogError("There are errors while loading:\n"); foreach (var error in schema.LoadError) { LogError(error); } LogError("\r\n"); } Diagram diagram = new Diagram(); diagram.ShowDocumentation = Options.ShowDocumentation; diagram.ElementsByName = schema.ElementsByName; diagram.Scale = Options.Zoom / 100.0f; foreach (var rootElement in Options.RootElements) { string elementName = rootElement; string elementNamespace = null; if(!string.IsNullOrEmpty(elementName)) { var pos = rootElement.IndexOf("@"); if(pos != -1) { elementName = rootElement.Substring(0, pos); elementNamespace = rootElement.Substring(pos + 1); } } foreach (var element in schema.Elements) { if ((elementNamespace != null && elementNamespace == element.NameSpace && element.Name == elementName) || (elementNamespace == null && element.Name == elementName)) { Log("Adding '{0}' element to the diagram...\n", rootElement); diagram.Add(element.Tag, element.NameSpace); } } } Form form = new Form(); Graphics graphics = form.CreateGraphics(); graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; for (int i = 0; i < Options.ExpandLevel; i++) { Log("Expanding to level {0}...\n", i + 1); diagram.ExpandOneLevel(); } diagram.Layout(graphics); Log("Saving image...\n"); try { bool result = false; DiagramExporter exporter = new DiagramExporter(diagram); IDictionary<string, object> specificRendererParameters = new Dictionary<string, object>() { { "TextOutputFields", Options.TextOutputFields } //For future parameters, {} }; if (Options.OutputOnStdOut) { Stream stream = Console.OpenStandardOutput(); result = exporter.Export(stream, "." + Options.OutputOnStdOutExtension.ToLower(), graphics, new DiagramAlertHandler(ByPassSaveAlert), specificRendererParameters); stream.Flush(); } else { result = exporter.Export(Options.OutputFile, graphics, new DiagramAlertHandler(SaveAlert), specificRendererParameters); } if (result) Log("The diagram is now saved in the file: {0}\n", Options.OutputFile); else Log("ERROR: The diagram has not been saved!\n"); } catch (Exception ex) { Log("ERROR: The diagram has not been saved. {0}\n", ex.Message); } graphics.Dispose(); form.Dispose(); } else { if (Options.RequestHelp) { string version = typeof(Program).Assembly.GetName().Version.ToString(); MessageBox.Show(string.Format(usage, version, Environment.GetCommandLineArgs()[0])); } Application.ThreadException += HandleThreadException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } }
public override void Render(Diagram diagram) { _fieldSeparator = IsCSV ? "," : "\t"; _finalTextOutputFields = new List<string>(); if (TextOutputFields.Count == 0) _finalTextOutputFields = fields; else foreach(string field in TextOutputFields) if(fields.Contains(field)) _finalTextOutputFields.Add(field); this.BeginItemsRender(); foreach (DiagramItem element in diagram.RootElements) { this.Render(element); } this.EndItemsRender(); }
public abstract void Render(Diagram diagram);
public void Render(Diagram diagram, Rectangle? clipRectangle) { this.BeginItemsRender(); Rectangle clipBox = clipRectangle.HasValue ? clipRectangle.Value : Rectangle.Empty; if (!clipBox.IsEmpty) { clipBox.X = (int)((float)clipBox.X / diagram.Scale); clipBox.Y = (int)((float)clipBox.Y / diagram.Scale); clipBox.Width = (int)((float)clipBox.Width / diagram.Scale); clipBox.Height = (int)((float)clipBox.Height / diagram.Scale); foreach (DiagramItem element in diagram.RootElements) { if (element.BoundingBox.IntersectsWith(clipBox)) { this.Render(element, clipBox); } } } else { foreach (DiagramItem element in diagram.RootElements) { this.Render(element); } } this.EndItemsRender(); }
public override void Render(Diagram diagram) { this.Render(diagram, null); }
public static void Draw(Diagram diagram, Graphics g) { Draw(diagram, g, null); }
/// <summary> /// This cleans up any resources being used. /// </summary> /// <param name="disposing"> /// This is <see langword="true"/> if managed resources should be /// disposed; otherwise, <see langword="false"/>. /// </param> private void Dispose(bool disposing) { if (disposing) { if (_printDocument != null) { _printDocument.Dispose(); _printDocument = null; } } _diagram = null; }
public override void Render(Diagram diagram) { _boundingBox = diagram.ScaleRectangle(diagram.BoundingBox); this.BeginItemsRender(); foreach (DiagramItem element in diagram.RootElements) { this.Render(element); } this.EndItemsRender(); }