Skip to content

Commit

Permalink
Fixes issue #3103.
Browse files Browse the repository at this point in the history
Rename all "Unsynchronize" to "Desynchronize". Changes icons. Adds
possiblities to zoom, update, take snapshots...
  • Loading branch information
AlexisDrogoul committed Aug 4, 2021
1 parent 7978fd8 commit f9a5c92
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 276 deletions.
5 changes: 4 additions & 1 deletion msi.gama.core/src/msi/gama/common/interfaces/IGamaView.java
Expand Up @@ -62,7 +62,7 @@ public interface Test {

}

public interface Display {
public interface Display extends IGamaView {

boolean containsPoint(int x, int y);

Expand All @@ -84,6 +84,7 @@ public interface Display {

void showToolbar();

@Override
LayeredDisplayOutput getOutput();

int getIndex();
Expand All @@ -93,6 +94,8 @@ public interface Display {
default List<String> getCameraNames() {
return Collections.EMPTY_LIST;
}

void takeSnapshot();
}

public interface Error {
Expand Down
28 changes: 12 additions & 16 deletions msi.gama.core/src/msi/gama/outputs/AbstractDisplayOutput.java
Expand Up @@ -38,7 +38,7 @@ public AbstractDisplayOutput(final IDescription desc) {

final Runnable opener = () -> {
view = getScope().getGui().showView(getScope(), getViewId(), isUnique() ? null : getName(), 1); // IWorkbenchPage.VIEW_ACTIVATE
if (view == null) { return; }
if (view == null) return;
view.addOutput(AbstractDisplayOutput.this);
};

Expand All @@ -65,22 +65,18 @@ public boolean init(final IScope scope) throws GamaRuntimeException {

@Override
public void dispose() {
if (disposed) { return; }
if (disposed) return;
disposed = true;
if (view != null) {
view.removeOutput(this);
view = null;
}
if (getScope() != null) {
GAMA.releaseScope(getScope());
}
if (getScope() != null) { GAMA.releaseScope(getScope()); }
}

@Override
public void update() throws GamaRuntimeException {
if (view != null) {
view.update(this);
}
if (view != null) { view.update(this); }
}

@Override
Expand All @@ -96,25 +92,25 @@ public boolean isSynchronized() {
@Override
public void setSynchronized(final boolean sync) {
synchro = sync;
if (view != null) {
view.updateToolbarState();
}
if (view != null) { view.updateToolbarState(); }
}

@Override
public void setPaused(final boolean pause) {
super.setPaused(pause);
if (view != null) {
view.updateToolbarState();
}
if (view != null) { view.updateToolbarState(); }
}

@Override
public IGamaView getView() {
return view;
}

@Override
public String getId() {
final String cName = this.getDescription().getModelDescription().getAlias();
if (cName != null && !cName.equals("") && !getName().contains("#")) {
if (cName != null && !"".equals(cName) && !getName().contains("#"))
return isUnique() ? getViewId() : getViewId() + getName() + "#" + cName;
}
return isUnique() ? getViewId() : getViewId() + getName();
}

Expand Down
8 changes: 8 additions & 0 deletions msi.gama.core/src/msi/gama/outputs/IDisplayOutput.java
Expand Up @@ -10,6 +10,8 @@
********************************************************************************************************/
package msi.gama.outputs;

import msi.gama.common.interfaces.IGamaView;

/**
* Display outputs extend regular outputs to represent and serve as the logical model of views displayed on the user
* interface.
Expand Down Expand Up @@ -80,4 +82,10 @@ public interface IDisplayOutput extends IOutput {
default boolean isAutoSave() {
return false;
}

/**
* Returns the GamaView associated with this output
*/

IGamaView getView();
}
61 changes: 25 additions & 36 deletions msi.gama.core/src/msi/gama/outputs/InspectDisplayOutput.java
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* msi.gama.outputs.InspectDisplayOutput.java, in plugin msi.gama.core,
* is part of the source code of the GAMA modeling and simulation platform (v. 1.8.1)
*
* msi.gama.outputs.InspectDisplayOutput.java, in plugin msi.gama.core, is part of the source code of the GAMA modeling
* and simulation platform (v. 1.8.1)
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package msi.gama.outputs;

Expand Down Expand Up @@ -129,7 +129,7 @@ public InspectDisplayOutput(final IDescription desc) {
}
type = getLiteral(IKeyword.TYPE);
if (type == null) {
if (getKeyword().equals(IKeyword.BROWSE)) {
if (IKeyword.BROWSE.equals(getKeyword())) {
type = IKeyword.TABLE;
} else {
type = IKeyword.AGENT;
Expand All @@ -141,16 +141,12 @@ public InspectDisplayOutput(final IDescription desc) {
@Override
public boolean init(final IScope scope) {
super.init(scope);
if (type.equals(IKeyword.AGENT) && getValue() != null) {
lastValue = getValue().value(getScope());
}
if (IKeyword.AGENT.equals(type) && getValue() != null) { lastValue = getValue().value(getScope()); }
if (attributes != null) {
listOfAttributes = (Map<String, String>) Types.MAP.of(Types.STRING, Types.STRING).cast(getScope(),
attributes.value(getScope()), null, true);
}
if (rootAgent == null || rootAgent.dead()) {
rootAgent = getScope().getRoot();
}
if (rootAgent == null || rootAgent.dead()) { rootAgent = getScope().getRoot(); }
return true;
}

Expand Down Expand Up @@ -204,7 +200,7 @@ public InspectDisplayOutput(final IExperimentAgent a) {
}

public void launch(final IScope scope) throws GamaRuntimeException {
if (!scope.init(InspectDisplayOutput.this).passed()) { return; }
if (!scope.init(InspectDisplayOutput.this).passed()) return;
// TODO What to do in case of multi-simulations ???
if (scope.getSimulation() != null) {
scope.getSimulation().addOutput(InspectDisplayOutput.this);
Expand All @@ -221,9 +217,9 @@ public void launch(final IScope scope) throws GamaRuntimeException {
public boolean step(final IScope scope) {
// ((AbstractScope) getScope()).traceAgents = true;
if (IKeyword.TABLE.equals(type)) {
if (rootAgent == null || rootAgent.dead()) { return false; }
if (getValue() == null) { return true; }
if (getScope().interrupted()) { return false; }
if (rootAgent == null || rootAgent.dead()) return false;
if (getValue() == null) return true;
if (getScope().interrupted()) return false;
getScope().setCurrentSymbol(this);
lastValue = getScope().evaluate(getValue(), rootAgent).getValue();
}
Expand All @@ -232,7 +228,7 @@ public boolean step(final IScope scope) {

@Override
public boolean isUnique() {
return !type.equals(IKeyword.TABLE);
return !IKeyword.TABLE.equals(type);
}

@Override
Expand All @@ -242,42 +238,37 @@ public String getId() {

@Override
public String getViewId() {
if (IKeyword.TABLE.equals(type)) { return IGui.TABLE_VIEW_ID; }
if (IKeyword.TABLE.equals(type)) return IGui.TABLE_VIEW_ID;
return IGui.AGENT_VIEW_ID;

}

final static IAgent[] EMPTY = new IAgent[0];
final static IAgent[] EMPTY = {};

@Override
public IAgent[] getLastValue() {
if (IKeyword.TABLE.equals(type)) {
if (rootAgent == null || rootAgent.dead()) { return EMPTY; }
}
if (IKeyword.TABLE.equals(type) && (rootAgent == null || rootAgent.dead())) return EMPTY;
// DEBUG.LOG("Last value :" + lastValue);
if (lastValue instanceof IAgent) { return new IAgent[] { (IAgent) lastValue }; }
if (lastValue instanceof IAgent) return new IAgent[] { (IAgent) lastValue };
if (lastValue instanceof ISpecies && rootAgent != null) {
final IPopulation pop = rootAgent.getMicroPopulation((ISpecies) lastValue);
final IAgent[] result = pop.toArray();
return result;
return pop.toArray();
}
if (lastValue instanceof IContainer) { return ((IContainer<?, ?>) lastValue)
.listValue(getScope(), Types.NO_TYPE, false).toArray(new IAgent[0]); }
if (lastValue instanceof IContainer)
return ((IContainer<?, ?>) lastValue).listValue(getScope(), Types.NO_TYPE, false).toArray(new IAgent[0]);
return EMPTY;
}

public ISpecies getSpecies() {
final IExpression valueExpr = getValue();
if (valueExpr == null) { return null; }
if (valueExpr == null) return null;
final IType theType = valueExpr.getGamlType().getContentType();
if (theType == Types.get(IKeyword.MODEL)) { return getScope().getModel().getSpecies(); }
if (theType == Types.get(IKeyword.MODEL)) return getScope().getModel().getSpecies();
final SpeciesDescription sd = theType.getSpecies();
if (sd == null) { return getScope().getModel().getSpecies(IKeyword.AGENT); }
if (sd.equals(getScope().getModel().getDescription())) { return getScope().getModel().getSpecies(); }
if (sd == null) return getScope().getModel().getSpecies(IKeyword.AGENT);
if (sd.equals(getScope().getModel().getDescription())) return getScope().getModel().getSpecies();
String speciesName = sd.getName();
if (speciesName == null) {
speciesName = IKeyword.AGENT;
}
if (speciesName == null) { speciesName = IKeyword.AGENT; }
return rootAgent.getSpecies().getMicroSpecies(speciesName);
}

Expand All @@ -301,9 +292,7 @@ public Object executeOn(final IScope scope) throws GamaRuntimeException {
final IType theType = value.getGamlType();
if (theType.isAgentType()) {
GAMA.getGui().setSelectedAgent((IAgent) value.value(scope));
} else if (theType.isContainer()) {
ValuedDisplayOutputFactory.browse(scope.getRoot(), value);
}
} else if (theType.isContainer()) { ValuedDisplayOutputFactory.browse(scope.getRoot(), value); }
return value.value(scope);
}

Expand Down
30 changes: 23 additions & 7 deletions msi.gama.core/src/msi/gama/outputs/LayeredDisplayOutput.java
Expand Up @@ -17,6 +17,8 @@
import com.google.common.collect.Iterables;

import msi.gama.common.interfaces.IDisplaySurface;
import msi.gama.common.interfaces.IGamaView;
import msi.gama.common.interfaces.IGamaView.Display;
import msi.gama.common.interfaces.IGamlIssue;
import msi.gama.common.interfaces.IGui;
import msi.gama.common.interfaces.IKeyword;
Expand Down Expand Up @@ -347,15 +349,15 @@ public void validate(final IDescription d) {
if (parent != null) { handleInheritance(d, parent.toString()); }

final IExpressionDescription auto = d.getFacet(AUTOSAVE);
if (auto != null && auto.getExpression().isConst() && auto.getExpression().literalValue().equals(TRUE)) {
if (auto != null && auto.getExpression().isConst() && TRUE.equals(auto.getExpression().literalValue())) {
d.info("With autosave enabled, GAMA must remain the frontmost window and the display must not be covered or obscured by other windows",
IGamlIssue.GENERAL, auto.getTarget(), AUTOSAVE);
}
// Are we in OpenGL world ?
final IExpressionDescription type = d.getFacet(TYPE);
final Boolean isOpenGLDefault = !GamaPreferences.Displays.CORE_DISPLAY.getValue().equals("Java2D");
final Boolean isOpenGLDefault = !"Java2D".equals(GamaPreferences.Displays.CORE_DISPLAY.getValue());
final Boolean isOpenGLWanted = type == null ? isOpenGLDefault
: type.getExpression().literalValue().equals(LayeredDisplayData.OPENGL);
: LayeredDisplayData.OPENGL.equals(type.getExpression().literalValue());
if (type != null) {
// Addresses and fixes Issue 833.
final String s = type.getExpression().literalValue();
Expand All @@ -365,8 +367,8 @@ public void validate(final IDescription d) {
IGamlIssue.UNKNOWN_KEYWORD, TYPE);
return;
}
} else {
if (isOpenGLDefault) { d.setFacet(TYPE, LabelExpressionDescription.create(LayeredDisplayData.OPENGL)); }
} else if (isOpenGLDefault) {
d.setFacet(TYPE, LabelExpressionDescription.create(LayeredDisplayData.OPENGL));
}

final String camera = d.firstFacetFoundAmong(CAMERA_LOCATION, CAMERA_TARGET, CAMERA_ORIENTATION,
Expand Down Expand Up @@ -591,9 +593,23 @@ public void setIndex(final int index) {
@Override
public boolean isAutoSave() {
final IExpression e = getFacet(IKeyword.AUTOSAVE);
if (e == null) return false;
if (e == IExpressionFactory.FALSE_EXPR) return false;
if (e == null || e == IExpressionFactory.FALSE_EXPR) return false;
return true;
}

public void zoom(final int mode) {
if (mode < 0) {
surface.zoomOut();
} else if (mode == 0) {
surface.zoomFit();
} else {
surface.zoomIn();
}
}

@Override
public IGamaView.Display getView() {
return (Display) super.getView();
}

}
23 changes: 7 additions & 16 deletions msi.gama.core/src/msi/gama/outputs/MonitorOutput.java
Expand Up @@ -139,33 +139,27 @@ public boolean init(final IScope scope) {
super.init(scope);
if (colorExpression == null) {
final ITopLevelAgent sim = scope.getRoot();
if (sim != null) {
constantColor = sim.getColor();
}
if (sim != null) { constantColor = sim.getColor(); }
}
return true;
}

@Override
public boolean step(final IScope scope) {
getScope().setCurrentSymbol(this);
if (getScope().interrupted()) { return false; }
if (getScope().interrupted()) return false;
if (getValue() != null) {
try {
lastValue = getValue().value(getScope());
if (history != null) {
history.add(lastValue);
}
if (history != null) { history.add(lastValue); }
} catch (final GamaRuntimeException e) {
lastValue = ItemList.ERROR_CODE + e.getMessage();
}
} else {
lastValue = null;
}
if (constantColor == null) {
if (colorExpression != null) {
color = Cast.asColor(scope, colorExpression.value(scope));
}
if (constantColor == null && colorExpression != null) {
color = Cast.asColor(scope, colorExpression.value(scope));
}
return true;
}
Expand All @@ -182,9 +176,7 @@ public boolean isUnique() {
@Override
public String getName() {
String result = super.getName();
if (result == null) {
result = getExpressionText();
}
if (result == null) { result = getExpressionText(); }
return result;
}

Expand All @@ -204,8 +196,7 @@ protected void setValue(final IExpression value) {
}

public void saveHistory() {
if (getScope() == null) { return; }
if (history == null || history.isEmpty()) { return; }
if (getScope() == null || history == null || history.isEmpty()) return;
Files.newFolder(getScope(), monitorFolder);
String file =
monitorFolder + "/" + "monitor_" + getName() + "_cycle_" + getScope().getClock().getCycle() + ".csv";
Expand Down

0 comments on commit f9a5c92

Please sign in to comment.