1
1
mirror of https://github.com/dgis/xsddiagram.git synced 2024-10-05 14:17:40 +03:00

- Add the documentation in the diagram (experimental).

- Increase the icon resolution.
This commit is contained in:
dgis 2016-02-17 18:24:39 +01:00
parent 7ed08010b5
commit 44b5a23097
11 changed files with 183 additions and 83 deletions

BIN
Icons/Icon256.pdn Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 216 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 707 B

After

Width:  |  Height:  |  Size: 1.2 KiB

36
MainForm.Designer.cs generated
View File

@ -23,6 +23,7 @@ namespace XSDDiagram
this.openURLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveDiagramToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.validateXMLFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.recentFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.closeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.pageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -55,6 +56,7 @@ namespace XSDDiagram
this.toolStripComboBoxZoom = new System.Windows.Forms.ToolStripComboBox();
this.toolStripComboBoxAlignement = new System.Windows.Forms.ToolStripComboBox();
this.toolStripButtonShowReferenceBoundingBox = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonShowDocumentation = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonTogglePanel = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripButtonAbout = new System.Windows.Forms.ToolStripButton();
@ -100,7 +102,6 @@ namespace XSDDiagram
this.expandOneLevelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textBoxElementPath = new System.Windows.Forms.TextBox();
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.recentFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStripMain.SuspendLayout();
this.statusStripMain.SuspendLayout();
this.toolStripMain.SuspendLayout();
@ -186,6 +187,12 @@ namespace XSDDiagram
this.validateXMLFileToolStripMenuItem.Text = "&Validate XML File...";
this.validateXMLFileToolStripMenuItem.Click += new System.EventHandler(this.validateXMLFileToolStripMenuItem_Click);
//
// recentFilesToolStripMenuItem
//
this.recentFilesToolStripMenuItem.Name = "recentFilesToolStripMenuItem";
this.recentFilesToolStripMenuItem.Size = new System.Drawing.Size(204, 22);
this.recentFilesToolStripMenuItem.Text = "&Recent Files";
//
// closeToolStripMenuItem
//
this.closeToolStripMenuItem.Name = "closeToolStripMenuItem";
@ -240,7 +247,7 @@ namespace XSDDiagram
this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.windowsExplorerRegistrationToolStripMenuItem});
this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem";
this.toolsToolStripMenuItem.Size = new System.Drawing.Size(47, 20);
this.toolsToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
this.toolsToolStripMenuItem.Text = "&Tools";
//
// windowsExplorerRegistrationToolStripMenuItem
@ -282,7 +289,7 @@ namespace XSDDiagram
//
this.nextTabToolStripMenuItem.Name = "nextTabToolStripMenuItem";
this.nextTabToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Tab)));
this.nextTabToolStripMenuItem.Size = new System.Drawing.Size(226, 22);
this.nextTabToolStripMenuItem.Size = new System.Drawing.Size(228, 22);
this.nextTabToolStripMenuItem.Text = "&Next Tab";
this.nextTabToolStripMenuItem.Click += new System.EventHandler(this.nextTabToolStripMenuItem_Click);
//
@ -291,7 +298,7 @@ namespace XSDDiagram
this.previousTabToolStripMenuItem.Name = "previousTabToolStripMenuItem";
this.previousTabToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift)
| System.Windows.Forms.Keys.Tab)));
this.previousTabToolStripMenuItem.Size = new System.Drawing.Size(226, 22);
this.previousTabToolStripMenuItem.Size = new System.Drawing.Size(228, 22);
this.previousTabToolStripMenuItem.Text = "&Previous Tab";
this.previousTabToolStripMenuItem.Click += new System.EventHandler(this.previousTabToolStripMenuItem_Click);
//
@ -344,6 +351,7 @@ namespace XSDDiagram
this.toolStripComboBoxZoom,
this.toolStripComboBoxAlignement,
this.toolStripButtonShowReferenceBoundingBox,
this.toolStripButtonShowDocumentation,
this.toolStripButtonTogglePanel,
this.toolStripSeparator4,
this.toolStripButtonAbout});
@ -506,9 +514,20 @@ namespace XSDDiagram
this.toolStripButtonShowReferenceBoundingBox.Size = new System.Drawing.Size(23, 22);
this.toolStripButtonShowReferenceBoundingBox.Text = "References";
this.toolStripButtonShowReferenceBoundingBox.ToolTipText = "Show the bounding box for the referenced elements";
this.toolStripButtonShowReferenceBoundingBox.Visible = false;
this.toolStripButtonShowReferenceBoundingBox.Click += new System.EventHandler(this.toolStripButtonShowReferenceBoundingBox_Click);
//
// toolStripButtonShowDocumentation
//
this.toolStripButtonShowDocumentation.CheckOnClick = true;
this.toolStripButtonShowDocumentation.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButtonShowDocumentation.Image = global::XSDDiagram.Properties.Resources.Properties;
this.toolStripButtonShowDocumentation.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButtonShowDocumentation.Name = "toolStripButtonShowDocumentation";
this.toolStripButtonShowDocumentation.Size = new System.Drawing.Size(23, 22);
this.toolStripButtonShowDocumentation.Text = "toolStripButton1";
this.toolStripButtonShowDocumentation.ToolTipText = "Show the documentation in the diagram";
this.toolStripButtonShowDocumentation.Click += new System.EventHandler(this.toolStripButtonShowDocumentation_Click);
//
// toolStripButtonTogglePanel
//
this.toolStripButtonTogglePanel.Checked = true;
@ -937,12 +956,6 @@ namespace XSDDiagram
this.toolTip.OwnerDraw = true;
this.toolTip.ShowAlways = true;
//
// recentFilesToolStripMenuItem
//
this.recentFilesToolStripMenuItem.Name = "recentFilesToolStripMenuItem";
this.recentFilesToolStripMenuItem.Size = new System.Drawing.Size(204, 22);
this.recentFilesToolStripMenuItem.Text = "&Recent Files";
//
// MainForm
//
this.AllowDrop = true;
@ -1076,6 +1089,7 @@ namespace XSDDiagram
private System.Windows.Forms.ToolStripMenuItem openURLToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem closeToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem recentFilesToolStripMenuItem;
private System.Windows.Forms.ToolStripButton toolStripButtonShowDocumentation;
}
}

View File

@ -1765,6 +1765,12 @@ namespace XSDDiagram
e.Exception.LineNumber, e.Exception.LinePosition, e.Exception.Message, validationErrorMessages.Count, e.Severity));
}
private void toolStripButtonShowDocumentation_Click(object sender, EventArgs e)
{
this.diagram.ShowDocumentation = this.toolStripButtonShowDocumentation.Checked;
UpdateDiagram();
}
private void MainForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.Control && (e.KeyCode == Keys.D0 || e.KeyCode == Keys.NumPad0))

View File

@ -119,10 +119,12 @@ TODO LIST:
CHANGES:
version 0.18 (Not released yet)
- Add the documentation in the diagram (experimental).
- Add a close entry in the File menu.
- Add a recently opened list.
- Show the Windows Explorer registration menu only if we have the adminitrative right.
- Disable the impossible actions in the menu and the toolbar when XSD file are not loaded.
- Increase the icon resolution.
- From AlexM: oh, and allow the specification of a complex type in the command line as a root (-r element1 -r complexType2 -r ...).
- Fixed min/maxOccurs for group references (Thanks Cleric-K).
- Fixed the node expansion group of type 'All' (Thanks Carsten).

Binary file not shown.

Binary file not shown.

View File

@ -20,15 +20,17 @@ namespace XSDDiagram.Rendering
{
#region Private Fields
private bool _showBoundingBox;
private Size _size;
private Size _padding;
private bool _showBoundingBox;
private bool _showDocumentation;
private Size _size;
private Size _padding;
private float _scale;
private Font _font;
private Font _smallFont;
private Font _documentationFont;
private Rectangle _boundingBox;
private Rectangle _boundingBox;
private DiagramAlignement _alignement;
private List<DiagramItem> _rootElements;
@ -60,10 +62,12 @@ namespace XSDDiagram.Rendering
public Rectangle BoundingBox { get { return _boundingBox; } }
public float Scale { get { return _scale; } set { _scale = value; } }
public DiagramAlignement Alignement { get { return _alignement; } set { _alignement = value; } }
public bool ShowBoundingBox { get { return _showBoundingBox; } set { _showBoundingBox = value; } }
public bool ShowBoundingBox { get { return _showBoundingBox; } set { _showBoundingBox = value; } }
public bool ShowDocumentation { get { return _showDocumentation; } set { _showDocumentation = value; } }
public Font Font { get { return _font; } set { _font = value; } }
public Font SmallFont { get { return _smallFont; } set { _smallFont = value; } }
public Font Font { get { return _font; } set { _font = value; } }
public Font SmallFont { get { return _smallFont; } set { _smallFont = value; } }
public Font DocumentationFont { get { return _documentationFont; } set { _documentationFont = value; } }
public IDictionary<string, XSDObject> ElementsByName { get { return _elementsByName; } set { _elementsByName = value; } }
public List<DiagramItem> RootElements { get { return _rootElements; } }
@ -425,19 +429,30 @@ namespace XSDDiagram.Rendering
{
string fontName = "Arial"; // "Verdana"; // "Arial";
if (_font != null)
{
_font.Dispose();
}
if (_smallFont != null)
{
_smallFont.Dispose();
}
//if (_font != null)
//{
// _font.Dispose();
//}
//if (_smallFont != null)
//{
// _smallFont.Dispose();
//}
//if (_documentationFont != null)
//{
// _documentationFont.Dispose();
//}
//_font = new Font(fontName, 10.0f * (float)Math.Pow(_scale, 2.0), FontStyle.Bold, GraphicsUnit.Pixel);
//_smallFont = new Font(fontName, 9.0f * (float)Math.Pow(_scale, 2.0), GraphicsUnit.Pixel);
//_documentationFont = new Font(fontName, 10.0f * (float)Math.Pow(_scale, 2.0), GraphicsUnit.Pixel);
float fontScale = (float)Math.Pow(_scale, 2.0);
if (_font == null)
_font = new Font(fontName, 10.0f * fontScale, FontStyle.Bold, GraphicsUnit.Pixel);
if (_smallFont == null)
_smallFont = new Font(fontName, 9.0f * fontScale, GraphicsUnit.Pixel);
if (_documentationFont == null)
_documentationFont = new Font(fontName, 10.0f * fontScale, GraphicsUnit.Pixel);
_font = new Font(fontName, 10.0f * (float)Math.Pow(_scale, 2.0), FontStyle.Bold, GraphicsUnit.Pixel);
_smallFont = new Font(fontName, 9.0f * (float)Math.Pow(_scale, 2.0), GraphicsUnit.Pixel);
foreach (DiagramItem element in _rootElements)
foreach (DiagramItem element in _rootElements)
element.GenerateMeasure(g);
_boundingBox = new Rectangle(0, 0, 100, 0);

View File

@ -486,42 +486,30 @@ namespace XSDDiagram.Rendering
}
// Draw Documentation
XMLSchema.annotated annotated = drawingItem.TabSchema as XMLSchema.annotated;
if (annotated != null && annotated.annotation != null)
if (drawingItem.Diagram.ShowDocumentation && drawingItem.DocumentationBox != null)
{
foreach (object o in annotated.annotation.Items)
string text = drawingItem.GetTextDocumentation();
if (text != null)
{
if (o is XMLSchema.documentation)
StringFormat stringFormatText = new StringFormat();
stringFormatText.Alignment = StringAlignment.Near;
stringFormatText.LineAlignment = StringAlignment.Near;
stringFormatText.FormatFlags |= StringFormatFlags.NoClip; //MONOFIX
//_graphics.DrawString(text, drawingItem.Font, foreground
// , new RectangleF(scaledElementBox.X - drawingItem.Diagram.Scale * 5.0f, scaledElementBox.Y + scaledElementBox.Height + drawingItem.Diagram.Scale * 12.0f
// , scaledElementBox.Width + drawingItem.Diagram.Scale * 10.0f, 2.0f * scaledElementBox.Height)
// , stringFormatText);
Rectangle scaledDocumentationBox = drawingItem.ScaleRectangle(drawingItem.DocumentationBox);
if (drawingItem.Diagram.ShowBoundingBox)
{
string text = null;
XMLSchema.documentation documentation = o as XMLSchema.documentation;
if (documentation.Any != null && documentation.Any.Length > 0)
{
text = documentation.Any[0].Value;
text = text.Replace("\n", " ");
text = text.Replace("\t", " ");
text = text.Replace("\r", "");
text = Regex.Replace(text, " +", " ");
text = text.Trim();
}
else if (documentation.source != null)
{
text = documentation.source;
}
if (text != null)
{
StringFormat stringFormatText = new StringFormat();
stringFormatText.Alignment = StringAlignment.Near;
stringFormatText.LineAlignment = StringAlignment.Near;
stringFormatText.FormatFlags |= StringFormatFlags.NoClip; //MONOFIX
_graphics.DrawString(text, drawingItem.Font, foreground
, new RectangleF(scaledElementBox.X - drawingItem.Diagram.Scale * 5.0f, scaledElementBox.Y + scaledElementBox.Height + drawingItem.Diagram.Scale * 12.0f
, scaledElementBox.Width + drawingItem.Diagram.Scale * 10.0f, 2.0f * scaledElementBox.Height)
, stringFormatText);
}
break;
int color = 255 - drawingItem.Depth * 8;
_graphics.FillRectangle(new SolidBrush(Color.FromArgb(color, 255 - color, color)), scaledDocumentationBox);
_graphics.DrawRectangle(foregroundPen, scaledDocumentationBox);
}
_graphics.DrawString(text, drawingItem.DocumentationFont, foreground
, new RectangleF(scaledDocumentationBox.X, scaledDocumentationBox.Y, scaledDocumentationBox.Width, scaledDocumentationBox.Height)
, stringFormatText);
}
}

View File

@ -13,6 +13,7 @@
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace XSDDiagram.Rendering
{
@ -41,6 +42,7 @@ namespace XSDDiagram.Rendering
private Rectangle _elementBox;
private Rectangle _childExpandButtonBox;
private Rectangle _documentationBox;
private Rectangle _boundingBox;
private Diagram _diagram;
@ -67,6 +69,7 @@ namespace XSDDiagram.Rendering
_childExpandButtonSize = 10;
_depth = 0;
_elementBox = Rectangle.Empty;
_documentationBox = Rectangle.Empty;
_childExpandButtonBox = Rectangle.Empty;
_boundingBox = Rectangle.Empty;
_size = new Size(50, 25);
@ -263,15 +266,22 @@ namespace XSDDiagram.Rendering
return _diagram.Font;
}
}
public Font SmallFont
{
get
{
return _diagram.SmallFont;
}
public Font SmallFont
{
get
{
return _diagram.SmallFont;
}
}
public Font DocumentationFont
{
get
{
return _diagram.DocumentationFont;
}
}
public Point Location
{
get
@ -319,19 +329,19 @@ namespace XSDDiagram.Rendering
_padding = value;
}
}
public Rectangle ElementBox
{
get
{
return _elementBox;
}
set
{
_elementBox = value;
}
public Rectangle ElementBox
{
get
{
return _elementBox;
}
set
{
_elementBox = value;
}
}
public Rectangle ChildExpandButtonBox
{
get
@ -343,7 +353,19 @@ namespace XSDDiagram.Rendering
_childExpandButtonBox = value;
}
}
public Rectangle DocumentationBox
{
get
{
return _documentationBox;
}
set
{
_documentationBox = value;
}
}
public Rectangle BoundingBox
{
get
@ -424,6 +446,39 @@ namespace XSDDiagram.Rendering
return _diagram.ScaleRectangle(rectangle);
}
public string GetTextDocumentation()
{
string text = null;
XMLSchema.annotated annotated = this.TabSchema as XMLSchema.annotated;
if (annotated != null && annotated.annotation != null)
{
foreach (object o in annotated.annotation.Items)
{
if (o is XMLSchema.documentation)
{
XMLSchema.documentation documentation = o as XMLSchema.documentation;
if (documentation.Any != null && documentation.Any.Length > 0)
{
text = documentation.Any[0].Value;
text = text.Replace("\n", " ");
text = text.Replace("\t", " ");
text = text.Replace("\r", "");
text = Regex.Replace(text, " +", " ");
text = text.Trim();
}
else if (documentation.source != null)
{
text = documentation.source;
}
break;
}
}
}
return text;
}
public void GenerateMeasure(Graphics g)
{
if (_parent != null)
@ -459,6 +514,18 @@ namespace XSDDiagram.Rendering
_boundingBox.Width = _size.Width + 2 * _padding.Width + childBoundingBoxWidth;
_boundingBox.Height = Math.Max(_size.Height + 2 * _padding.Height, childBoundingBoxHeight);
if (_diagram.ShowDocumentation)
{
string text = GetTextDocumentation();
if (text != null)
{
SizeF sizeF = g.MeasureString(text, DocumentationFont);
double documentationWidth = Math.Max(1.0, _size.Width + _padding.Width * 2.0);
double documentationHeight = (Math.Ceiling(sizeF.Width / documentationWidth) + 1) * sizeF.Height;
_documentationBox = new Rectangle(new Point(0, 0), new Size((int)documentationWidth, (int)documentationHeight));
_boundingBox.Height += (_diagram.Alignement == DiagramAlignement.Center ? 2 : 1) *_documentationBox.Height + 2 * _padding.Height;
}
}
_elementBox = new Rectangle(new Point(0, 0), _size - new Size(_hasChildElements ? _childExpandButtonSize / 2 : 0, 0));
@ -521,6 +588,14 @@ namespace XSDDiagram.Rendering
_childExpandButtonBox.Offset(_location);
_elementBox.Offset(_location);
if (_documentationBox != null)
{
if(_diagram.Alignement == DiagramAlignement.Far)
_documentationBox.Offset(_location.X, _location.Y - _documentationBox.Height - _padding.Height);
else
_documentationBox.Offset(_location.X, _location.Y + _elementBox.Height + _padding.Height);
}
}
public void HitTest(Point point, out DiagramItem element, out DiagramHitTestRegion region)