Skip to content

Commit

Permalink
Add the fields SEQ,LASTCHILD,XSDTYPE when rendering to a txt or csv f…
Browse files Browse the repository at this point in the history
…ile (#22).
  • Loading branch information
dgis committed Oct 21, 2019
1 parent 38596b8 commit 3bec6a6
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 30 deletions.
14 changes: 9 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// XSDDiagram - A XML Schema Definition file viewer
// Copyright (C) 2006-2011 Regis COSNIER
// Copyright (C) 2006-2019 Regis COSNIER
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -35,7 +35,7 @@ public static class Program
//static extern bool AllocConsole();

static string usage = @"XSD Diagram, version {0}
Usage: {1} [-o output.svg] [-os EXTENSION] [-r RootElement[@namespace]]* [-e N] [-d] [-z N] [-f PATH,NAME,TYPE,NAMESPACE,COMMENT] [-a] [-y] [-u USERNAME] [-p PASSWORD] [file.xsd or URL]
Usage: {1} [-o output.svg] [-os EXTENSION] [-r RootElement[@namespace]]* [-e N] [-d] [-z N] [-f PATH,NAME,TYPE,NAMESPACE,COMMENT,SEQ,LASTCHILD,XSDTYPE] [-a] [-y] [-u USERNAME] [-p PASSWORD] [file.xsd or URL]
-o FILE
specifies the output image. '.png','.jpg', '.svg', '.txt', '.csv' ('.emf' on Windows) are allowed.
Expand All @@ -56,8 +56,8 @@ Display the documentation.
-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.
-f PATH,NAME,TYPE,NAMESPACE,COMMENT,SEQ,LASTCHILD,XSDTYPE
specifies the fields you want to output when rendering to a txt or csv file.
-a
outputs the attributes in text mode only (.txt and .csv).
-y
Expand Down Expand Up @@ -189,7 +189,11 @@ public static void Main()
for (int i = 0; i < Options.ExpandLevel; i++)
{
Log("Expanding to level {0}...\n", i + 1);
diagram.ExpandOneLevel();
if (!diagram.ExpandOneLevel())
{
Log("Cannot expand more.\n");
break;
}
}
diagram.Layout(graphics);
Log("Saving image...\n");
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("XSD Diagram")]
[assembly: AssemblyCopyright("Copyright © 2006-2018 Regis Cosnier, All Rights Reserved.")]
[assembly: AssemblyCopyright("Copyright © 2006-2019 Regis Cosnier, All Rights Reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
14 changes: 9 additions & 5 deletions ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
XSD Diagram is a free xml schema definition diagram viewer (http://regis.cosnier.free.fr).

Version 1.2 Copyright (c) 2006-2018 Regis Cosnier, All Rights Reserved.
Version 1.3alpha Copyright (c) 2006-2019 Regis Cosnier, All Rights Reserved.

This program is free software and may be distributed
according to the terms of the GNU General Public License (GPL).
Expand Down Expand Up @@ -40,7 +40,7 @@ COMMAND LINE USAGE:

or on Windows use 'XSDDiagramConsole.exe' instead of 'XSDDiagram.exe' if you need the console:

> XSDDiagramConsole.exe [-o output.svg] [-os EXTENSION] [-r RootElement[@namespace]]* [-e N] [-d] [-z N] [-f PATH,NAME,TYPE,NAMESPACE,COMMENT] [-a] [-y] [-u USERNAME] [-p PASSWORD] [file.xsd or URL]
> XSDDiagramConsole.exe [-o output.svg] [-os EXTENSION] [-r RootElement[@namespace]]* [-e N] [-d] [-z N] [-f PATH,NAME,TYPE,NAMESPACE,COMMENT,SEQ,LASTCHILD,XSDTYPE] [-a] [-y] [-u USERNAME] [-p PASSWORD] [file.xsd or URL]

Options:

Expand All @@ -62,8 +62,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.
-f PATH,NAME,TYPE,NAMESPACE,COMMENT,SEQ,LASTCHILD,XSDTYPE
specifies the fields you want to output when rendering to a txt or csv file.
-a
outputs the attributes in text mode only (.txt and .csv).
-y
Expand Down Expand Up @@ -139,6 +139,9 @@ TODO LIST:

CHANGES:

version 1.3 (2019-10-XX)
- Add the fields SEQ,LASTCHILD,XSDTYPE when rendering to a txt or csv file (https://github.com/dgis/xsddiagram/issues/22).

version 1.2 (2018-06-19)
- Add infer XSD from XML menu.
- Fix a null reference exception in the documentation (Thanks Mario M.).
Expand Down Expand Up @@ -272,7 +275,7 @@ version 0.1 (2006-09-14)

LICENSE:

Copyright (c) 2006-2018 Regis COSNIER, All Rights Reserved.
Copyright (c) 2006-2019 Regis COSNIER, All Rights Reserved.

This program is free software and may be distributed
according to the terms of the GNU General Public License (GPL).
Expand All @@ -284,6 +287,7 @@ Regis Cosnier (Initial developer)
Mathieu Malaterre (Debian and Ubuntu package)
Paul Selormey (Refactoring)
Edu Serna (searching feature)
TCH68k (for the text fileds: SEQ,LASTCHILD,XSDTYPE)
Adrian Covrig
Hermann Swart
Arjan Kloosterboer
Expand Down
Binary file modified XSDDiagram.exe
Binary file not shown.
Binary file modified XSDDiagramConsole.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions XSDDiagrams/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("XSD Diagrams")]
[assembly: AssemblyCopyright("Copyright © 2011-2015 Regis Cosnier, All Rights Reserved.")]
[assembly: AssemblyCopyright("Copyright © 2011-2019 Regis Cosnier, All Rights Reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
26 changes: 17 additions & 9 deletions XSDDiagrams/Rendering/Diagram.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// XSDDiagram - A XML Schema Definition file viewer
// Copyright (C) 2006-2011 Regis COSNIER
// Copyright (C) 2006-2019 Regis COSNIER
//
// The content of this file is subject to the terms of either
// the GNU Lesser General Public License only (LGPL) or
Expand Down Expand Up @@ -434,17 +434,19 @@ public void RemoveAll()
_rootElements.Clear();
}

public void ExpandOneLevel()
public bool ExpandOneLevel()
{
bool result = false;
foreach (DiagramItem item in _rootElements)
{
this.ExpandOneLevel(item);
result |= this.ExpandOneLevel(item);

if (item.HasChildElements && item.ChildElements.Count == 0)
{
this.ExpandChildren(item);
result |= this.ExpandChildren(item);
}
}
return result;
}

public void Clear()
Expand Down Expand Up @@ -592,11 +594,13 @@ public Rectangle ScaleRectangle(Rectangle rectangle)
(int)Math.Round(rectangle.Height * this.Scale));
}

public void ExpandChildren(DiagramItem parentDiagramElement)
public bool ExpandChildren(DiagramItem parentDiagramElement)
{
bool result = false;
ClearSearch();
if (parentDiagramElement.ItemType == DiagramItemType.element || parentDiagramElement.ItemType == DiagramItemType.type)
{
result = true;
DiagramItem diagramElement = parentDiagramElement;
if (diagramElement.TabSchema is XMLSchema.element)
{
Expand Down Expand Up @@ -641,7 +645,8 @@ public void ExpandChildren(DiagramItem parentDiagramElement)
}
else if (parentDiagramElement.ItemType == DiagramItemType.group)
{
DiagramItem diagramCompositors = parentDiagramElement;
result = true;
DiagramItem diagramCompositors = parentDiagramElement;
XMLSchema.group group = diagramCompositors.TabSchema as XMLSchema.group;

if (group.Items != null)
Expand Down Expand Up @@ -683,6 +688,7 @@ public void ExpandChildren(DiagramItem parentDiagramElement)
AddAny(diagramCompositors, null, diagramCompositors.NameSpace);
}
}
return result;
}

public void SelectElement(DiagramItem element)
Expand Down Expand Up @@ -919,18 +925,20 @@ private void ExpandComplexType(DiagramItem parentDiagramElement,
}
}

private void ExpandOneLevel(DiagramItem parentItem)
private bool ExpandOneLevel(DiagramItem parentItem)
{
bool result = false;
ClearSearch();
foreach (DiagramItem item in parentItem.ChildElements)
{
this.ExpandOneLevel(item);
result |= this.ExpandOneLevel(item);

if (item.HasChildElements && item.ChildElements.Count == 0)
{
this.ExpandChildren(item);
result |= this.ExpandChildren(item);
}
}
return result;
}

#endregion
Expand Down
46 changes: 41 additions & 5 deletions XSDDiagrams/Rendering/DiagramTxtRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// XSDDiagram - A XML Schema Definition file viewer
// Copyright (C) 2006-2011 Regis COSNIER
// Copyright (C) 2006-2019 Regis COSNIER
//
// The content of this file is subject to the terms of either
// the GNU Lesser General Public License only (LGPL) or
Expand Down Expand Up @@ -32,7 +32,7 @@ public sealed class DiagramTxtRenderer : DiagramRenderer
private Schema _schema;

private static List<string> fields = new List<string>() {
"PATH", "NAME", "TYPE", "NAMESPACE", "COMMENT"
"PATH", "NAME", "TYPE", "NAMESPACE", "COMMENT", "SEQ", "LASTCHILD", "XSDTYPE"
};

#endregion
Expand All @@ -53,11 +53,13 @@ public DiagramTxtRenderer(TextWriter writer)

#region Public Properties

public bool iteratingLastChild;

public override string Name
{
get
{
return "SVG";
return "TXT";
}
}

Expand Down Expand Up @@ -124,7 +126,7 @@ public Schema Schema

public override void BeginItemsRender()
{
//PATH,NAME,TYPE,NAMESPACE,COMMENT,ATTRIBUT_NAME,ATTRIBUT_TYPE,ATTRIBUT_COMMENT
//PATH,NAME,TYPE,NAMESPACE,COMMENT,SEQ,LASTCHILD,XSDTYPE,ATTRIBUT_NAME,ATTRIBUT_TYPE,ATTRIBUT_COMMENT
//foreach (string field in _finalTextOutputFields)
for (int i = 0; i < _finalTextOutputFields.Count; i++)
{
Expand Down Expand Up @@ -157,9 +159,10 @@ public override void Render(Diagram diagram)
_finalTextOutputFields.Add(field);

this.BeginItemsRender();

int c = 0;
foreach (DiagramItem element in diagram.RootElements)
{
this.iteratingLastChild = diagram.RootElements.Count == ++c;
this.Render(element);
}

Expand All @@ -180,6 +183,9 @@ public override void Render(DiagramItem drawingItem)
else if (drawingItem.TabSchema is XMLSchema.complexType)
type = "complexType";

string occurences = String.Format("{0}..", drawingItem.MinOccurrence) +
(drawingItem.MaxOccurrence == -1 ? "" : string.Format("{0}", drawingItem.MaxOccurrence));

if (type.Length > 0)
{
string path = '/' + drawingItem.Name;
Expand Down Expand Up @@ -221,9 +227,34 @@ public override void Render(DiagramItem drawingItem)
}
}

//bool lastChild = drawingItem.Parent.ChildElements[drawingItem.Parent.ChildElements.Count - 1] == drawingItem;

// Output the item
string t;
XMLSchema.element el;
for (int i = 0; i < _finalTextOutputFields.Count; i++)
{
el = drawingItem.TabSchema as XMLSchema.element;
if (el != null)
{
string et = "" + el.type;
if (et == "")
{
t = "[none]";
}
else
{
t = et.Substring(et.LastIndexOf(':') + 1);
if (t == "")
{
t = "[none]";
}
}
}
else
{
t = "[none]";
}
if (i > 0)
_writer.Write(_fieldSeparator);
string field = _finalTextOutputFields[i];
Expand All @@ -234,6 +265,9 @@ public override void Render(DiagramItem drawingItem)
case "TYPE": _writer.Write(type); break;
case "NAMESPACE": _writer.Write(drawingItem.NameSpace); break;
case "COMMENT": _writer.Write(comment); break;
case "SEQ": _writer.Write(occurences); break;
case "LASTCHILD": _writer.Write(this.iteratingLastChild ? "1" : "0"); break;
case "XSDTYPE": _writer.Write(t); break;
}
}
_writer.WriteLine();
Expand Down Expand Up @@ -328,8 +362,10 @@ public override void Render(DiagramItem drawingItem)
// Draw children expand box
if (drawingItem.HasChildElements && drawingItem.ShowChildElements)
{
int c = 0;
foreach (DiagramItem element in drawingItem.ChildElements)
{
this.iteratingLastChild = drawingItem.ChildElements.Count == ++c;
this.Render(element);
//_writer.WriteLine();
}
Expand Down

0 comments on commit 3bec6a6

Please sign in to comment.