Commit e2210bf3 authored by Johannes Eder's avatar Johannes Eder

Working graphical state simulation editor

Issue-Ref: 4015
Issue-Url: https://af3-developer.fortiss.org/issues/4015Signed-off-by: Johannes Eder's avatarJohannes Eder <eder@fortiss.org>
parent b8ce5d02
CustomSimulationFXViewBase.java 7c1b4c58ee68a72dbab0f619789a396f9b1bff14 YELLOW
DataStateTableViewFX.java 1513d51a55600b61cbe3248adf8668a4f0d62d48 YELLOW
GraphicalSimulationFXView.java 742b702a1ad98b053999b477fd6509f2c43df90b RED
GraphicalSimulationFXView.java b88f10f049e926b21d383b60756c4461f00e36ca YELLOW
GraphicalStructureSimulationFXView.java cb535487d7e993220b7f741dda2aee897c03ec5a YELLOW
InputOutputTableFXView.java c6cc89136fed287864303d98efae38e3da0acbe3 YELLOW
SimulationFXViewBase.java d5ef82a988c84b9e22612fe88c5ebdca4bd16067 YELLOW
......@@ -76,7 +76,7 @@ public abstract class GraphicalSimulationFXView<T extends EObject>
/** {@inheritDoc} */
@Override
public final Parent createFXPartScene() {
public Parent createFXPartScene() {
ComponentModelFactory delegatingModelFactory = new ComponentModelFactory(getModelElement());
GraphicalSimulationFXView<T>.SimulationComponentVisualFactory delegatingVisualFactory =
new SimulationComponentVisualFactory();
......
......@@ -116,10 +116,10 @@
point="org.eclipse.ui.views">
<view
allowMultiple="true"
class="org.fortiss.af3.state.ui.simulator.views.GraphicalStateSimulationView"
class="org.fortiss.af3.state.ui.simulator.views.GraphicalStateSimulationFXView"
icon="icons/structure.png"
id="org.fortiss.af3.state.ui.simulator.views.GraphicalStateSimulationView"
name="Automaton Simulation UI"
id="org.fortiss.af3.state.ui.simulator.views.GraphicalStateSimulationFXView"
name="Automaton Simulation FX UI"
restorable="false">
</view>
<view
......
......@@ -8,7 +8,7 @@ StateAutomatonFXEditor.java eea88e496c873ec92f6b2a0735cbd3d542a3063f GREEN
StateAutomatonFXEditorBase.java 901e1ce52a2a53fb73c160b0af7fd7fbfc1e3044 GREEN
StateAutomatonFXEditorBinding.java 5fae7a8e04236c07d176a2b1ed22f7043e3a09fe GREEN
StateAutomatonFXEditorBindingBase.java c2bf20b1e1d709a9c7662a62795662f8fc33b855 GREEN
StateAutomatonModelFactory.java 07989fa95608fc8ce25e977cba898cf94932e0ae GREEN
StateAutomatonVisualFactory.java c6a118c966f2ac5692a3077b168501ba12267cf9 GREEN
StateAutomatonModelFactory.java 8f1fa1f0abc7a49335adfe6704dcea29709f4ee3 YELLOW
StateAutomatonVisualFactory.java a440ce07d3e21a0f1b3235f74ff6d84a9869d782 YELLOW
StateFXEditor.java 88e2e7b328650f045c9465b314c30b271edebda3 GREEN
StateFXEditorBinding.java 999bb18112d5ffe35642b475e2cc7d231b822d02 GREEN
......@@ -20,17 +20,17 @@ import static java.util.Objects.requireNonNull;
import java.util.List;
import org.fortiss.tooling.common.ui.javafx.lwfxef.model.IModelFactory;
import org.fortiss.af3.state.model.State;
import org.fortiss.af3.state.model.StateAutomaton;
import org.fortiss.af3.state.model.TransitionSegment;
import org.fortiss.tooling.common.ui.javafx.lwfxef.model.IModelFactory;
/**
* The implementation of the {@link IModelFactory} for the {@link StateAutomaton} editor.
*
* @author hoelzl
*/
final class StateAutomatonModelFactory implements IModelFactory {
public final class StateAutomatonModelFactory implements IModelFactory {
/** The currently edited state. */
private final State rootElement;
......
......@@ -37,7 +37,7 @@ import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisualFactory;
*
* @author hoelzl
*/
final class StateAutomatonVisualFactory implements IVisualFactory {
public class StateAutomatonVisualFactory implements IVisualFactory {
/** Constructor */
public StateAutomatonVisualFactory() {
......
DiagramStateTransitionSegmentConnectorVisual.java 77fd78443e8a72b651f55f522f62e9c62a50ce10 GREEN
StateTransitionSegmentConnectorVisual.java 768004d1d5f68fcc11668987a6b2e404e8d522f4 GREEN
StateVisual.java e6c6df6613a01e087ff962093d2e186d066d6a17 GREEN
StateVisual.java 00be549c433456a656e8e34fb57bbdb116101270 YELLOW
......@@ -21,11 +21,11 @@ import static org.fortiss.af3.state.ui.AF3StateUIActivator.PLUGIN_ID;
import static org.fortiss.tooling.common.ui.javafx.util.GraphicUtils.convertColor;
import static org.fortiss.tooling.common.ui.javafx.util.GraphicUtils.getFXImage;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IContentVisual;
import org.fortiss.af3.state.model.State;
import org.fortiss.af3.state.model.StateAutomaton;
import org.fortiss.tooling.base.ui.editor.fx.visual.NamedLayoutedEllipticContentVisual;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IContentVisual;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
......@@ -36,7 +36,7 @@ import javafx.scene.paint.Paint;
*
* @author hoelzl
*/
public final class StateVisual extends NamedLayoutedEllipticContentVisual<State> {
public class StateVisual extends NamedLayoutedEllipticContentVisual<State> {
/** The fill color used by initial states. */
private static final Color INITIAL_STATE_COLOR =
......
DataStateSimulationViewMenuContributor.java 29904aac245a4e0c43b8dc04ae4c3a0adfbfd82e YELLOW
DataStateTableView.java 37fe2b1219b52a5a09214565101979b985c2cf98 GREEN
GraphicalStateSimulationFXView.java 52641f51f69adc321bd24383433495baeb61fac0 RED
GraphicalStateSimulationView.java 4e9e7c53cb9ce0bd259cb2a89e79172015cc1395 GREEN
GraphicalStateViewMenuContributor.java 229a7b5496b7ee318e5937e0bc875102e2e5f664 GREEN
GraphicalStateViewMenuContributor.java d768b5c5b1850092e73c7078acb6d96e886fc1da YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2011 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.state.ui.simulator.views;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.ui.simulatorfx.views.GraphicalSimulationFXView;
import org.fortiss.af3.state.model.State;
import org.fortiss.af3.state.model.StateAutomaton;
import org.fortiss.af3.state.model.TransitionSegment;
import org.fortiss.af3.state.model.TransitionSegmentSpecification;
import org.fortiss.af3.state.simulator.ExecutableStateAutomatonSpecification;
import org.fortiss.af3.state.ui.editor.fx.StateAutomatonControllerFactory;
import org.fortiss.af3.state.ui.editor.fx.StateAutomatonModelFactory;
import org.fortiss.af3.state.ui.editor.fx.StateAutomatonVisualFactory;
import org.fortiss.af3.state.ui.editor.fx.visual.StateVisual;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.base.ui.editor.fx.controller.LayoutedRectangularResizableContentController;
import org.fortiss.tooling.base.ui.editor.fx.visual.NamedLayoutedCurveLinkVisual;
import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramCoordinate;
import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewer;
import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewerFeatures;
import org.fortiss.tooling.common.ui.javafx.lwfxef.change.Change;
import org.fortiss.tooling.common.ui.javafx.lwfxef.controller.IClickController;
import org.fortiss.tooling.common.ui.javafx.lwfxef.controller.IController;
import org.fortiss.tooling.common.ui.javafx.lwfxef.controller.base.ClickControllerBase;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IContentVisual;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.ILinkVisual;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
/**
* View for the graphical simulation of state automata.
*
* @author ratiu
*/
public class GraphicalStateSimulationFXView extends GraphicalSimulationFXView<Component> {
/** Stores the view ID. */
public static final String ID = GraphicalStateSimulationFXView.class.getName();
// /** The specification displayed in this view. */
// private Component stateComponentSpecification;
/** Constructor. */
public GraphicalStateSimulationFXView() {
super(Component.class);
}
/** {@inheritDoc} */
@Override
public Parent createFXPartScene() {
StateAutomaton automaton = null;
for(IModelElementSpecification sp : getModelElement().getSpecifications()) {
if(sp instanceof StateAutomaton) {
automaton = (StateAutomaton)sp;
break;
}
}
StateAutomatonModelFactory delegatingModelFactory =
new StateAutomatonModelFactory(automaton);
SimulationAutomatonVisualFactory delegatingVisualFactory =
new SimulationAutomatonVisualFactory();
SimulationAutomatonControllerFactory delegatingControllerFactory =
new SimulationAutomatonControllerFactory();
viewer = new DiagramViewer(delegatingModelFactory, delegatingVisualFactory,
delegatingControllerFactory, cb -> modelSelected(), chg -> applyModelChange());
DiagramViewerFeatures features = viewer.getFeatures();
// extend zoom factors
features.setZoomFactors(new double[] {0.5, 0.75, 1, 1.5, 2, 4, 6});
features.setZoomFactorIndex(2); // Zoom
// x1
return viewer.getVisualNode();
}
/** {@inheritDoc} */
@Override
protected void setModelElement(Component component) {
StateAutomaton automaton = null;
for(IModelElementSpecification sp : getModelElement().getSpecifications()) {
if(sp instanceof StateAutomaton) {
automaton = (StateAutomaton)sp;
break;
}
}
viewer.updateModelVisual(automaton);
}
/** {@inheritDoc} */
@Override
protected void updateVisuals(Component component) {
viewer.updateAllVisuals();
}
/** {@inheritDoc} */
@Override
protected void setFxFocus() {
viewer.requestFocus();
}
/** Visual Factory for Channels in simulation to display simulated values. */
public final class SimulationAutomatonVisualFactory extends StateAutomatonVisualFactory {
/** {@inheritDoc} */
@Override
public ILinkVisual createLinkVisual(ILinkMVCBundle modelBundle) {
Object linkObj = modelBundle.getModel();
if(linkObj instanceof TransitionSegment) {
return new NamedLayoutedCurveLinkVisual<TransitionSegment>(modelBundle,
TransitionSegment.class) {
/** {@inheritDoc} */
@Override
protected Paint getLineColor() {
Object model = modelBundle.getModel();
if(model instanceof TransitionSegment) {
TransitionSegment ts = (TransitionSegment)model;
// Find the current last fired transition
// lastFiredTransitionSegments represents the current last fired
// transition
if(executable != null) {
ExecutableStateAutomatonSpecification exec =
(ExecutableStateAutomatonSpecification)executable;
// currentState = exec.getCurrentState();
for(TransitionSegmentSpecification tsp : exec
.getLastFiredTransitionSegments()) {
if(tsp.getTransitionSegment().equals(ts)) {
return Color.RED;
}
}
}
}
return super.getLineColor();
}
};
}
return null;
}
/** {@inheritDoc} */
@Override
public IContentVisual createContentVisual(IContentMVCBundle modelBundle) {
Object modelObj = modelBundle.getModel();
if(modelObj instanceof State) {
return new StateVisual(modelBundle) {
/** {@inheritDoc} */
@Override
protected Paint getFillColor() {
Object model = modelBundle.getModel();
if(model instanceof State) {
State state = (State)model;
if(executable != null) {
// Find the current active state and last fired transition
// currentState represents the current active State
ExecutableStateAutomatonSpecification exec =
(ExecutableStateAutomatonSpecification)executable;
State currentState = exec.getCurrentState();
if(currentState.equals(state)) {
return Color.RED;
}
}
}
return super.getFillColor();
}
};
}
return null;
}
}
/** Component controller factory for simulation context. */
public final class SimulationAutomatonControllerFactory
extends StateAutomatonControllerFactory {
/** {@inheritDoc} */
@Override
public IController createContentController(IContentMVCBundle model) {
return new LayoutedRectangularResizableContentController<State>(model, State.class) {
/** {@inheritDoc} */
@Override
public IClickController getClickController(Node node,
DiagramCoordinate diagramLocation) {
return new ClickControllerBase() {
@Override
public Change doubleClick(MouseEvent event, Node node,
DiagramCoordinate diagramLocation) {
// TODO
// ISimulationContextMenuContributor contrib =
// ISimulationContextMenuService.INSTANCE
// .getTopMostContributor(GraphicalSimulationFXView.this);
// if(contrib != null) {
// IContributionItem contribItem = contrib.getContributedItem(
// GraphicalSimulationFXView.this, getModelElement());
// if(contribItem instanceof ActionContributionItem)
// ((ActionContributionItem)contribItem).getAction().run();
// }
return null; // no changes to model
}
};
}
};
}
}
}
......@@ -41,6 +41,7 @@ import org.fortiss.tooling.base.ui.editpart.ConnectorEditPartBase;
*
* @author ratiu
*/
@Deprecated
public class GraphicalStateSimulationView extends
org.fortiss.af3.component.ui.simulator.component.GraphicalSimulationView<Component> {
......
......@@ -40,6 +40,6 @@ public class GraphicalStateViewMenuContributor extends SimulationContextMenuCont
/** {@inheritDoc} */
@Override
public String getViewID() {
return GraphicalStateSimulationView.ID;
return GraphicalStateSimulationFXView.ID;
}
}
Markdown is supported
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