From bee5f56c255c78ce991ab45dc12b5639638aef12 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Wed, 14 Sep 2016 11:31:12 +0000 Subject: [PATCH] refs #6686 SysdynFileImport class which implements SimanticsResourceFileImport git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@33192 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn/.project | 5 +++ org.simantics.sysdyn/META-INF/MANIFEST.MF | 4 +- .../org.simantics.sysdyn.SysdynFileImport.xml | 4 ++ org.simantics.sysdyn/build.properties | 16 ++------ .../sysdyn/manager/SysdynGameExperiment.java | 2 +- .../sysdyn/modelica/ModelicaWriter.java | 2 +- .../utils/imports/SysdynFileImport.java | 39 +++++++++++++++++++ 7 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 org.simantics.sysdyn/OSGI-INF/org.simantics.sysdyn.SysdynFileImport.xml create mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFileImport.java diff --git a/org.simantics.sysdyn/.project b/org.simantics.sysdyn/.project index 05d44396..df77a66e 100644 --- a/org.simantics.sysdyn/.project +++ b/org.simantics.sysdyn/.project @@ -20,6 +20,11 @@ + + org.eclipse.pde.ds.core.builder + + + org.eclipse.pde.PluginNature diff --git a/org.simantics.sysdyn/META-INF/MANIFEST.MF b/org.simantics.sysdyn/META-INF/MANIFEST.MF index 2e56948b..8bf988ce 100644 --- a/org.simantics.sysdyn/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn/META-INF/MANIFEST.MF @@ -33,7 +33,8 @@ Require-Bundle: org.simantics.objmap;bundle-version="0.1.0", org.jfree.jchart;bundle-version="1.0.13", org.jfree.jcommon;bundle-version="1.0.16", org.simantics.spreadsheet.graph;bundle-version="1.1.0", - fi.semantum.sysdyn.solver;bundle-version="0.1.0" + fi.semantum.sysdyn.solver;bundle-version="0.1.0", + org.simantics.fileimport Export-Package: org.simantics.sysdyn, org.simantics.sysdyn.adapter, org.simantics.sysdyn.elementaryCycles, @@ -61,3 +62,4 @@ Import-Package: org.eclipse.ui, org.simantics.sysdyn.utils, org.simantics.ui Bundle-Vendor: VTT Technical Reserarch Centre of Finland +Service-Component: OSGI-INF/org.simantics.sysdyn.SysdynFileImport.xml diff --git a/org.simantics.sysdyn/OSGI-INF/org.simantics.sysdyn.SysdynFileImport.xml b/org.simantics.sysdyn/OSGI-INF/org.simantics.sysdyn.SysdynFileImport.xml new file mode 100644 index 00000000..a9bed563 --- /dev/null +++ b/org.simantics.sysdyn/OSGI-INF/org.simantics.sysdyn.SysdynFileImport.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/org.simantics.sysdyn/build.properties b/org.simantics.sysdyn/build.properties index 26e468c9..361c0b93 100644 --- a/org.simantics.sysdyn/build.properties +++ b/org.simantics.sysdyn/build.properties @@ -1,18 +1,8 @@ -############################################################################### -# Copyright (c) 2010 Association for Decentralized Information Management in -# Industry THTH ry. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# VTT Technical Research Centre of Finland - initial API and implementation -############################################################################### -source.. = src/ output.. = bin/ bin.includes = META-INF/,\ .,\ adapters.xml,\ plugin.xml,\ - scl/ + scl/,\ + OSGI-INF/org.simantics.sysdyn.SysdynFileImport.xml +source.. = src/ diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java index 288bb1bf..3a396670 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java @@ -76,7 +76,7 @@ public class SysdynGameExperiment extends SysdynGameExperimentBase { if(control == null) control = new FMUControlJNI(); - results = new TDoubleArrayList[results.length]; + results = new TDoubleArrayList[results != null ? results.length : 0]; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java index 931b1f38..31e679ad 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -216,7 +216,7 @@ public class ModelicaWriter { * @param b String builder */ private static void writeConfiguration(Configuration configuration, HashSet sheetNames, double startTime, StringBuilder b) { - boolean defTime = true; + boolean defTime = false; String app; // Lists for storing different configuration elements diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFileImport.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFileImport.java new file mode 100644 index 00000000..01699bfe --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFileImport.java @@ -0,0 +1,39 @@ +package org.simantics.sysdyn.utils.imports; + +import java.nio.file.Path; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.simantics.db.Resource; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.fileimport.SimanticsResourceFileImport; +import org.simantics.scl.runtime.function.Function1; +import org.simantics.utils.DataContainer; + +public class SysdynFileImport extends SimanticsResourceFileImport { + + private static final Map EXTENSIONS_FILTERS = Collections.singletonMap("*.sysdyn", + "Sysdyn model file (*.sysdyn)"); + + @Override + public Map allowedExtensionsWithFilters() { + return EXTENSIONS_FILTERS; + } + + @Override + public Optional perform(Resource parent, Path file) throws Exception { + DataContainer result = new DataContainer<>(); + ImportUtils.importModelFile(file.toAbsolutePath().toString(), new NullProgressMonitor(), + new Function1() { + + @Override + public WriteRequest apply(Resource model) { + result.set(model); + return null; + } + }); + return Optional.ofNullable(result.get()); + } +} -- 2.47.1