]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation/tests/org/simantics/simulation/test/TestPseudoSolver.java
Possibility to open SCL-modules from plug-in in JAR-file
[simantics/platform.git] / bundles / org.simantics.simulation / tests / org / simantics / simulation / test / TestPseudoSolver.java
1 /*******************************************************************************
2  * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     VTT Technical Research Centre of Finland - initial API and implementation
10  *******************************************************************************/
11 package org.simantics.simulation.test;
12
13 import java.util.Formatter;
14 import java.util.concurrent.Executor;
15
16 import org.simantics.databoard.Bindings;
17 import org.simantics.databoard.accessor.error.AccessorException;
18 import org.simantics.simulation.data.Datasource;
19 import org.simantics.simulation.data.PseudoSolver;
20 import org.simantics.simulation.data.Datasource.DatasourceListener;
21 import org.simantics.simulation.data.VariableHandle;
22
23 public class TestPseudoSolver {
24         
25         public static void main(String[] args) throws InterruptedException {
26                 
27                 PseudoSolver solver = new PseudoSolver();
28                 solver.addListener( new DatasourceListener() {
29                         @Override
30                         public void onStep(Datasource source) {
31                                 StringBuilder sb = new StringBuilder();
32                                 Formatter f = new Formatter(sb);
33                                 
34                                 VariableHandle sineHandle = source.openHandle(null, PseudoSolver.SINE, Bindings.DOUBLE);
35                                 VariableHandle rampHandle = source.openHandle(null, PseudoSolver.RAMP, Bindings.DOUBLE);
36                                 
37                                 double time = (Double) source.getTime(Bindings.DOUBLE);
38                                 try {
39                                         double sine = (Double) sineHandle.getValue();
40                                         double ramp = (Double) rampHandle.getValue();
41                                         f.format("%3f: sine=%,5f, ramp=%,5f\n", time, sine, ramp);
42                                         System.out.print(sb);
43                                 } catch (AccessorException e) {
44                                         e.printStackTrace();
45                                 }
46                         }
47
48                         @Override
49                         public Executor getExecutor() {
50                                 return null;
51                         }
52                 } );
53                 solver.start();
54                 
55                 Thread.sleep(10*1000L);
56                 solver.stop();
57         }
58
59 }
60