Commit 6d4120fb authored by Lukas Ladenberger's avatar Lukas Ladenberger
Browse files

towards reimplementing running visualization

parent 733ee9c5
......@@ -14,9 +14,12 @@ import java.util.Map;
import org.eclipse.swt.widgets.Display;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.model.Simulation;
import de.bmotionstudio.gef.editor.model.Visualization;
import de.bmotionstudio.gef.editor.model.VisualizationView;
import de.prob.core.Animator;
import de.prob.core.IAnimationListener;
import de.prob.core.ILifecycleListener;
import de.prob.core.command.EvaluationGetValuesCommand;
import de.prob.core.command.EvaluationInsertFormulaCommand;
import de.prob.core.command.EvaluationInsertFormulaCommand.FormulaType;
......@@ -26,7 +29,7 @@ import de.prob.core.domainobjects.State;
import de.prob.exceptions.ProBException;
import de.prob.parserbase.ProBParseException;
public class Animation implements IAnimationListener {
public class Animation implements IAnimationListener, ILifecycleListener {
private Animator animator;
......@@ -36,16 +39,16 @@ public class Animation implements IAnimationListener {
private State currentState;
private Visualization visualization;
private Boolean observerCallBack = true;
public Animation(Animator anim, Visualization visualization) {
private Simulation simulation;
public Animation(Animator anim, Simulation simulation) {
StaticListenerRegistry.registerListener((IAnimationListener) this);
StaticListenerRegistry.registerListener((ILifecycleListener) this);
this.currentStateOperations = new HashMap<String, Operation>();
this.animator = anim;
this.visualization = visualization;
this.visualization.setAnimation(this);
this.simulation = simulation;
}
private void setNewState(State state) {
......@@ -103,18 +106,31 @@ public class Animation implements IAnimationListener {
}
public void checkObserver() {
// if (visualization.isRunning()) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
System.out.println("CHECK OBSERVER OF "
+ simulation.getProjectFile().getName());
for (VisualizationView visView : simulation
.getVisualizationViews().values()) {
Visualization visualization = visView.getVisualization();
List<BControl> allBControls = new ArrayList<BControl>();
allBControls.add(visualization);
collectAllBControls(allBControls, visualization);
for (BControl c : allBControls)
c.checkObserver(Animation.this);
}
});
// }
}
});
}
public State getState() {
......@@ -129,12 +145,9 @@ public class Animation implements IAnimationListener {
return currentStateOperations.get(operation);
}
public Visualization getVisualization() {
return this.visualization;
}
public void unregister() {
StaticListenerRegistry.unregisterListener((IAnimationListener) this);
// StaticListenerRegistry.unregisterListener((ILifecycleListener) this);
}
public void setObserverCallBack(Boolean observerCallBack) {
......@@ -174,5 +187,14 @@ public class Animation implements IAnimationListener {
public Map<String, Operation> getCurrentStateOperations() {
return currentStateOperations;
}
@Override
public void reset() {
if (simulation.isRunning()) {
System.out.println("STOP SIMULATION "
+ simulation.getProjectFile().getName());
simulation.stop();
}
}
}
......@@ -283,7 +283,7 @@ public class BMotionStudioEditor extends EditorPart implements
if (obj instanceof Visualization) {
simulation = new Simulation();
simulation = new Simulation("MLift.bum");
Visualization visualization = (Visualization) obj;
visualization.setProjectFile(file);
......
......@@ -29,6 +29,8 @@ public class BMotionStudioImage {
public static final String IMG_ICON_MOTION = "icon_motion";
public static final String IMG_ICON_MOTION_WIZ = "icon_motion_wiz";
public static final String IMG_ICON_BMOTION_RUN = "icon_bmotion_run";
public static ImageDescriptor getImageDescriptor(final String path) {
return getImageDescriptor(BMotionEditorPlugin.PLUGIN_ID, path);
}
......@@ -68,6 +70,7 @@ public class BMotionStudioImage {
registerImage(IMG_LOGO_BMOTION64, "icons/logo_bmotion_64.png");
registerImage(IMG_ICON_MOTION, "icons/icon_motion.gif");
registerImage(IMG_ICON_MOTION_WIZ, "icons/icon_motion_wiz.gif");
registerImage(IMG_ICON_BMOTION_RUN, "icons/icon_run.png");
registerBControlImages();
......
......@@ -37,35 +37,10 @@ public class BMotionStudioLauncher implements IEditorLauncher {
Simulation simulation = BMotionEditorPlugin.getOpenSimulations().get(
file.getName());
// final String perspectiveId = PerspectiveUtil
// .getPerspectiveIdFromFile(file);
// The simulation is already open
if (simulation != null) {
PerspectiveUtil.openPerspective(simulation);
initViews(simulation);
//
// IPerspectiveDescriptor perspective = PlatformUI.getWorkbench()
// .getPerspectiveRegistry()
// .findPerspectiveWithId(perspectiveId);
//
// // Check if a perspective already exists
// if (perspective != null) {
// // If yes, just switch the perspective
// PerspectiveUtil.switchPerspective(perspective);
// } else {
//
//
// }
//
// IFile perspectiveFile = file.getProject().getFile(
// getPerspectiveFileName());
// if (perspectiveFile.exists()) {
//
// }
// PerspectiveUtil.openPerspective(simulation);
return;
}
......@@ -97,11 +72,11 @@ public class BMotionStudioLauncher implements IEditorLauncher {
if (obj instanceof Visualization) {
simulation = new Simulation();
Visualization visualization = (Visualization) obj;
visualization.setProjectFile(file);
simulation = new Simulation(visualization.getMachineName());
String secId = UUID.randomUUID().toString();
VisualizationView visualizationView = new VisualizationView(
......@@ -158,8 +133,6 @@ public class BMotionStudioLauncher implements IEditorLauncher {
if (viewReference != null) {
visualizationViewPart = (VisualizationViewPart) viewReference
.getPart(true);
System.out.println(" ===> Visualization found: "
+ visualizationViewPart);
} else {
// If not, create a new one
try {
......@@ -169,13 +142,10 @@ public class BMotionStudioLauncher implements IEditorLauncher {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(" ===> Visualization created: "
+ visualizationViewPart);
}
if (visualizationViewPart != null
&& !visualizationViewPart.isInitialized()) {
System.out.println(" ===> Visualization initialized");
visualizationViewPart.init(simulation, visView);
}
......
......@@ -169,6 +169,10 @@ public class VisualizationViewPart extends ViewPart implements
return visualizationView;
}
public Simulation getSimulation() {
return simulation;
}
private void createActions() {
ActionRegistry registry = getActionRegistry();
......@@ -327,6 +331,8 @@ public class VisualizationViewPart extends ViewPart implements
setInitialized(false);
if (getVisualizationView() != null)
getVisualizationView().removePropertyChangeListener(this);
if (getSimulation() != null)
getSimulation().removePropertyChangeListener(this);
}
@Override
......@@ -380,6 +386,7 @@ public class VisualizationViewPart extends ViewPart implements
public void init(Simulation simulation, VisualizationView visualizationView) {
this.simulation = simulation;
this.simulation.addPropertyChangeListener(this);
this.visualizationView = visualizationView;
this.visualizationView.addPropertyChangeListener(this);
this.visualization = visualizationView.getVisualization();
......@@ -558,8 +565,33 @@ public class VisualizationViewPart extends ViewPart implements
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("name"))
setPartName(evt.getNewValue().toString());
String name = visualizationView.getName();
Boolean running = simulation.isRunning();
String propertyName = evt.getPropertyName();
if (propertyName.equals("name"))
name = evt.getNewValue().toString();
if (propertyName.equals("running"))
running = Boolean.valueOf(evt.getNewValue().toString());
if (propertyName.equals("running")
|| propertyName.equals("name")) {
if (running) {
setPartName("(Running) " + name);
setTitleImage(BMotionStudioImage
.getImage(BMotionStudioImage.IMG_ICON_BMOTION_RUN));
} else {
setPartName(name);
setTitleImage(BMotionStudioImage
.getImage(BMotionStudioImage.IMG_LOGO_BMOTION));
}
}
}
}
......@@ -49,6 +49,7 @@ public class CloseSimulationAction extends Action {
PerspectiveUtil.deletePerspective(perspectiveDescriptor);
}
simulation.stop();
BMotionEditorPlugin.closeSimulation(simulation);
}
......
......@@ -86,12 +86,6 @@ public class ControlPanel extends ViewPart implements ISimulationListener,
((Simulation) parent).setDirty(true);
treeViewer.update(element, null);
// IWorkbenchPage page = PlatformUI.getWorkbench()
// .getActiveWorkbenchWindow().getActivePage();
// IViewReference viewReference = page.findViewReference(
// VisualizationViewPart.ID, visView.getViewId());
// IViewPart view = viewReference.getView(true);
}
}
......@@ -121,6 +115,11 @@ public class ControlPanel extends ViewPart implements ISimulationListener,
column2.getColumn().setText("Dirty");
column2.getColumn().setWidth(40);
TreeViewerColumn column3 = new TreeViewerColumn(treeViewer, SWT.RIGHT);
column3.getColumn().setAlignment(SWT.LEFT);
column3.getColumn().setText("Running");
column3.getColumn().setWidth(40);
treeViewer.setContentProvider(new ITreeContentProvider() {
@Override
......@@ -194,6 +193,8 @@ public class ControlPanel extends ViewPart implements ISimulationListener,
treeViewer);
final SaveSimulationAction saveSimulationAction = new SaveSimulationAction(
treeViewer);
final RunSimulationAction runSimulationAction = new RunSimulationAction(
treeViewer);
final AddVisualizationViewAction addVisualizationViewAction = new AddVisualizationViewAction(
treeViewer);
final RemoveVisualizationViewAction deleteVisualizationViewAction = new RemoveVisualizationViewAction(
......@@ -212,6 +213,8 @@ public class ControlPanel extends ViewPart implements ISimulationListener,
manager.add(saveSimulationAction);
manager.add(separator);
manager.add(addVisualizationViewAction);
manager.add(separator);
manager.add(runSimulationAction);
} else if (firstElement instanceof VisualizationView) {
manager.add(deleteVisualizationViewAction);
}
......@@ -301,6 +304,15 @@ public class ControlPanel extends ViewPart implements ISimulationListener,
else
return ColorConstants.green;
}
case 2:
if (element instanceof Simulation) {
Simulation simulation = (Simulation) element;
if (simulation.isRunning())
return ColorConstants.green;
else
return ColorConstants.red;
}
}
return null;
......@@ -308,7 +320,6 @@ public class ControlPanel extends ViewPart implements ISimulationListener,
@Override
public Image getColumnImage(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}
......@@ -333,7 +344,8 @@ public class ControlPanel extends ViewPart implements ISimulationListener,
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("dirty"))
if (evt.getPropertyName().equals("dirty")
|| evt.getPropertyName().equals("running"))
treeViewer.refresh();
}
......
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.controlpanel;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.PlatformUI;
import de.bmotionstudio.gef.editor.BMotionStudioImage;
import de.bmotionstudio.gef.editor.model.Simulation;
import de.bmotionstudio.gef.editor.util.PerspectiveUtil;
public class RunSimulationAction extends Action {
private TreeViewer viewer;
public RunSimulationAction(TreeViewer viewer) {
this.viewer = viewer;
setText("Run Simulation");
setImageDescriptor(BMotionStudioImage
.getImageDescriptor("icons/icon_run.png"));
}
@Override
public void run() {
IStructuredSelection sel = (IStructuredSelection) viewer.getSelection();
Object firstElement = sel.getFirstElement();
if (firstElement instanceof Simulation) {
Simulation simulation = (Simulation) firstElement;
IPerspectiveRegistry perspectiveRegistry = PlatformUI
.getWorkbench().getPerspectiveRegistry();
String perspectiveId = PerspectiveUtil
.getPerspectiveIdFromFile(simulation.getProjectFile());
IPerspectiveDescriptor perspectiveDescriptor = perspectiveRegistry
.findPerspectiveWithId(perspectiveId);
if (perspectiveDescriptor != null)
PerspectiveUtil.switchPerspective(perspectiveDescriptor);
simulation.start();
}
}
}
......@@ -155,7 +155,7 @@ public class VisualizationProgressBar extends ProgressBarDialog {
}
private void startProbAnimator() {
animation = new Animation(animator, visualization);
animation = new Animation(animator, null);
ILanguageService langService = getGenericLoadMachine(visualization
.getLanguage());
if (langService != null) {
......
......@@ -6,6 +6,15 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eventb.core.IEventBRoot;
import org.rodinp.core.IRodinFile;
import org.rodinp.core.IRodinProject;
import org.rodinp.core.RodinCore;
import de.bmotionstudio.gef.editor.Animation;
import de.prob.core.Animator;
import de.prob.core.command.LoadEventBModelCommand;
import de.prob.exceptions.ProBException;
public class Simulation {
......@@ -17,8 +26,15 @@ public class Simulation {
private transient boolean dirty;
public Simulation() {
private transient Animation animation;
private transient boolean running;
private String model;
public Simulation(String model) {
this.views = new HashMap<String, VisualizationView>();
this.model = model;
}
public Map<String, VisualizationView> getVisualizationViews() {
......@@ -42,12 +58,22 @@ public class Simulation {
return dirty;
}
public boolean isRunning() {
return running;
}
public void setDirty(boolean dirty) {
boolean oldVal = this.dirty;
this.dirty = dirty;
listeners.firePropertyChange("dirty", oldVal, dirty);
}
public void setRunning(boolean running) {
boolean oldVal = this.running;
this.running = running;
listeners.firePropertyChange("running", oldVal, running);
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
getListeners().addPropertyChangeListener(listener);
}
......@@ -62,4 +88,31 @@ public class Simulation {
getListeners().removePropertyChangeListener(listener);
}
public void start() {
Animator animator = Animator.getAnimator();
animation = new Animation(animator, this);
IEventBRoot modelRoot = getCorrespondingFile(getProjectFile(), model);
try {
LoadEventBModelCommand.load(animator, modelRoot);
setRunning(true);
} catch (ProBException e) {
e.printStackTrace();
}
}
public void stop() {
if (animation != null)
animation.unregister();
setRunning(false);
}
private IEventBRoot getCorrespondingFile(IFile file, String machineFileName) {
IRodinProject rProject = RodinCore.valueOf(file.getProject());
IRodinFile rFile = rProject.getRodinFile(machineFileName);
IEventBRoot eventbRoot = (IEventBRoot) rFile.getRoot();
return eventbRoot;
}
}
......@@ -25,6 +25,9 @@ public class SimpleValueDisplay extends Observer {
public void check(final Animation animation, final BControl bcontrol) {
if (eval == null)
return;
// First evaluate predicate (predicate field)
String bolValue = "true";
if (predicate != null && predicate.length() > 0) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment