From 1a55e51994e8c147ea27ead66cfc25c8cc8fb512 Mon Sep 17 00:00:00 2001 From: wuestholz Date: Sun, 14 Jul 2013 18:45:12 -0700 Subject: Split up the model viewer into a library and an application and added some functionality. --- Source/ModelViewer/Main.cs | 51 +++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'Source/ModelViewer/Main.cs') diff --git a/Source/ModelViewer/Main.cs b/Source/ModelViewer/Main.cs index 2e612aa1..1caed654 100644 --- a/Source/ModelViewer/Main.cs +++ b/Source/ModelViewer/Main.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using System.IO; using Microsoft.Boogie; +using System.Diagnostics.Contracts; namespace Microsoft.Boogie.ModelViewer { @@ -92,6 +93,18 @@ namespace Microsoft.Boogie.ModelViewer } } + public void ReadModel(string model, int setModelIdTo = 0) + { + Contract.Requires(model != null); + + using (var rd = new StringReader(model)) + { + allModels = Model.ParseModels(rd).ToArray(); + } + + AddAndLoadModel(setModelIdTo); + } + public void ReadModels(string modelFileName, int setModelIdTo) { this.lastModelFileName = modelFileName; @@ -102,28 +115,34 @@ namespace Microsoft.Boogie.ModelViewer allModels = Model.ParseModels(rd).ToArray(); } - modelId = setModelIdTo; - - if (modelId >= allModels.Length) - modelId = 0; - - currentModel = allModels[modelId]; - AddModelMenu(); - - foreach (var p in Providers()) { - if (p.IsMyModel(currentModel)) { - this.langProvider = p; - break; - } - } - - LoadModel(modelId); + AddAndLoadModel(setModelIdTo); } else { currentModel = new Model(); } this.SetWindowTitle(modelFileName); + } + + private void AddAndLoadModel(int setModelIdTo) + { + modelId = setModelIdTo; + + if (modelId >= allModels.Length) + modelId = 0; + + currentModel = allModels[modelId]; + AddModelMenu(); + + foreach (var p in Providers()) + { + if (p.IsMyModel(currentModel)) + { + this.langProvider = p; + break; + } + } + LoadModel(modelId); } private void LoadModel(int idx) -- cgit v1.2.3