Skip to content

Commit

Permalink
add possiblity to autosave facet to specify the path, file name
Browse files Browse the repository at this point in the history
  • Loading branch information
hqnghi88 committed May 21, 2021
1 parent b6444ca commit b010c3a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
27 changes: 21 additions & 6 deletions msi.gama.core/src/msi/gama/outputs/LayeredDisplayData.java
Expand Up @@ -99,6 +99,7 @@ public void notifyListeners(final Changes property, final Object value) {
* Properties
*/
private boolean isAutosaving = false;
private String autosavingPath = "";
private boolean isToolbarVisible = GamaPreferences.Displays.CORE_DISPLAY_TOOLBAR.getValue();
private boolean isSynchronized = GamaPreferences.Runtime.CORE_SYNC.getValue();
private String displayType =
Expand Down Expand Up @@ -194,6 +195,14 @@ public void setAutosave(final boolean autosave) {
this.isAutosaving = autosave;
}

public void setAutosavePath(final String p) {
this.autosavingPath = p;
}

public String getAutosavePath() {
return autosavingPath;
}

public boolean isWireframe() {
return isWireframe;
}
Expand Down Expand Up @@ -746,6 +755,9 @@ public void initWith(final IScope scope, final IDescription desc) {
if (auto.getGamlType().equals(Types.POINT)) {
setAutosave(true);
setImageDimension(Cast.asPoint(scope, auto.value(scope)));
} else if (auto.getGamlType().equals(Types.STRING)) {
setAutosave(true);
setAutosavePath(Cast.asString(scope, auto.value(scope)));
} else {
setAutosave(Cast.asBool(scope, auto.value(scope)));
}
Expand Down Expand Up @@ -935,12 +947,15 @@ private void setZNear(final Double zN) {
public void update(final IScope scope, final Facets facets) {
final IExpression auto = facets.getExpr(IKeyword.AUTOSAVE);
if (auto != null) {
if (auto.getGamlType().equals(Types.POINT)) {
setAutosave(true);
setImageDimension(Cast.asPoint(scope, auto.value(scope)));
} else {
setAutosave(Cast.asBool(scope, auto.value(scope)));
}
if (auto.getGamlType().equals(Types.POINT)) {
setAutosave(true);
setImageDimension(Cast.asPoint(scope, auto.value(scope)));
} else if (auto.getGamlType().equals(Types.STRING)) {
setAutosave(true);
setAutosavePath(Cast.asString(scope, auto.value(scope)));
} else {
setAutosave(Cast.asBool(scope, auto.value(scope)));
}
}
// /////////////// dynamic Lighting ///////////////////

Expand Down
Expand Up @@ -242,7 +242,7 @@
doc = @doc ("Set the distances to the far depth clipping planes. Must be positive.")),
@facet (
name = IKeyword.AUTOSAVE,
type = { IType.BOOL, IType.POINT },
type = { IType.BOOL, IType.POINT, IType.STRING },
optional = true,
doc = @doc ("Allows to save this display on disk. A value of true/false will save it at a resolution of 500x500. A point can be passed to personalize these dimensions. Note that setting autosave to true (or to any other value than false) in a display will synchronize all the displays defined in the experiment")), },
omissible = IKeyword.NAME)
Expand Down
Expand Up @@ -16,6 +16,7 @@
import msi.gama.common.util.ImageUtils;
import msi.gama.outputs.IDisplayOutput;
import msi.gama.outputs.LayeredDisplayData;
import msi.gama.outputs.LayeredDisplayOutput;
import msi.gama.runtime.GAMA;
import msi.gama.runtime.IScope;
import msi.gama.runtime.exceptions.GamaRuntimeException;
Expand All @@ -36,9 +37,10 @@ void doSnapshot(final IDisplayOutput output, final IDisplaySurface surface, fina

final int width = w == -1 ? surface.getWidth() : w;
final int height = h == -1 ? surface.getHeight() : h;
final String file = snapshotFile + "_size_" + width + "x" + height + "_cycle_" + scope.getClock().getCycle()
+ "_time_" + java.lang.System.currentTimeMillis() + ".png";

final String autosavePath=data.getAutosavePath();
final String file =autosavePath!=""?autosavePath:(snapshotFile + "_size_" + width + "x" + height + "_cycle_" + scope.getClock().getCycle()
+ "_time_" + java.lang.System.currentTimeMillis() + ".png");
System.out.println("xxx "+file);
BufferedImage image = null;
if (GamaPreferences.Displays.DISPLAY_FAST_SNAPSHOT.getValue()) {
try {
Expand Down

0 comments on commit b010c3a

Please sign in to comment.