1
1
mirror of https://github.com/dgis/xsddiagram.git synced 2024-09-11 18:47:19 +03:00
This commit is contained in:
(no author) 2010-07-13 12:54:30 +00:00
parent a0772c6473
commit e20da083a3
3 changed files with 113 additions and 74 deletions

View File

@ -862,60 +862,11 @@ xmlns=""http://www.w3.org/2000/svg"">
this.elementBox.Offset(this.location);
}
protected void DrawOccurencesText(Graphics g, SolidBrush foreground)
{
if (this.maxOccurrence > 1 || this.maxOccurrence == -1)
{
StringFormat stringFormatOccurences = new StringFormat();
stringFormatOccurences.Alignment = StringAlignment.Far;
stringFormatOccurences.LineAlignment = StringAlignment.Center;
stringFormatOccurences.FormatFlags |= StringFormatFlags.NoClip; //MONOFIX
string occurences = string.Format("{0}..", this.minOccurrence) + (this.maxOccurrence == -1 ? "∞" : string.Format("{0}", this.maxOccurrence));
PointF pointOccurences = new PointF();
pointOccurences.X = this.Diagram.Scale * (this.Location.X + this.Size.Width - 10);
pointOccurences.Y = this.Diagram.Scale * (this.Location.Y + this.Size.Height + 10);
g.DrawString(occurences, this.SmallFont, foreground, pointOccurences, stringFormatOccurences);
}
}
protected int ScaleInt(int integer) { return this.diagram.ScaleInt(integer); }
protected Point ScalePoint(Point point) { return this.diagram.ScalePoint(point); }
protected Size ScaleSize(Size point) { return this.diagram.ScaleSize(point); }
protected Rectangle ScaleRectangle(Rectangle rectangle) { return this.diagram.ScaleRectangle(rectangle); }
protected void DrawLines(Graphics g, Pen foregroundPen)
{
if (this.showChildElements)
{
if (this.childElements.Count == 1)
{
int parentMidleY = ScaleInt(this.location.Y + this.size.Height / 2);
g.DrawLine(foregroundPen, ScaleInt(this.location.X + this.size.Width), parentMidleY, ScaleInt(this.childElements[0].Location.X), parentMidleY);
}
else if (this.childElements.Count > 1)
{
DiagramBase firstElement = this.childElements[0];
DiagramBase lastElement = this.childElements[this.childElements.Count - 1];
int verticalLine = ScaleInt(firstElement.BoundingBox.Left);
foreach (DiagramBase element in this.childElements)
{
if (element.InheritFrom == null)
{
int currentMidleY = ScaleInt(element.Location.Y + element.Size.Height / 2);
g.DrawLine(foregroundPen, verticalLine, currentMidleY, ScaleInt(element.Location.X), currentMidleY);
}
}
int parentMidleY = ScaleInt(this.location.Y + this.size.Height / 2);
int firstMidleY = ScaleInt(firstElement.Location.Y + firstElement.Size.Height / 2);
firstMidleY = Math.Min(firstMidleY, parentMidleY);
int lastMidleY = ScaleInt(lastElement.Location.Y + lastElement.Size.Height / 2);
lastMidleY = Math.Max(lastMidleY, parentMidleY);
g.DrawLine(foregroundPen, verticalLine, firstMidleY, verticalLine, lastMidleY);
g.DrawLine(foregroundPen, ScaleInt(this.location.X + this.size.Width), parentMidleY, verticalLine, parentMidleY);
}
}
}
public void HitTest(Point point, out DiagramBase element, out HitTestRegion region)
{
element = null;
@ -993,7 +944,40 @@ xmlns=""http://www.w3.org/2000/svg"">
Rectangle scaledElementBox = ScaleRectangle(this.elementBox);
// Draw the children lines
DrawLines(g, foregroundPen);
if (this.showChildElements)
{
Pen foregroundInheritPen = new Pen(foreground);
foregroundInheritPen.StartCap = LineCap.Round;
foregroundInheritPen.EndCap = LineCap.Round;
if (this.childElements.Count == 1)
{
int parentMidleY = ScaleInt(this.location.Y + this.size.Height / 2);
g.DrawLine(foregroundInheritPen, ScaleInt(this.location.X + this.size.Width), parentMidleY, ScaleInt(this.childElements[0].Location.X), parentMidleY);
}
else if (this.childElements.Count > 1)
{
DiagramBase firstElement = this.childElements[0];
DiagramBase lastElement = this.childElements[this.childElements.Count - 1];
int verticalLine = ScaleInt(firstElement.BoundingBox.Left);
foreach (DiagramBase element in this.childElements)
{
if (element.InheritFrom == null)
{
int currentMidleY = ScaleInt(element.Location.Y + element.Size.Height / 2);
g.DrawLine(foregroundInheritPen, verticalLine, currentMidleY, ScaleInt(element.Location.X), currentMidleY);
}
}
int parentMidleY = ScaleInt(this.location.Y + this.size.Height / 2);
int firstMidleY = ScaleInt(firstElement.Location.Y + firstElement.Size.Height / 2);
firstMidleY = Math.Min(firstMidleY, parentMidleY);
int lastMidleY = ScaleInt(lastElement.Location.Y + lastElement.Size.Height / 2);
lastMidleY = Math.Max(lastMidleY, parentMidleY);
g.DrawLine(foregroundInheritPen, verticalLine, firstMidleY, verticalLine, lastMidleY);
g.DrawLine(foregroundInheritPen, ScaleInt(this.location.X + this.size.Width), parentMidleY, verticalLine, parentMidleY);
}
}
// Draw the inheritor line
if (this.inheritFrom != null)
@ -1274,7 +1258,18 @@ xmlns=""http://www.w3.org/2000/svg"">
}
// Draw occurences small text
DrawOccurencesText(g, foreground);
if (this.maxOccurrence > 1 || this.maxOccurrence == -1)
{
StringFormat stringFormatOccurences = new StringFormat();
stringFormatOccurences.Alignment = StringAlignment.Far;
stringFormatOccurences.LineAlignment = StringAlignment.Center;
stringFormatOccurences.FormatFlags |= StringFormatFlags.NoClip; //MONOFIX
string occurences = string.Format("{0}..", this.minOccurrence) + (this.maxOccurrence == -1 ? "∞" : string.Format("{0}", this.maxOccurrence));
PointF pointOccurences = new PointF();
pointOccurences.X = this.Diagram.Scale * (this.Location.X + this.Size.Width - 10);
pointOccurences.Y = this.Diagram.Scale * (this.Location.Y + this.Size.Height + 10);
g.DrawString(occurences, this.SmallFont, foreground, pointOccurences, stringFormatOccurences);
}
// Draw type
if (this.isSimpleContent)
@ -1674,7 +1669,7 @@ xmlns=""http://www.w3.org/2000/svg"">
// Draw text
if (this.name.Length > 0)
{
string style = string.Format("font-family:{0};font-size:{1}pt;fill:{2};text-anchor:middle;dominant-baseline:central", this.Font.Name, this.Font.Size * fontScale, foregroundColor);
string style = string.Format("font-family:{0};font-size:{1}pt;fill:{2};font-weight:bold;text-anchor:middle;dominant-baseline:central", this.Font.Name, this.Font.Size * fontScale, foregroundColor);
SVGText(result, this.name, style, new Rectangle(scaledElementBox.X, scaledElementBox.Y, scaledElementBox.Width, scaledElementBox.Height));
}
@ -1707,7 +1702,7 @@ xmlns=""http://www.w3.org/2000/svg"">
{
string arrowPen = string.Format("stroke:{0};stroke-width:{1}", foregroundColor, this.Diagram.Scale * 2.0f);
Point basePoint = new Point(this.elementBox.Left + 1, this.elementBox.Bottom - 1);
Point targetPoint = basePoint + new Size(2, -2);
Point targetPoint = basePoint + new Size(3, -3);
basePoint = ScalePoint(basePoint);
targetPoint = ScalePoint(targetPoint);
SVGLine(result, arrowPen, basePoint, targetPoint);

View File

@ -109,38 +109,80 @@ namespace XSDDiagram
private void saveDiagramToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "SVH files (*.svg)|*.svg" + (isRunningOnMono ? "" : "|EMF files (*.emf)|*.emf") + "|All files (*.*)|*.*";
saveFileDialog.Filter = "SVH files (*.svg)|*.svg" + (isRunningOnMono ? "" : "|EMF files (*.emf)|*.emf") + "|PNG files (*.png)|*.png|All files (*.*)|*.*";
saveFileDialog.FilterIndex = 1;
saveFileDialog.RestoreDirectory = true;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
Graphics g1 = this.panelDiagram.DiagramControl.CreateGraphics();
string extension = Path.GetExtension(saveFileDialog.FileName).ToLower();
if (extension.CompareTo(".svg") == 0 || isRunningOnMono)
if (string.IsNullOrEmpty(extension)) { extension = ".svg"; saveFileDialog.FileName += extension; }
if (extension.CompareTo(".emf") == 0)
{
float scaleSave = this.diagram.Scale;
try
{
this.diagram.Scale = 1.0f;
this.diagram.Layout(g1);
IntPtr hdc = g1.GetHdc();
Metafile metafile = new Metafile(saveFileDialog.FileName, hdc);
Graphics g2 = Graphics.FromImage(metafile);
g2.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
this.diagram.Layout(g2);
this.diagram.Paint(g2);
g1.ReleaseHdc(hdc);
metafile.Dispose();
g2.Dispose();
}
finally
{
this.diagram.Scale = scaleSave;
this.diagram.Layout(g1);
}
}
else if (extension.CompareTo(".png") == 0)
{
Rectangle bbox = this.diagram.ScaleRectangle(this.diagram.BoundingBox);
bool bypassAlert = true;
if (bbox.Width > 10000 || bbox.Height > 10000)
bypassAlert = MessageBox.Show(this, string.Format("Are you agree to generate a {0}x{1} image?", bbox.Width, bbox.Height), "Huge image generation", MessageBoxButtons.YesNo) == DialogResult.Yes;
if (bypassAlert)
{
Bitmap bitmap = new Bitmap(bbox.Width, bbox.Height);
Graphics graphics = Graphics.FromImage((Image)bitmap);
graphics.FillRectangle(Brushes.White, 0, 0, bbox.Width, bbox.Height);
this.diagram.Paint(graphics);
bitmap.Save(saveFileDialog.FileName);
}
}
else //if (extension.CompareTo(".svg") == 0)
{
string svgFileContent = this.diagram.ToSVG();
using (StreamWriter sw = new StreamWriter(saveFileDialog.FileName))
{
sw.WriteLine(svgFileContent);
}
}
else
{
Graphics g1 = this.panelDiagram.DiagramControl.CreateGraphics();
IntPtr hdc = g1.GetHdc();
Metafile metafile = new Metafile(saveFileDialog.FileName, hdc);
Graphics g2 = Graphics.FromImage(metafile);
g2.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
this.diagram.Layout(g2);
this.diagram.Paint(g2);
g1.ReleaseHdc(hdc);
g2.Dispose();
g1.Dispose();
float scaleSave = this.diagram.Scale;
try
{
this.diagram.Scale = 1.0f;
this.diagram.Layout(g1);
string svgFileContent = this.diagram.ToSVG();
using (StreamWriter sw = new StreamWriter(saveFileDialog.FileName))
{
sw.WriteLine(svgFileContent);
sw.Close();
}
}
finally
{
this.diagram.Scale = scaleSave;
this.diagram.Layout(g1);
}
}
g1.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
System.Diagnostics.Trace.WriteLine(ex.ToString());
}
}

View File

@ -13,7 +13,7 @@ FEATURES:
- Display the elements, the groups and the attributes
- Show the text/HTML documentation of element and attribute when available
- Print the diagram
- Export the diagram to SVG and EMF
- Export the diagram to SVG, PNG and EMF (EMF only with Windows)
- Zoom the diagram with the mouse wheel while holding the control key
- Registration in the Windows Explorer contextual menu
- Drag'n drop a file from explorer
@ -53,6 +53,8 @@ CHANGES:
version 0.7 (2010-07-14)
- Inversion of the mouse wheel direction to zoom
- Add the SVG diagram export
- Add the Tiago Daitx's code about the PNG diagram export
- Improve the diagram quality
version 0.6 (2010-06-27)
- Fix the print function.