From 4a060e5c2519899ec9db2b31ca704437f3f17f46 Mon Sep 17 00:00:00 2001 From: jkauttio Date: Thu, 21 Aug 2014 07:46:31 +0000 Subject: [PATCH] Make a common model import interface for external model formats to lay groundwork for BPMN import prototype refs #5197 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30110 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/handlers/imports/ImportMdlHandler.java | 2 +- .../sysdyn/ui/wizards/mdl/WizardMdlImportPage.java | 2 +- .../org/simantics/sysdyn/modelImport/IModelParser.java | 9 +++++++++ .../src/org/simantics/sysdyn/modelImport/MdlParser.java | 7 ++++--- 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/IModelParser.java diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java index 8d35a4ea..e1230b8a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java @@ -68,7 +68,7 @@ public class ImportMdlHandler extends AbstractHandler { // Convert Vensim model to Simantics SysDyn format using MdlParser final Model model; try { - model = MdlParser.parse(file); + model = new MdlParser().parse(file); } catch (Exception e) { e.printStackTrace(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/WizardMdlImportPage.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/WizardMdlImportPage.java index 93766ed4..d4679f7d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/WizardMdlImportPage.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/WizardMdlImportPage.java @@ -183,7 +183,7 @@ public class WizardMdlImportPage extends WizardPage{ final Model model; try { - model = MdlParser.parse(file); + model = new MdlParser().parse(file); } catch (Exception e) { e.printStackTrace(); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/IModelParser.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/IModelParser.java new file mode 100644 index 00000000..a179b6c5 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/IModelParser.java @@ -0,0 +1,9 @@ +package org.simantics.sysdyn.modelImport; + +import java.io.File; + +import org.simantics.sysdyn.modelImport.model.Model; + +public interface IModelParser { + public Model parse(File file) throws Exception; +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlParser.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlParser.java index 25c77c0e..876390a5 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlParser.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlParser.java @@ -20,6 +20,7 @@ import java.util.regex.Pattern; import org.simantics.sysdyn.modelImport.mdl.Declaration; import org.simantics.sysdyn.modelImport.mdl.Lookup; import org.simantics.sysdyn.modelImport.mdl.MdlModel; +import org.simantics.sysdyn.modelImport.mdl.MdlVariable; import org.simantics.sysdyn.modelImport.mdl.Sketch; import org.simantics.sysdyn.modelImport.mdl.SketchComment; import org.simantics.sysdyn.modelImport.mdl.SketchConnection; @@ -28,7 +29,6 @@ import org.simantics.sysdyn.modelImport.mdl.SketchValve; import org.simantics.sysdyn.modelImport.mdl.SketchVariable; import org.simantics.sysdyn.modelImport.mdl.Subscript; import org.simantics.sysdyn.modelImport.mdl.SubscriptVariable; -import org.simantics.sysdyn.modelImport.mdl.MdlVariable; import org.simantics.sysdyn.modelImport.model.Comment; import org.simantics.sysdyn.modelImport.model.Connection; import org.simantics.sysdyn.modelImport.model.Model; @@ -37,7 +37,7 @@ import org.simantics.sysdyn.modelImport.model.Shadow; import org.simantics.sysdyn.modelImport.model.Symbol; import org.simantics.sysdyn.modelImport.model.Valve; -public class MdlParser { +public class MdlParser implements IModelParser { private static final String UTF_8 = "{UTF-8}"; private static final String SKETCH_VERSION = "V300"; @@ -48,7 +48,8 @@ public class MdlParser { private static final String PARAMETER_STOP = "FINAL TIME"; private static final String PARAMETER_STEP = "TIME STEP"; - public static Model parse(File file) throws Exception { + @Override + public Model parse(File file) throws Exception { // generate a mdl model based on the contents of the file MdlModel mdl = parseFile(file); -- 2.47.1