mirror of
https://github.com/dgis/xsddiagram.git
synced 2024-09-11 18:47:19 +03:00
Add txt and csv renderer with basic fields selection.
This commit is contained in:
parent
b8281da7f3
commit
54951474aa
@ -213,7 +213,11 @@ namespace XSDDiagram
|
||||
{
|
||||
DiagramExporter exporter = new DiagramExporter(diagram);
|
||||
Graphics g1 = this.panelDiagram.DiagramControl.CreateGraphics();
|
||||
exporter.Export(outputFilename, g1, new DiagramAlertHandler(SaveAlert));
|
||||
exporter.Export(outputFilename, g1, new DiagramAlertHandler(SaveAlert), new Dictionary<string, object>()
|
||||
{
|
||||
{ "TextOutputFields", Options.TextOutputFields }
|
||||
//For future parameters, {}
|
||||
});
|
||||
g1.Dispose();
|
||||
}
|
||||
catch (System.ArgumentException ex)
|
||||
|
16
Options.cs
16
Options.cs
@ -35,6 +35,7 @@ namespace XSDDiagram
|
||||
public static bool IsRunningOnMono { get; private set; }
|
||||
public static string Username { get; private set; }
|
||||
public static string Password { get; private set; }
|
||||
public static IList<string> TextOutputFields { get; private set; }
|
||||
|
||||
static Options()
|
||||
{
|
||||
@ -47,7 +48,9 @@ namespace XSDDiagram
|
||||
Zoom = 100.0f;
|
||||
ForceHugeImageGeneration = false;
|
||||
RequestHelp = false;
|
||||
IsRunningOnMono = Type.GetType("Mono.Runtime") != null;
|
||||
TextOutputFields = new List<string>();
|
||||
|
||||
IsRunningOnMono = Type.GetType("Mono.Runtime") != null;
|
||||
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
List<string> arguments = new List<string>();
|
||||
@ -137,7 +140,16 @@ namespace XSDDiagram
|
||||
if (currentArgument < arguments.Count)
|
||||
Password = args[currentArgument++];
|
||||
}
|
||||
else
|
||||
else if (string.Compare("-f", argument, true) == 0)
|
||||
{
|
||||
if (currentArgument < arguments.Count)
|
||||
{
|
||||
string textOutputFields = args[currentArgument++];
|
||||
foreach (string field in textOutputFields.Split(new char[] { ',' }))
|
||||
TextOutputFields.Add(field.Trim());
|
||||
}
|
||||
}
|
||||
else
|
||||
InputFile = argument;
|
||||
}
|
||||
}
|
||||
|
33
Program.cs
33
Program.cs
@ -16,10 +16,10 @@
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using XSDDiagram.Rendering;
|
||||
|
||||
namespace XSDDiagram
|
||||
@ -126,11 +126,12 @@ Example 4:
|
||||
|
||||
if (schema.LoadError.Count > 0)
|
||||
{
|
||||
Log("There are errors while loading:\n");
|
||||
LogError("There are errors while loading:\n");
|
||||
foreach (var error in schema.LoadError)
|
||||
{
|
||||
Log(error);
|
||||
LogError(error);
|
||||
}
|
||||
LogError("\r\n");
|
||||
}
|
||||
|
||||
Diagram diagram = new Diagram();
|
||||
@ -165,15 +166,20 @@ Example 4:
|
||||
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));
|
||||
result = exporter.Export(stream, "." + Options.OutputOnStdOutExtension.ToLower(), graphics, new DiagramAlertHandler(ByPassSaveAlert), specificRendererParameters);
|
||||
stream.Flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = exporter.Export(Options.OutputFile, graphics, new DiagramAlertHandler(SaveAlert));
|
||||
result = exporter.Export(Options.OutputFile, graphics, new DiagramAlertHandler(SaveAlert), specificRendererParameters);
|
||||
}
|
||||
|
||||
if (result)
|
||||
@ -204,12 +210,17 @@ Example 4:
|
||||
}
|
||||
}
|
||||
|
||||
static void Log(string format, params object[] arg)
|
||||
{
|
||||
if (Options.OutputOnStdOut)
|
||||
return;
|
||||
Console.Write(format, arg);
|
||||
}
|
||||
static void Log(string format, params object[] arg)
|
||||
{
|
||||
if (Options.OutputOnStdOut)
|
||||
return;
|
||||
Console.Write(format, arg);
|
||||
}
|
||||
|
||||
static void LogError(string format, params object[] arg)
|
||||
{
|
||||
Console.Error.Write(format, arg);
|
||||
}
|
||||
|
||||
static bool ByPassSaveAlert(string title, string message)
|
||||
{
|
||||
|
@ -58,6 +58,8 @@ Options:
|
||||
-z N
|
||||
specifies the zoom percentage from 10% to 1000% (only for .png image).
|
||||
Work only with the '-o', '-os png' or '-os jpg' option.
|
||||
-f PATH,NAME,TYPE,NAMESPACE,COMMENT
|
||||
specifies the fields you want to output when rendering to a txt or csf file.
|
||||
-y
|
||||
force huge image generation without user prompt.
|
||||
-u USERNAME
|
||||
@ -88,7 +90,7 @@ Example 4:
|
||||
'TotoRoot' and expanding the tree from the root until the 3rd level.
|
||||
|
||||
Example 5:
|
||||
> XSDDiagramConsole.exe -os txt -r TotoRoot -e 3 ./folder1/toto.xsd
|
||||
> XSDDiagramConsole.exe -os txt -r TotoRoot -e 3 -f NAME,TYPE,COMMENT ./folder1/toto.xsd
|
||||
will write a textual representation in the standard output from a diagram with a root element
|
||||
'TotoRoot' and expanding the tree from the root until the 3rd level.
|
||||
|
||||
@ -114,6 +116,7 @@ CHANGES:
|
||||
|
||||
version 0.17 (2013-12-xx)
|
||||
- Add CSV and TXT output rendering following the Christian's idea.
|
||||
- Log errors in the standard error console (when launched via command line).
|
||||
|
||||
version 0.16 (2013-01-23)
|
||||
- Fix an issue to prevent the cylcles in the imported files.
|
||||
|
BIN
XSDDiagram.exe
BIN
XSDDiagram.exe
Binary file not shown.
Binary file not shown.
@ -15,6 +15,7 @@ using System.IO;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XSDDiagram.Rendering
|
||||
{
|
||||
@ -57,8 +58,14 @@ namespace XSDDiagram.Rendering
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public bool Export(string outputFilename, Graphics referenceGraphics,
|
||||
public bool Export(string outputFilename, Graphics referenceGraphics,
|
||||
DiagramAlertHandler alerteDelegate)
|
||||
{
|
||||
return Export(outputFilename, referenceGraphics, alerteDelegate, null);
|
||||
}
|
||||
|
||||
public bool Export(string outputFilename, Graphics referenceGraphics,
|
||||
DiagramAlertHandler alerteDelegate, IDictionary<string, object> specificRendererParameters)
|
||||
{
|
||||
string extension = Path.GetExtension(outputFilename).ToLower();
|
||||
if (string.IsNullOrEmpty(extension))
|
||||
@ -68,12 +75,18 @@ namespace XSDDiagram.Rendering
|
||||
}
|
||||
using (FileStream stream = File.Create(outputFilename))
|
||||
{
|
||||
return Export(stream, extension, referenceGraphics, alerteDelegate);
|
||||
return Export(stream, extension, referenceGraphics, alerteDelegate, specificRendererParameters);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Export(Stream stream, string extension, Graphics referenceGraphics,
|
||||
public bool Export(Stream stream, string extension, Graphics referenceGraphics,
|
||||
DiagramAlertHandler alerteDelegate)
|
||||
{
|
||||
return Export(stream, extension, referenceGraphics, alerteDelegate, null);
|
||||
}
|
||||
|
||||
public bool Export(Stream stream, string extension, Graphics referenceGraphics,
|
||||
DiagramAlertHandler alerteDelegate, IDictionary<string, object> specificRendererParameters)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
@ -138,6 +151,10 @@ namespace XSDDiagram.Rendering
|
||||
using (DiagramTxtRenderer renderer = new DiagramTxtRenderer(sw))
|
||||
{
|
||||
renderer.IsCSV = extension.CompareTo(".csv") == 0;
|
||||
IDictionary<string, object> parameters = specificRendererParameters as IDictionary<string, object>;
|
||||
object o;
|
||||
if (parameters != null && parameters.TryGetValue("TextOutputFields", out o))
|
||||
renderer.TextOutputFields = o as IList<string>;
|
||||
renderer.Render(_diagram);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,8 @@ using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XSDDiagram.Rendering
|
||||
{
|
||||
@ -23,6 +25,13 @@ namespace XSDDiagram.Rendering
|
||||
|
||||
private TextWriter _writer;
|
||||
private bool _isCSV;
|
||||
private string _fieldSeparator;
|
||||
private IList<string> _textOutputFields;
|
||||
private IList<string> _finalTextOutputFields;
|
||||
|
||||
private static List<string> fields = new List<string>() {
|
||||
"PATH", "NAME", "TYPE", "NAMESPACE", "COMMENT"
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
@ -70,6 +79,18 @@ namespace XSDDiagram.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
public IList<string> TextOutputFields
|
||||
{
|
||||
get
|
||||
{
|
||||
return _textOutputFields;
|
||||
}
|
||||
set
|
||||
{
|
||||
_textOutputFields = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
@ -79,7 +100,15 @@ namespace XSDDiagram.Rendering
|
||||
public override void BeginItemsRender()
|
||||
{
|
||||
//PATH,NAME,TYPE,NAMESPACE,COMMENT,ATTRIBUT_NAME,ATTRIBUT_TYPE,ATTRIBUT_COMMENT
|
||||
_writer.WriteLine(@"PATH,TYPE,NAMESPACE,COMMENT");
|
||||
//foreach (string field in _finalTextOutputFields)
|
||||
for (int i = 0; i < _finalTextOutputFields.Count; i++)
|
||||
{
|
||||
if(i > 0)
|
||||
_writer.Write(_fieldSeparator);
|
||||
string field = _finalTextOutputFields[i];
|
||||
_writer.Write(field);
|
||||
}
|
||||
_writer.WriteLine();
|
||||
}
|
||||
|
||||
public override void EndItemsRender()
|
||||
@ -88,6 +117,16 @@ namespace XSDDiagram.Rendering
|
||||
|
||||
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)
|
||||
@ -100,452 +139,122 @@ namespace XSDDiagram.Rendering
|
||||
|
||||
public override void Render(DiagramItem drawingItem)
|
||||
{
|
||||
//if (drawingItem.diagram.ShowBoundingBox)
|
||||
//{
|
||||
// int color = 255 - depth * 8;
|
||||
// g.FillRectangle(new SolidBrush(Color.FromArgb(color, color, color)), drawingItem.ScaleRectangle(drawingItem.boundingBox));
|
||||
// g.DrawRectangle(foregroundPen, drawingItem.ScaleRectangle(drawingItem.boundingBox));
|
||||
//}
|
||||
string type = "";
|
||||
if (drawingItem.TabSchema is XMLSchema.element)
|
||||
type = "element";
|
||||
else if (drawingItem.TabSchema is XMLSchema.simpleType)
|
||||
type = "simpleType";
|
||||
else if (drawingItem.TabSchema is XMLSchema.complexType)
|
||||
type = "complexType";
|
||||
|
||||
// Draw the children
|
||||
if (drawingItem.ShowChildElements)
|
||||
if (type.Length > 0)
|
||||
{
|
||||
string path = '/' + drawingItem.Name;
|
||||
DiagramItem parentElement = drawingItem.Parent;
|
||||
while (parentElement != null)
|
||||
{
|
||||
//if (parentElement.ItemType == DiagramItemType.element && !string.IsNullOrEmpty(parentElement.Name))
|
||||
if ((type == "element" || type == "simpleType" || type == "complexType") && !string.IsNullOrEmpty(parentElement.Name))
|
||||
path = '/' + parentElement.Name + path;
|
||||
parentElement = parentElement.Parent;
|
||||
}
|
||||
|
||||
string comment = "";
|
||||
XMLSchema.annotated annotated = drawingItem.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)
|
||||
{
|
||||
string text = documentation.Any[0].Value;
|
||||
text = text.Replace("\n", " ");
|
||||
text = text.Replace("\t", " ");
|
||||
text = text.Replace("\r", "");
|
||||
text = Regex.Replace(text, " +", " ");
|
||||
text = text.Trim();
|
||||
comment = text;
|
||||
}
|
||||
else if (documentation.source != null)
|
||||
{
|
||||
comment = documentation.source;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _finalTextOutputFields.Count; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
_writer.Write(_fieldSeparator);
|
||||
string field = _finalTextOutputFields[i];
|
||||
switch (field)
|
||||
{
|
||||
case "PATH": _writer.Write(path); break;
|
||||
case "NAME": _writer.Write(drawingItem.Name); break;
|
||||
case "TYPE": _writer.Write(type); break;
|
||||
case "NAMESPACE": _writer.Write(drawingItem.NameSpace); break;
|
||||
case "COMMENT": _writer.Write(comment); break;
|
||||
}
|
||||
}
|
||||
_writer.WriteLine();
|
||||
|
||||
|
||||
//// Draw the inheritor line
|
||||
//if (drawingItem.InheritFrom != null)
|
||||
//{
|
||||
//}
|
||||
|
||||
//switch (drawingItem.ItemType)
|
||||
//{
|
||||
// case DiagramItemType.element:
|
||||
// break;
|
||||
|
||||
// case DiagramItemType.type:
|
||||
// break;
|
||||
|
||||
// case DiagramItemType.group:
|
||||
// {
|
||||
// // Draw the main shape following the min/max occurences
|
||||
|
||||
// // Draw the group type
|
||||
// switch (drawingItem.GroupType)
|
||||
// {
|
||||
// case DiagramItemGroupType.Sequence: break;
|
||||
// case DiagramItemGroupType.Choice: break;
|
||||
// case DiagramItemGroupType.All: break;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
//// Draw text
|
||||
//if (drawingItem.Name.Length > 0)
|
||||
//{
|
||||
// //drawingItem.Name;
|
||||
//}
|
||||
|
||||
//// Draw occurences small text
|
||||
//if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1) {}
|
||||
|
||||
//// Draw type
|
||||
//if (drawingItem.IsSimpleContent) {}
|
||||
|
||||
//// Draw reference arrow
|
||||
//if (drawingItem.IsReference) {}
|
||||
}
|
||||
|
||||
// Draw children expand box
|
||||
if (drawingItem.HasChildElements && drawingItem.ShowChildElements)
|
||||
{
|
||||
foreach (DiagramItem element in drawingItem.ChildElements)
|
||||
{
|
||||
this.Render(element);
|
||||
_writer.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
string backgroundBrush = "fill:rgb(255,255,255)";
|
||||
string foregroundColor = "rgb(0,0,0)";
|
||||
string foregroundBrush = "fill:" + foregroundColor;
|
||||
string foregroundPen = "stroke:" + foregroundColor + ";stroke-width:1";
|
||||
string foregroundRoundPen = foregroundPen + ";stroke-linecap:round";
|
||||
string dashed = "stroke-dasharray:4,1";
|
||||
|
||||
Rectangle scaledElementBox = drawingItem.ScaleRectangle(drawingItem.ElementBox);
|
||||
|
||||
// Draw the children lines
|
||||
if (drawingItem.ShowChildElements)
|
||||
{
|
||||
if (drawingItem.ChildElements.Count == 1)
|
||||
{
|
||||
int parentMidleY = drawingItem.ScaleInt(drawingItem.Location.Y + drawingItem.Size.Height / 2);
|
||||
this.SVGLine(foregroundRoundPen,
|
||||
drawingItem.ScaleInt(drawingItem.Location.X + drawingItem.Size.Width),
|
||||
parentMidleY, drawingItem.ScaleInt(drawingItem.ChildElements[0].Location.X), parentMidleY);
|
||||
}
|
||||
else if (drawingItem.ChildElements.Count > 1)
|
||||
{
|
||||
DiagramItem firstElement = drawingItem.ChildElements[0];
|
||||
DiagramItem lastElement = drawingItem.ChildElements[drawingItem.ChildElements.Count - 1];
|
||||
int verticalLine = drawingItem.ScaleInt(firstElement.BoundingBox.Left);
|
||||
|
||||
foreach (DiagramItem element in drawingItem.ChildElements)
|
||||
{
|
||||
if (element.InheritFrom == null)
|
||||
{
|
||||
int currentMidleY = drawingItem.ScaleInt(element.Location.Y + element.Size.Height / 2);
|
||||
SVGLine(foregroundRoundPen, verticalLine, currentMidleY,
|
||||
drawingItem.ScaleInt(element.Location.X), currentMidleY);
|
||||
}
|
||||
}
|
||||
|
||||
int parentMidleY = drawingItem.ScaleInt(drawingItem.Location.Y + drawingItem.Size.Height / 2);
|
||||
int firstMidleY = drawingItem.ScaleInt(firstElement.Location.Y + firstElement.Size.Height / 2);
|
||||
firstMidleY = Math.Min(firstMidleY, parentMidleY);
|
||||
int lastMidleY = drawingItem.ScaleInt(lastElement.Location.Y + lastElement.Size.Height / 2);
|
||||
lastMidleY = Math.Max(lastMidleY, parentMidleY);
|
||||
this.SVGLine(foregroundRoundPen, verticalLine, firstMidleY, verticalLine, lastMidleY);
|
||||
this.SVGLine(foregroundRoundPen,
|
||||
drawingItem.ScaleInt(drawingItem.Location.X + drawingItem.Size.Width),
|
||||
parentMidleY, verticalLine, parentMidleY);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the inheritor line
|
||||
if (drawingItem.InheritFrom != null)
|
||||
{
|
||||
string foregroundInheritPen = foregroundPen + ";" + dashed;
|
||||
|
||||
Point p1 = new Point(drawingItem.ScaleInt(drawingItem.InheritFrom.Location.X - 5),
|
||||
drawingItem.ScaleInt(drawingItem.InheritFrom.Location.Y + drawingItem.InheritFrom.Size.Height + 5));
|
||||
Point p2 = new Point(drawingItem.ScaleInt(drawingItem.Location.X - 5),
|
||||
drawingItem.ScaleInt(drawingItem.Location.Y - 5));
|
||||
this.SVGLine(foregroundInheritPen, p1, p2);
|
||||
this.SVGLine(foregroundInheritPen, p2,
|
||||
new Point(drawingItem.ScaleInt(drawingItem.Location.X), drawingItem.ScaleInt(drawingItem.Location.Y)));
|
||||
|
||||
Point targetPoint = new Point(drawingItem.ScaleInt(drawingItem.InheritFrom.Location.X - 3),
|
||||
drawingItem.ScaleInt(drawingItem.InheritFrom.Location.Y + drawingItem.InheritFrom.Size.Height + 3));
|
||||
SVGLine(foregroundInheritPen, targetPoint, p1);
|
||||
Point[] pathPoint = new Point[5];
|
||||
pathPoint[0] = targetPoint;
|
||||
pathPoint[1] = targetPoint;
|
||||
pathPoint[1].X += drawingItem.ScaleInt(2);
|
||||
pathPoint[1].Y += drawingItem.ScaleInt(2);
|
||||
pathPoint[2] = targetPoint;
|
||||
pathPoint[2].X += drawingItem.ScaleInt(3);
|
||||
pathPoint[2].Y -= drawingItem.ScaleInt(3);
|
||||
pathPoint[3] = targetPoint;
|
||||
pathPoint[3].X -= drawingItem.ScaleInt(2);
|
||||
pathPoint[3].Y -= drawingItem.ScaleInt(2);
|
||||
pathPoint[4] = targetPoint;
|
||||
|
||||
string path = SVGPolygonToDrawCommand(pathPoint);
|
||||
SVGPath(backgroundBrush + ";" + foregroundPen, path);
|
||||
}
|
||||
|
||||
switch (drawingItem.ItemType)
|
||||
{
|
||||
case DiagramItemType.element:
|
||||
{
|
||||
// Draw the main shape following the min/max occurences
|
||||
string foregroundBoxPen = foregroundPen;
|
||||
|
||||
if (drawingItem.MinOccurrence == 0)
|
||||
{
|
||||
foregroundBoxPen += ";" + dashed;
|
||||
}
|
||||
if (drawingItem.MaxOccurrence == 1)
|
||||
{
|
||||
SVGRectangle(backgroundBrush + ";" + foregroundBoxPen, scaledElementBox);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rectangle elementBoxShifted = scaledElementBox;
|
||||
elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
|
||||
this.SVGRectangle(backgroundBrush + ";" + foregroundBoxPen, elementBoxShifted);
|
||||
this.SVGRectangle(backgroundBrush + ";" + foregroundBoxPen, scaledElementBox);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DiagramItemType.type:
|
||||
{
|
||||
// Draw the main shape following the min/max occurences
|
||||
int bevel = (int)(scaledElementBox.Height * 0.30);
|
||||
Point[] pathPoint = new Point[6];
|
||||
pathPoint[0] = pathPoint[5] = scaledElementBox.Location;
|
||||
pathPoint[1] = scaledElementBox.Location;
|
||||
pathPoint[1].X = scaledElementBox.Right;
|
||||
pathPoint[2] = scaledElementBox.Location + scaledElementBox.Size;
|
||||
pathPoint[3] = scaledElementBox.Location;
|
||||
pathPoint[3].Y = scaledElementBox.Bottom;
|
||||
pathPoint[4] = pathPoint[3];
|
||||
pathPoint[0].X += bevel;
|
||||
pathPoint[3].X += bevel;
|
||||
pathPoint[4].Y -= bevel;
|
||||
pathPoint[5].Y += bevel;
|
||||
|
||||
string path = SVGPolygonToDrawCommand(pathPoint);
|
||||
|
||||
Point[] pathPointShifted = new Point[6];
|
||||
Size scaledShiftedBevel = drawingItem.ScaleSize(new Size(3, 3));
|
||||
for (int i = 0; i < pathPoint.Length; i++)
|
||||
pathPointShifted[i] = pathPoint[i] + scaledShiftedBevel;
|
||||
|
||||
string pathShifted = SVGPolygonToDrawCommand(pathPointShifted);
|
||||
|
||||
string foregroundBoxPen = foregroundPen;
|
||||
if (drawingItem.MinOccurrence == 0)
|
||||
{
|
||||
foregroundBoxPen += ";" + dashed;
|
||||
}
|
||||
if (drawingItem.MaxOccurrence == 1)
|
||||
{
|
||||
SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rectangle elementBoxShifted = scaledElementBox;
|
||||
elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
|
||||
this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, pathShifted);
|
||||
this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DiagramItemType.group:
|
||||
{
|
||||
// Draw the main shape following the min/max occurences
|
||||
int bevel = (int)(scaledElementBox.Height * 0.30);
|
||||
Point[] pathPoint = new Point[8];
|
||||
pathPoint[0] = pathPoint[7] = scaledElementBox.Location;
|
||||
pathPoint[1] = scaledElementBox.Location;
|
||||
pathPoint[1].X = scaledElementBox.Right; pathPoint[2] = pathPoint[1];
|
||||
pathPoint[3] = pathPoint[4] = scaledElementBox.Location + scaledElementBox.Size;
|
||||
pathPoint[5] = scaledElementBox.Location;
|
||||
pathPoint[5].Y = scaledElementBox.Bottom;
|
||||
pathPoint[6] = pathPoint[5];
|
||||
pathPoint[0].X += bevel;
|
||||
pathPoint[1].X -= bevel;
|
||||
pathPoint[2].Y += bevel;
|
||||
pathPoint[3].Y -= bevel;
|
||||
pathPoint[4].X -= bevel;
|
||||
pathPoint[5].X += bevel;
|
||||
pathPoint[6].Y -= bevel;
|
||||
pathPoint[7].Y += bevel;
|
||||
|
||||
string path = SVGPolygonToDrawCommand(pathPoint);
|
||||
|
||||
Point[] pathPointShifted = new Point[8];
|
||||
Size scaledShiftedBevel = drawingItem.ScaleSize(new Size(3, 3));
|
||||
for (int i = 0; i < pathPoint.Length; i++)
|
||||
pathPointShifted[i] = pathPoint[i] + scaledShiftedBevel;
|
||||
|
||||
string pathShifted = this.SVGPolygonToDrawCommand(pathPointShifted);
|
||||
|
||||
|
||||
string foregroundBoxPen = foregroundPen;
|
||||
if (drawingItem.MinOccurrence == 0)
|
||||
{
|
||||
foregroundBoxPen += ";" + dashed;
|
||||
}
|
||||
if (drawingItem.MaxOccurrence == 1)
|
||||
{
|
||||
this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, pathShifted);
|
||||
this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
|
||||
}
|
||||
|
||||
// Draw the group type
|
||||
switch (drawingItem.GroupType)
|
||||
{
|
||||
case DiagramItemGroupType.Sequence:
|
||||
{
|
||||
Point p0 = drawingItem.Location + new Size(0, drawingItem.ElementBox.Height / 2);
|
||||
Point p1 = p0 + new Size(3, 0);
|
||||
Point p2 = p1 + new Size(drawingItem.ElementBox.Width - 6, 0);
|
||||
SVGLine(foregroundPen, drawingItem.ScalePoint(p1), drawingItem.ScalePoint(p2));
|
||||
Point point2 = p0 + new Size(drawingItem.ElementBox.Width / 2, 0);
|
||||
Point point1 = point2 + new Size(-5, 0);
|
||||
Point point3 = point2 + new Size(+5, 0);
|
||||
Size pointSize = new Size(4, 4);
|
||||
Size pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
|
||||
point1 -= pointSize2;
|
||||
point2 -= pointSize2;
|
||||
point3 -= pointSize2;
|
||||
pointSize = drawingItem.ScaleSize(pointSize);
|
||||
SVGEllipse(foregroundColor, new Rectangle(drawingItem.ScalePoint(point1), pointSize));
|
||||
SVGEllipse(foregroundColor, new Rectangle(drawingItem.ScalePoint(point2), pointSize));
|
||||
SVGEllipse(foregroundColor, new Rectangle(drawingItem.ScalePoint(point3), pointSize));
|
||||
|
||||
//Point p0 = drawingItem.Location + new Size(0, drawingItem.ElementBox.Height / 2);
|
||||
//Point point0 = p0 + new Size(3, 0);
|
||||
//Point point2 = p0 + new Size(drawingItem.ElementBox.Width / 2, 0);
|
||||
//Point point1 = point2 + new Size(-5, 0);
|
||||
//Point point3 = point2 + new Size(+5, 0);
|
||||
//Point point4 = point0 + new Size(drawingItem.ElementBox.Width - 6, 0);
|
||||
|
||||
//Pen foregroundBallPen = new Pen(foreground);
|
||||
//foregroundBallPen.EndCap = LineCap.RoundAnchor;
|
||||
////foregroundBallPen.ScaleTransform(1.0f / drawingItem.diagram.Scale, 1.0f / drawingItem.diagram.Scale);
|
||||
//foregroundBallPen.ScaleTransform(drawingItem.diagram.Scale, drawingItem.diagram.Scale);
|
||||
|
||||
//SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point0), drawingItem.ScalePoint(point1));
|
||||
//SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point1), drawingItem.ScalePoint(point2));
|
||||
//SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point2), drawingItem.ScalePoint(point3));
|
||||
//foregroundBallPen.EndCap = LineCap.Flat;
|
||||
//SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point3), drawingItem.ScalePoint(point4));
|
||||
}
|
||||
break;
|
||||
case DiagramItemGroupType.Choice:
|
||||
{
|
||||
int yMiddle = drawingItem.ElementBox.Y + drawingItem.ElementBox.Height / 2;
|
||||
int yUp = yMiddle - 4;
|
||||
int yDown = yMiddle + 4;
|
||||
int xMiddle = drawingItem.ElementBox.X + drawingItem.ElementBox.Width / 2;
|
||||
int xLeft2 = xMiddle - 4;
|
||||
int xLeft1 = xLeft2 - 4;
|
||||
int xLeft0 = xLeft1 - 4;
|
||||
int xRight0 = xMiddle + 4;
|
||||
int xRight1 = xRight0 + 4;
|
||||
int xRight2 = xRight1 + 4;
|
||||
|
||||
Point point1 = new Point(xMiddle, yUp);
|
||||
Point point2 = new Point(xMiddle, yMiddle);
|
||||
Point point3 = new Point(xMiddle, yDown);
|
||||
Size pointSize = new Size(4, 4);
|
||||
Size pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
|
||||
point1 -= pointSize2;
|
||||
point2 -= pointSize2;
|
||||
point3 -= pointSize2;
|
||||
pointSize = drawingItem.ScaleSize(pointSize);
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xLeft0, yMiddle)),
|
||||
drawingItem.ScalePoint(new Point(xLeft1, yMiddle)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xLeft1, yMiddle)),
|
||||
drawingItem.ScalePoint(new Point(xLeft2, yUp)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xRight0, yUp)),
|
||||
drawingItem.ScalePoint(new Point(xRight1, yUp)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xRight0, yMiddle)),
|
||||
drawingItem.ScalePoint(new Point(xRight2, yMiddle)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xRight0, yDown)),
|
||||
drawingItem.ScalePoint(new Point(xRight1, yDown)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xRight1, yUp)),
|
||||
drawingItem.ScalePoint(new Point(xRight1, yDown)));
|
||||
SVGEllipse(foregroundColor,
|
||||
new Rectangle(drawingItem.ScalePoint(point1), pointSize));
|
||||
SVGEllipse(foregroundColor,
|
||||
new Rectangle(drawingItem.ScalePoint(point2), pointSize));
|
||||
SVGEllipse(foregroundColor,
|
||||
new Rectangle(drawingItem.ScalePoint(point3), pointSize));
|
||||
}
|
||||
break;
|
||||
case DiagramItemGroupType.All:
|
||||
{
|
||||
int yMiddle = drawingItem.ElementBox.Y + drawingItem.ElementBox.Height / 2;
|
||||
int yUp = yMiddle - 4;
|
||||
int yDown = yMiddle + 4;
|
||||
int xMiddle = drawingItem.ElementBox.X + drawingItem.ElementBox.Width / 2;
|
||||
int xLeft2 = xMiddle - 4;
|
||||
int xLeft1 = xLeft2 - 4;
|
||||
int xLeft0 = xLeft1 - 4;
|
||||
int xRight0 = xMiddle + 4;
|
||||
int xRight1 = xRight0 + 4;
|
||||
int xRight2 = xRight1 + 4;
|
||||
|
||||
Point point1 = new Point(xMiddle, yUp);
|
||||
Point point2 = new Point(xMiddle, yMiddle);
|
||||
Point point3 = new Point(xMiddle, yDown);
|
||||
Size pointSize = new Size(4, 4);
|
||||
Size pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
|
||||
point1 -= pointSize2;
|
||||
point2 -= pointSize2;
|
||||
point3 -= pointSize2;
|
||||
pointSize = drawingItem.ScaleSize(pointSize);
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xLeft2, yUp)),
|
||||
drawingItem.ScalePoint(new Point(xLeft1, yUp)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xLeft2, yMiddle)),
|
||||
drawingItem.ScalePoint(new Point(xLeft0, yMiddle)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xLeft2, yDown)),
|
||||
drawingItem.ScalePoint(new Point(xLeft1, yDown)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xLeft1, yUp)),
|
||||
drawingItem.ScalePoint(new Point(xLeft1, yDown)));
|
||||
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xRight0, yUp)),
|
||||
drawingItem.ScalePoint(new Point(xRight1, yUp)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xRight0, yMiddle)),
|
||||
drawingItem.ScalePoint(new Point(xRight2, yMiddle)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xRight0, yDown)),
|
||||
drawingItem.ScalePoint(new Point(xRight1, yDown)));
|
||||
SVGLine(foregroundPen,
|
||||
drawingItem.ScalePoint(new Point(xRight1, yUp)),
|
||||
drawingItem.ScalePoint(new Point(xRight1, yDown)));
|
||||
SVGEllipse(foregroundColor,
|
||||
new Rectangle(drawingItem.ScalePoint(point1), pointSize));
|
||||
SVGEllipse(foregroundColor,
|
||||
new Rectangle(drawingItem.ScalePoint(point2), pointSize));
|
||||
SVGEllipse(foregroundColor,
|
||||
new Rectangle(drawingItem.ScalePoint(point3), pointSize));
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float fontScale = 0.8f;
|
||||
|
||||
// Draw text
|
||||
if (drawingItem.Name.Length > 0)
|
||||
{
|
||||
string style = String.Format(
|
||||
"font-family:{0};font-size:{1}pt;fill:{2};font-weight:bold;text-anchor:middle;dominant-baseline:central",
|
||||
drawingItem.Font.Name, drawingItem.Font.Size * fontScale, foregroundColor);
|
||||
SVGText(drawingItem.Name, style,
|
||||
new Rectangle(scaledElementBox.X, scaledElementBox.Y, scaledElementBox.Width, scaledElementBox.Height));
|
||||
}
|
||||
|
||||
// Draw occurences small text
|
||||
if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1)
|
||||
{
|
||||
string occurences = String.Format("{0}..", drawingItem.MinOccurrence) +
|
||||
(drawingItem.MaxOccurrence == -1 ? "∞" : string.Format("{0}", drawingItem.MaxOccurrence));
|
||||
PointF pointOccurences = new PointF();
|
||||
pointOccurences.X = drawingItem.Diagram.Scale * (drawingItem.Location.X + drawingItem.Size.Width - 10);
|
||||
pointOccurences.Y = drawingItem.Diagram.Scale * (drawingItem.Location.Y + drawingItem.Size.Height + 10);
|
||||
string style = String.Format(
|
||||
"font-family:{0};font-size:{1}pt;fill:{2};text-anchor:end;dominant-baseline:central",
|
||||
drawingItem.SmallFont.Name, drawingItem.SmallFont.Size * fontScale, foregroundColor);
|
||||
SVGText(occurences, style, new Point((int)pointOccurences.X, (int)pointOccurences.Y));
|
||||
}
|
||||
|
||||
// Draw type
|
||||
if (drawingItem.IsSimpleContent)
|
||||
{
|
||||
Point currentPoint = scaledElementBox.Location + new Size(2, 2);
|
||||
SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(8), 0));
|
||||
currentPoint += new Size(0, 2);
|
||||
SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
|
||||
currentPoint += new Size(0, 2);
|
||||
SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
|
||||
currentPoint += new Size(0, 2);
|
||||
SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
|
||||
}
|
||||
|
||||
// Draw reference arrow
|
||||
if (drawingItem.IsReference)
|
||||
{
|
||||
string arrowPen = String.Format("stroke:{0};stroke-width:{1}",
|
||||
foregroundColor, drawingItem.Diagram.Scale * 2.0f);
|
||||
Point basePoint = new Point(drawingItem.ElementBox.Left + 1, drawingItem.ElementBox.Bottom - 1);
|
||||
Point targetPoint = basePoint + new Size(3, -3);
|
||||
basePoint = drawingItem.ScalePoint(basePoint);
|
||||
targetPoint = drawingItem.ScalePoint(targetPoint);
|
||||
SVGLine(arrowPen, basePoint, targetPoint);
|
||||
|
||||
Point[] pathPoint = new Point[5];
|
||||
pathPoint[0] = targetPoint;
|
||||
pathPoint[1] = targetPoint;
|
||||
pathPoint[1].X += drawingItem.ScaleInt(2);
|
||||
pathPoint[1].Y += drawingItem.ScaleInt(2);
|
||||
pathPoint[2] = targetPoint;
|
||||
pathPoint[2].X += drawingItem.ScaleInt(3);
|
||||
pathPoint[2].Y -= drawingItem.ScaleInt(3);
|
||||
pathPoint[3] = targetPoint;
|
||||
pathPoint[3].X -= drawingItem.ScaleInt(2);
|
||||
pathPoint[3].Y -= drawingItem.ScaleInt(2);
|
||||
pathPoint[4] = targetPoint;
|
||||
|
||||
string path = SVGPolygonToDrawCommand(pathPoint);
|
||||
SVGPath(foregroundBrush, path);
|
||||
}
|
||||
|
||||
// Draw children expand box
|
||||
if (drawingItem.HasChildElements)
|
||||
{
|
||||
Rectangle scaledChildExpandButtonBox = drawingItem.ScaleRectangle(drawingItem.ChildExpandButtonBox);
|
||||
SVGRectangle(backgroundBrush + ";" + foregroundPen, scaledChildExpandButtonBox);
|
||||
|
||||
Point middle = new Point(scaledChildExpandButtonBox.Width / 2, scaledChildExpandButtonBox.Height / 2);
|
||||
int borderPadding = Math.Max(2, drawingItem.ScaleInt(2));
|
||||
|
||||
Point p1 = scaledChildExpandButtonBox.Location + new Size(borderPadding, middle.Y);
|
||||
Point p2 = new Point(scaledChildExpandButtonBox.Right - borderPadding, p1.Y);
|
||||
SVGLine(foregroundPen, p1, p2);
|
||||
if (!drawingItem.ShowChildElements)
|
||||
{
|
||||
p1 = scaledChildExpandButtonBox.Location + new Size(middle.X, borderPadding);
|
||||
p2 = new Point(p1.X, scaledChildExpandButtonBox.Bottom - borderPadding);
|
||||
SVGLine(foregroundPen, p1, p2);
|
||||
//_writer.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -554,58 +263,6 @@ namespace XSDDiagram.Rendering
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void SVGLine(string pen, Point pt1, Point pt2)
|
||||
{
|
||||
this.SVGLine(pen, pt1.X, pt1.Y, pt2.X, pt2.Y);
|
||||
}
|
||||
|
||||
private void SVGLine(string pen, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
_writer.WriteLine("<line x1=\"{0}\" y1=\"{1}\" x2=\"{2}\" y2=\"{3}\" style=\"{4}\"/>",
|
||||
x1, y1, x2, y2, pen);
|
||||
}
|
||||
|
||||
private void SVGRectangle(string pen, Rectangle rect)
|
||||
{
|
||||
_writer.WriteLine("<rect x=\"{0}\" y=\"{1}\" width=\"{2}\" height=\"{3}\" style=\"{4}\"/>",
|
||||
rect.X, rect.Y, rect.Width, rect.Height, pen);
|
||||
}
|
||||
|
||||
private void SVGEllipse(string brush, Rectangle rect)
|
||||
{
|
||||
_writer.WriteLine("<ellipse cx=\"{0}\" cy=\"{1}\" rx=\"{2}\" ry=\"{3}\" style=\"{4}\"/>",
|
||||
rect.X + rect.Width / 2, rect.Y + rect.Height / 2, rect.Width / 2, rect.Height / 2, brush);
|
||||
}
|
||||
|
||||
private void SVGPath(string style, string drawCommand)
|
||||
{
|
||||
_writer.WriteLine("<path d=\"{0}\" style=\"{1}\"/>", drawCommand, style);
|
||||
}
|
||||
|
||||
private void SVGText(string text, string style, Point point)
|
||||
{
|
||||
_writer.WriteLine("<text x=\"{0}\" y=\"{1}\" style=\"{2}\">{3}</text>",
|
||||
point.X, point.Y, style, text);
|
||||
}
|
||||
|
||||
private void SVGText(string text, string style, Rectangle rect)
|
||||
{
|
||||
_writer.WriteLine("<text x=\"{0}\" y=\"{1}\" style=\"{2}\">{3}</text>",
|
||||
rect.X + rect.Width / 2.0, rect.Y + rect.Height / 2.0, style, text);
|
||||
}
|
||||
|
||||
private string SVGPolygonToDrawCommand(Point[] pathPoint)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < pathPoint.Length; i++)
|
||||
{
|
||||
result.AppendFormat("{0}{1} {2} ", i == 0 ? 'M' : 'L', pathPoint[i].X, pathPoint[i].Y);
|
||||
}
|
||||
result.Append('Z');
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
Loading…
Reference in New Issue
Block a user