public static String TEMP_FMU_COMMON_DIRECTORY; \r
public static String LOCK_FILE_NAME = "fmu.lock";\r
\r
+ public static Object syncObject = new Object();\r
+\r
/**\r
* Static: load native libraries required for the FMU simulation to work.\r
*/\r
\r
TEMP_FOLDER_1 = fmuDir.toString();\r
TEMP_FOLDER_2 = fmuDir.toString() + "_2";\r
- \r
+\r
// Lock fmu directory in temp directory\r
lockFMUDirectory();\r
}\r
- \r
+\r
public String getModelID() {\r
return dirName;\r
}\r
private boolean fmuLoaded = false;\r
public void loadFMUFile(String path) throws FMUJNIException {\r
\r
- if(fmuN % 2 == 0) {\r
- fmuDir = TEMP_FOLDER_1;\r
- fmuN++;\r
- } else {\r
- fmuDir = TEMP_FOLDER_2;\r
- fmuN = 0;\r
- }\r
+ synchronized(syncObject) {\r
\r
- File tempDir = new File(fmuDir);\r
- if(tempDir.isDirectory()) {\r
- try {\r
- FileUtils.deleteAll(tempDir);\r
- } catch (IOException e) {\r
- throw new FMUJNIException("Could not create temp folder for fmu");\r
+ if(fmuN % 2 == 0) {\r
+ fmuDir = TEMP_FOLDER_1;\r
+ fmuN++;\r
+ } else {\r
+ fmuDir = TEMP_FOLDER_2;\r
+ fmuN = 0;\r
}\r
- tempDir.mkdir();\r
- } else {\r
- tempDir.mkdir();\r
- }\r
\r
+ File tempDir = new File(fmuDir);\r
+ if(tempDir.isDirectory()) {\r
+ try {\r
+ FileUtils.deleteAll(tempDir);\r
+ } catch (IOException e) {\r
+ throw new FMUJNIException("Could not create temp folder for fmu");\r
+ }\r
+ tempDir.mkdir();\r
+ } else {\r
+ tempDir.mkdir();\r
+ }\r
\r
- try {\r
- String tmpPath = tempDir.getAbsolutePath();\r
- if(!tmpPath.endsWith("\\"))\r
- tmpPath = tmpPath + "\\";\r
- int ret = loadFMUFile_(getModelID(), path, tmpPath);\r
- if(ret == ERROR)\r
- throw new FMUJNIException(getLastErrorMessage());\r
- \r
- fmuLoaded = true;\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+\r
+ try {\r
+ String tmpPath = tempDir.getAbsolutePath();\r
+ if(!tmpPath.endsWith("\\"))\r
+ tmpPath = tmpPath + "\\";\r
+ int ret = loadFMUFile_(getModelID(), path, tmpPath);\r
+ if(ret == ERROR)\r
+ throw new FMUJNIException(getLastErrorMessage());\r
+\r
+ fmuLoaded = true;\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
* @throws FMUJNIException\r
*/\r
public void setStepLength(double step) throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
\r
- int ret = setStepLength_(getModelID(), step);\r
- if(ret == ERROR)\r
- throw new FMUJNIException(getLastErrorMessage());\r
+ try {\r
+\r
+ int ret = setStepLength_(getModelID(), step);\r
+ if(ret == ERROR)\r
+ throw new FMUJNIException(getLastErrorMessage());\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
* @throws FMUJNIException\r
*/\r
public void initializeSimulation() throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
\r
- int ret = initializeSimulation_(getModelID()); \r
- if(ret == ERROR)\r
- throw new FMUJNIException(getLastErrorMessage());\r
+ try {\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ int ret = initializeSimulation_(getModelID()); \r
+ if(ret == ERROR)\r
+ throw new FMUJNIException(getLastErrorMessage());\r
+\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
* @throws FMUJNIException\r
*/\r
public void subscribe(String[] variables) throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
+\r
+ try {\r
\r
- int ret = subscribe_(getModelID(), variables, variables.length); \r
- if(ret == ERROR)\r
- throw new FMUJNIException(getLastErrorMessage());\r
+ int ret = subscribe_(getModelID(), variables, variables.length); \r
+ if(ret == ERROR)\r
+ throw new FMUJNIException(getLastErrorMessage());\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
* @throws FMUJNIException\r
*/\r
public void setRealValue(String name, double value) throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
\r
- int ret = setRealValue_(getModelID(), name, value); \r
- if(ret == ERROR)\r
- throw new FMUJNIException(getLastErrorMessage());\r
+ try {\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ int ret = setRealValue_(getModelID(), name, value); \r
+ if(ret == ERROR)\r
+ throw new FMUJNIException(getLastErrorMessage());\r
+\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
* @throws FMUJNIException\r
*/\r
public void setIntegerValue(String name, int value) throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
\r
- int ret = setIntegerValue_(getModelID(), name, value); \r
- if(ret == ERROR)\r
- throw new FMUJNIException(getLastErrorMessage());\r
+ try {\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ int ret = setIntegerValue_(getModelID(), name, value); \r
+ if(ret == ERROR)\r
+ throw new FMUJNIException(getLastErrorMessage());\r
+\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
private native int setIntegerValue_(String id, String name, int value);\r
* @throws FMUJNIException\r
*/\r
public void setBooleanValue(String name, boolean value) throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
\r
- int ret = setBooleanValue_(getModelID(), name, value); \r
- if(ret == ERROR)\r
- throw new FMUJNIException(getLastErrorMessage());\r
+ try {\r
+\r
+ int ret = setBooleanValue_(getModelID(), name, value); \r
+ if(ret == ERROR)\r
+ throw new FMUJNIException(getLastErrorMessage());\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
private native int setBooleanValue_(String id, String name, boolean value);\r
\r
+ public void setTime(double time) throws FMUJNIException {\r
+ synchronized(syncObject) {\r
+\r
+ try {\r
+\r
+ int ret = setTime_(getModelID(), time); \r
+ if(ret == ERROR)\r
+ throw new FMUJNIException(getLastErrorMessage());\r
+\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
+ }\r
+ }\r
+ private native int setTime_(String id, double time);\r
\r
/**\r
* Simulate one step forward. The step length can be set with\r
* @throws FMUJNIException\r
*/\r
public void simulateStep() throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
\r
- int ret = simulateStep_(getModelID()); \r
- if(ret == ERROR)\r
- throw new FMUJNIException(getLastErrorMessage());\r
+ try {\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ int ret = simulateStep_(getModelID()); \r
+ if(ret == ERROR)\r
+ throw new FMUJNIException(getLastErrorMessage());\r
+\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
private native int simulateStep_(String id);\r
* @return\r
*/\r
public double[] getSubscribedResults(double[] results) throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
\r
- return getSubscribedResults_(getModelID(), results);\r
+ try {\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ return getSubscribedResults_(getModelID(), results);\r
+\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
* @throws FMUJNIException\r
*/\r
public void unloadFMU() throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
\r
- unlockFMUDirectory();\r
- if(fmuLoaded) {\r
- int ret = unloadFMU_(getModelID()); \r
- if(ret == ERROR)\r
- throw new FMUJNIException(getLastErrorMessage());\r
- }\r
- removeFMUDirectoryContents();\r
+ try {\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ unlockFMUDirectory();\r
+ if(fmuLoaded) {\r
+ int ret = unloadFMU_(getModelID()); \r
+ if(ret == ERROR)\r
+ throw new FMUJNIException(getLastErrorMessage());\r
+ }\r
+ removeFMUDirectoryContents();\r
+\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
private native int unloadFMU_(String id);\r
* @return current simulation time\r
*/\r
public double getTime() throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
+\r
+ try {\r
\r
- return getTime_(getModelID());\r
+ return getTime_(getModelID());\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
* @return all variables in a loaded model\r
*/\r
public String[] getAllVariables() throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
+\r
+ try {\r
\r
- return getAllVariables_(getModelID());\r
+ return getAllVariables_(getModelID());\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
private native String[] getAllVariables_(String id);\r
- \r
+\r
/**\r
* Get all variables from model that match the filter (and time variable)\r
* \r
* @return An array of variable names that match regexp filter (and time-variable)\r
* @throws FMUJNIException\r
*/\r
- public String[] filterVariables(String regexp) throws FMUJNIException {\r
- try {\r
+ public String[] filterVariables(String regexp) throws FMUJNIException { \r
+ synchronized(syncObject) {\r
+ try {\r
\r
- return filterVariables_(getModelID(), regexp + "|time");\r
+ return filterVariables_(getModelID(), regexp + "|time");\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
- \r
+\r
private native String[] filterVariables_(String id, String regexp);\r
\r
/**\r
* @return Last error message\r
*/\r
public String getLastErrorMessage() throws FMUJNIException {\r
- try {\r
+ synchronized(syncObject) {\r
\r
- return getLastErrorMessage_(getModelID());\r
+ try {\r
\r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ return getLastErrorMessage_(getModelID());\r
+\r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
* @throws FMUJNIException\r
*/\r
public double getRealValue(String name) throws FMUJNIException {\r
- try {\r
- return getRealValue_(getModelID(), name); \r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ synchronized(syncObject) {\r
+\r
+ try {\r
+ // TODO: printtaa id ja name, jotta saadaan virheessä kiinni \r
+ return getRealValue_(getModelID(), name); \r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
* @throws FMUJNIException\r
*/\r
public String getStringValue(String name) throws FMUJNIException {\r
- try {\r
- return getStringValue_(getModelID(), name); \r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ synchronized(syncObject) {\r
+\r
+ try {\r
+ return getStringValue_(getModelID(), name); \r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
private native String getStringValue_(String id, String name);\r
- \r
+\r
/**\r
* Get an integer value for variable\r
* @param name Name of the variable\r
* @throws FMUJNIException\r
*/\r
public int getIntegerValue(String name) throws FMUJNIException {\r
- try {\r
- return getIntegerValue_(getModelID(), name); \r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ synchronized(syncObject) {\r
+\r
+ try {\r
+ return getIntegerValue_(getModelID(), name); \r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
private native int getIntegerValue_(String id, String name);\r
- \r
+\r
/**\r
* Get a real (double) value for variable\r
* @param name Name of the variable\r
* @throws FMUJNIException\r
*/\r
public boolean getBooleanValue(String name) throws FMUJNIException {\r
- try {\r
- return getBooleanValue_(getModelID(), name); \r
- } catch (UnsatisfiedLinkError err) {\r
- throw new FMUJNIException(UNSATISFIED_LINK);\r
- } catch (Exception e) {\r
- throw new FMUJNIException(e.getMessage());\r
+ synchronized(syncObject) {\r
+\r
+ try {\r
+ return getBooleanValue_(getModelID(), name); \r
+ } catch (UnsatisfiedLinkError err) {\r
+ throw new FMUJNIException(UNSATISFIED_LINK);\r
+ } catch (Exception e) {\r
+ throw new FMUJNIException(e.getMessage());\r
+ }\r
}\r
}\r
\r
}\r
return true;\r
}\r
- \r
+\r
private boolean removeFMUDirectoryContents() {\r
// Remove contents\r
try {\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.procedure.AsyncProcedure;\r
+import org.simantics.diagram.G2DUtils;\r
import org.simantics.diagram.adapter.SyncElementFactory;\r
import org.simantics.diagram.connection.ConnectionVisuals;\r
import org.simantics.diagram.connection.RouteGraph;\r
import org.simantics.diagram.content.TerminalMap;\r
import org.simantics.diagram.query.DiagramRequests;\r
import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.diagram.stubs.G2DResource;\r
import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
import org.simantics.diagram.synchronization.graph.RouteGraphConnection;\r
import org.simantics.diagram.ui.DiagramModelHints;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.scenegraph.g2d.nodes.connection.IRouteGraphListener;\r
import org.simantics.scenegraph.g2d.nodes.connection.RouteGraphChangeEvent;\r
-import org.simantics.scenegraph.utils.GeometryUtils;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.structural2.modelingRules.CPTerminal;\r
import org.simantics.structural2.modelingRules.IAttachmentRelationMap;\r
// FIXME: With undo this seems to happen, don't know why yet!\r
return;\r
\r
+ Resource colorResource = graph.getPossibleObject(connection, G2DResource.getInstance(graph).HasColor);\r
+ Color color = null;\r
+ if(colorResource != null) {\r
+ color = G2DUtils.getColor(graph, colorResource);\r
+ element.setHint(ElementHints.KEY_TEXT_COLOR, color);\r
+ }\r
+ \r
RouteGraph rg = new RouteGraph();\r
\r
Set<Resource> nodes = new HashSet<Resource>();\r
direction = 0xf;\r
\r
//System.out.println("load line style: " + NameUtils.getSafeLabel(graph, attachmentRelation));\r
- ILineEndStyle endStyle = loadLineEndStyle(graph, te, attachmentRelation);\r
+ ILineEndStyle endStyle = loadLineEndStyle(graph, te, attachmentRelation, color);\r
\r
RouteTerminal routeTerminal = rg.addBigTerminal(/*x, y,*/ minx, miny, maxx, maxy, /*direction,*/ endStyle);\r
routeTerminal.setData( RouteGraphConnection.serialize(graph, connector) );\r
if (connectionType != null)\r
cv = graph.syncRequest(DiagramRequests.getConnectionVisuals(connectionType),\r
TransientCacheListener.<ConnectionVisuals> instance());\r
-\r
- Color lineColor = cv != null ? cv.toColor() : null;\r
+ \r
+ \r
+ Color lineColor = element.getHint(ElementHints.KEY_TEXT_COLOR);\r
if (lineColor == null)\r
- lineColor = Color.DARK_GRAY;\r
+ lineColor = cv != null ? cv.toColor() : Color.DARK_GRAY;\r
+ \r
Stroke lineStroke = cv != null ? cv.stroke : null;\r
if (lineStroke == null)\r
lineStroke = new BasicStroke(0.1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10, null, 0);\r
return null;\r
}\r
\r
- public ILineEndStyle loadLineEndStyle(ReadGraph graph, IElement te, Resource attachmentRelation)\r
+ public ILineEndStyle loadLineEndStyle(ReadGraph graph, IElement te, Resource attachmentRelation, Color color)\r
throws DatabaseException {\r
ILineEndStyle style;\r
// TODO: change bounds according to terminal type: Very small rectangle for Valves, Text box size for Stocks and Clouds\r
if(te.getElementClass().containsClass(ValveSceneGraph.class)) {\r
- style = new FlowArrowLineStyle("none 0 0 0");\r
+ style = new FlowArrowLineStyle("none 0 0 0", color);\r
} else {\r
if (graph.isSubrelationOf(attachmentRelation, DIA.HasHeadConnector)) {\r
- style = new FlowArrowLineStyle("fill 2 2 0");\r
+ style = new FlowArrowLineStyle("fill 2 2 0", color);\r
} else {\r
- style = new FlowArrowLineStyle("none 0 0 0");\r
+ style = new FlowArrowLineStyle("none 0 0 0", color);\r
}\r
}\r
return style;\r