Skip to content

Commit b1e864d

Browse files
caigenlevnach
authored andcommitted
Add FileType Support in TEst01
1 parent c097db8 commit b1e864d

3 files changed

Lines changed: 49 additions & 23 deletions

File tree

GraphLayout/Samples/LoadingDgmlGraph/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11

22

3+
using System;
34
using Microsoft.Msagl.Drawing;
45
using Microsoft.Msagl.Layout.Incremental;
56
using Microsoft.Msagl.Layout.Layered;
67
using Microsoft.Msagl.Layout.MDS;
78

89
namespace LoadingDgmlGraph {
910
class Program {
11+
[STAThread]
1012
static void Main(string[] args) {
1113
Microsoft.Msagl.GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions();
1214
//create a form

GraphLayout/Test/TestFormForGViewer/FormStuff.cs

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2626
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2727
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2828
*/
29-
using System;
29+
using System;
3030
using System.Diagnostics;
3131
using System.IO;
3232
using System.Windows.Forms;
33+
using DgmlParser;
3334
using Dot2Graph;
3435
using Microsoft.Msagl.Drawing;
3536
using Microsoft.Msagl.GraphViewerGdi;
@@ -41,7 +42,7 @@ public class FormStuff {
4142
protected static GViewer GViewer;
4243

4344
public static Form CreateOrAttachForm(GViewer gviewer, Form form) {
44-
GViewer=gviewer;
45+
GViewer = gviewer;
4546
if (form == null)
4647
form = new Form();
4748
form.SuspendLayout();
@@ -58,13 +59,13 @@ public static Form CreateOrAttachForm(GViewer gviewer, Form form) {
5859
return form;
5960
}
6061

61-
static void form_Load(object sender,EventArgs e) {
62-
((Form) sender).Focus();
62+
static void form_Load(object sender, EventArgs e) {
63+
((Form)sender).Focus();
6364
}
6465

6566

6667
static MenuStrip GetMainMenuStrip() {
67-
var menu=new MenuStrip();
68+
var menu = new MenuStrip();
6869
menu.Items.Add(FileStripItem());
6970

7071
return menu;
@@ -73,7 +74,7 @@ static MenuStrip GetMainMenuStrip() {
7374

7475
static ToolStripItem FileStripItem() {
7576
var item = new ToolStripMenuItem("File");
76-
item.DropDownItems.Add((ToolStripItem) OpenDotFileItem());
77+
item.DropDownItems.Add((ToolStripItem)OpenDotFileItem());
7778
item.DropDownItems.Add(ReloadDotFileItem());
7879
return item;
7980
}
@@ -86,8 +87,8 @@ static ToolStripItem ReloadDotFileItem() {
8687
}
8788

8889
static void ReloadFileClick(object sender, EventArgs e) {
89-
if(lastFileName!=null)
90-
ReadGraphFromFile(lastFileName, GViewer, false);
90+
if (lastFileName != null)
91+
ReadGraphFromFile(lastFileName, GViewer, false);
9192
}
9293

9394
static ToolStripItem OpenDotFileItem() {
@@ -101,7 +102,7 @@ static void OpenFileClick(object sender, EventArgs e) {
101102

102103
var openFileDialog = new OpenFileDialog {
103104
RestoreDirectory = true,
104-
Filter = "DOT (*.dot,*.gv)|*.dot;*.gv| All(*.*)|*.*"
105+
Filter = "MSAGL Files(*.msagl)|*.msagl|DOT (*.dot,*.gv)|*.dot;*.gv|DGML Files(*.dgml)|*.dgml|All(*.*)|*.*"
105106
};
106107

107108
if (openFileDialog.ShowDialog() == DialogResult.OK)
@@ -110,24 +111,46 @@ static void OpenFileClick(object sender, EventArgs e) {
110111

111112
internal static Graph CreateDrawingGraphFromFile(string fileName, out int line, out int column, out bool msaglFile) {
112113
string msg;
113-
var graph = Parser.Parse(fileName, out line, out column, out msg);
114-
if (graph != null) {
115-
msaglFile = false;
116-
return graph;
114+
Graph graph = null;
115+
msaglFile = false;
116+
line = column = 0;
117+
118+
// Get extension
119+
string ext = Path.GetExtension(fileName);
120+
switch (ext.ToLower()) {
121+
case ".dgml":
122+
try {
123+
graph = DgmlParser.DgmlParser.Parse(fileName);
124+
line = column = 0;
125+
return graph;
126+
}
127+
catch (Exception) {
128+
System.Diagnostics.Debug.WriteLine("cannot read " + fileName);
129+
}
130+
break;
131+
case ".dot":
132+
case ".gv":
133+
graph = Parser.Parse(fileName, out line, out column, out msg);
134+
if (graph != null) {
135+
return graph;
136+
}
137+
break;
138+
case ".msagl":
139+
default:
140+
try {
141+
graph = Graph.Read(fileName);
142+
msaglFile = true;
143+
return graph;
144+
}
145+
catch (Exception) {
146+
System.Diagnostics.Debug.WriteLine("cannot read " + fileName);
147+
}
148+
break;
117149
}
118150

119-
try {
120-
graph = Graph.Read(fileName);
121-
msaglFile = true;
122-
return graph;
123-
} catch (Exception) {
124-
System.Diagnostics.Debug.WriteLine("cannot read " + fileName);
125-
}
126-
msaglFile = false;
127-
return null;
151+
return graph;
128152
}
129153

130-
131154
public static void ReadGraphFromFile(string fileName, GViewer gViewer, bool verbose) {
132155
int eLine, eColumn;
133156
bool msaglFile;

GraphLayout/Test/TestFormForGViewer/TestFormForGViewer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
<ItemGroup>
1515
<ProjectReference Include="..\..\Drawing\AutomaticGraphLayout.Drawing.csproj" />
16+
<ProjectReference Include="..\..\tools\DgmlParser\DgmlParser.csproj" />
1617
<ProjectReference Include="..\..\tools\GraphViewerGDI\GraphViewerGDI.csproj" />
1718
<ProjectReference Include="..\..\MSAGL\AutomaticGraphLayout.csproj" />
1819
<ProjectReference Include="..\..\tools\Dot2Graph\Dot2Graph.csproj" />

0 commit comments

Comments
 (0)