From f85e3a7b1ee309d7999936bfd01c1c620745ea82 Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 23 Feb 2010 14:56:35 +0000 Subject: [PATCH] simulation toggle button in sysdyn perspective git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14355 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../icons/control_play.png | Bin 0 -> 592 bytes org.simantics.sysdyn.ui/plugin.xml | 31 ++++++++++++++++ .../sysdyn/ui/actions/ToggleSimulation.java | 34 ++++++++++++++++++ .../sysdyn/ui/simulation/SimulationJob.java | 6 ++-- 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 org.simantics.sysdyn.ui/icons/control_play.png create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java diff --git a/org.simantics.sysdyn.ui/icons/control_play.png b/org.simantics.sysdyn.ui/icons/control_play.png new file mode 100644 index 0000000000000000000000000000000000000000..0846555d0ca84cb99d4c70dad80144a232604041 GIT binary patch literal 592 zcmV-W0k7R5;6} zlgp~&KoEw{L*wq6jM9+RMU)_iNO6K~b@$|K=nj zb2!5=4Mjq_zrU*f>U2#vSVnMZ9ja4cY`AdOM*t}k^goWqfa3Iq(>2kSH;P81hAqIyBm_{t1>+!KRdtb~{1AK7>C~ zD-Nov`UX!X6ET_La7f{B_|*cRuZGR%^C`gjd@jmW6h*+;8;{2{8ja|Fzf-YTq+l@k zGLg?!DijI~9$+CG0 + + + + + + + + + + + + @@ -151,6 +173,15 @@ id="org.simantics.sysdyn.ui.rename" name="Rename"> + + + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java new file mode 100644 index 00000000..23f4e1d7 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java @@ -0,0 +1,34 @@ +package org.simantics.sysdyn.ui.actions; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.State; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; + +public class ToggleSimulation extends AbstractHandler { + + public static final String COMMAND = "org.simantics.sysdyn.ui.simulate"; + public static final String STATE = "org.simantics.sysdyn.ui.simulate.state"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service.getCommand(COMMAND); + State state = command.getState(STATE); + Boolean value = (Boolean) state.getValue(); + value = !value; + state.setValue(value); + return null; + } + + public static Boolean getState() { + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service.getCommand(COMMAND); + State state = command.getState(STATE); + return (Boolean)state.getValue(); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java index 3a80ebab..5a3789db 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java @@ -11,6 +11,7 @@ import org.eclipse.ui.console.MessageConsole; import org.eclipse.ui.console.MessageConsoleStream; import org.simantics.modelica.IModelicaMonitor; import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.ui.actions.ToggleSimulation; public class SimulationJob extends Job { @@ -28,7 +29,8 @@ public class SimulationJob extends Job { this.monitor.clearConsole(); try { model.update(); - model.simulate(this.monitor); + if(ToggleSimulation.getState()) + model.simulate(this.monitor); } catch (Exception e) { e.printStackTrace(); return new Status( @@ -62,7 +64,7 @@ public class SimulationJob extends Job { MessageConsoleStream out = this.console.newMessageStream(); out.println(message); } - + public void clearConsole() { this.console.clearConsole(); } -- 2.47.1