diff --git a/gama.extension.serialize/models/Serialization/models/Serialize Operators - Restore simulation.gaml b/gama.extension.serialize/models/Serialization/models/Serialize Operators - Restore simulation.gaml index 8ef23cbab1..1322812dfe 100644 --- a/gama.extension.serialize/models/Serialization/models/Serialize Operators - Restore simulation.gaml +++ b/gama.extension.serialize/models/Serialization/models/Serialize Operators - Restore simulation.gaml @@ -54,7 +54,7 @@ experiment "Repeated Simulations" type: gui { saved_step <- serialize(self.simulation); } - reflex restore when: (cycle = 4) { + reflex restore when: (cycle mod 4) = 0 { write "================ begin restore " + self + " - " + cycle; restore simulation from: saved_step; write "================ end restore " + self + " - " + cycle; diff --git a/gama.extension.serialize/models/Serialization/models/Serialize and Deserialize Objects.gaml b/gama.extension.serialize/models/Serialization/models/Serialize and Deserialize Objects.gaml index dfc1206fec..c80b46e8ab 100644 --- a/gama.extension.serialize/models/Serialization/models/Serialize and Deserialize Objects.gaml +++ b/gama.extension.serialize/models/Serialization/models/Serialize and Deserialize Objects.gaml @@ -12,13 +12,15 @@ global { init { list objects <- [[1,2,3,4], "fff",rgb(100,100,100)]; + write "Base object list: " + objects; + write "\nIndividually serialized and deserialized:"; loop o over: objects { string s <- serialize(o); write deserialize(s); } - write deserialize(serialize(objects)); + write "\nThe whole list serialized and deserialized: " + deserialize(serialize(objects)); } } diff --git a/gama.extension.serialize/src/gama/extension/serialize/binary/BinarySerialisation.java b/gama.extension.serialize/src/gama/extension/serialize/binary/BinarySerialisation.java index 324ae293bf..7cb070a739 100644 --- a/gama.extension.serialize/src/gama/extension/serialize/binary/BinarySerialisation.java +++ b/gama.extension.serialize/src/gama/extension/serialize/binary/BinarySerialisation.java @@ -149,12 +149,12 @@ public static void restoreFromString(final IAgent agent, final String string) { byte[] all = string.getBytes(ISerialisationConstants.STRING_BYTE_ARRAY_CHARSET); restoreFromBytes(agent, all); } catch (Throwable e) { - e.printStackTrace(); + // e.printStackTrace(); // The string is maybe a path ? try { restoreFromFile(agent, string); } catch (Throwable ex) { - throw GamaRuntimeException.create(ex, agent.getScope()); + GAMA.reportAndThrowIfNeeded(agent.getScope(),GamaRuntimeException.create(ex, agent.getScope()), true); } } } diff --git a/gama.extension.serialize/src/gama/extension/serialize/gaml/RestoreStatement.java b/gama.extension.serialize/src/gama/extension/serialize/gaml/RestoreStatement.java index dd19d681d3..1fece697db 100644 --- a/gama.extension.serialize/src/gama/extension/serialize/gaml/RestoreStatement.java +++ b/gama.extension.serialize/src/gama/extension/serialize/gaml/RestoreStatement.java @@ -66,9 +66,8 @@ optional = false, doc = @doc ("The file or the string from which to restore the agent")) }, omissible = IKeyword.TARGET) -@doc ("Allows to restore any agent that has been previously serialised or saved to a file, e.g. `string s <- serialize(a, 'json'); ... restore a from: s; `" - + " or `save simulation to: 'sim.gsim' format: `binary`; ... restore simulation from: file('sim.gsim') `") -@SuppressWarnings ({ "unchecked", "rawtypes" }) +@doc ("Allows to restore any agent that has been previously serialised or saved to a file, e.g. `string s <- serialize(a);` ... `restore a from: s;`" + + " or `save simulation to: 'sim.gsim' format: 'binary';` ... `restore simulation from: file('sim.gsim');`") public class RestoreStatement extends AbstractStatement { /** The header. */ diff --git a/gama.extension.serialize/src/gama/extension/serialize/gaml/SerialisationOperators.java b/gama.extension.serialize/src/gama/extension/serialize/gaml/SerialisationOperators.java index f391af277e..c39d3827e8 100644 --- a/gama.extension.serialize/src/gama/extension/serialize/gaml/SerialisationOperators.java +++ b/gama.extension.serialize/src/gama/extension/serialize/gaml/SerialisationOperators.java @@ -25,6 +25,7 @@ import gama.core.common.interfaces.IKeyword; import gama.core.common.util.StringUtils; import gama.core.metamodel.agent.IAgent; +import gama.core.runtime.GAMA; import gama.core.runtime.IScope; import gama.core.runtime.exceptions.GamaRuntimeException; import gama.core.util.IContainer; @@ -153,10 +154,10 @@ public static String toGeoJSon(final IScope scope, final IExpression spec, final @test ("to_json(font('Helvetica')) = '{\"gaml_type\":\"font\",\"name\":\"Helvetica\",\"style\":0,\"size\":12}'") @test ("to_json(point(20,10)) = '{\"gaml_type\":\"point\",\"x\":20.0,\"y\":10.0,\"z\":0.0}'") @doc ( - value = "Serializes any object/agent/simulation into a string, using the json format. A flag can be passed to enable/disable pretty printing (false by default)." - + "The format used by GAMA follows simple rules. int, float, bool, string values are outputted as they are. nil is outputted as 'null'. A list is outputted as a json array. Any other object or agent is outputted as a json object. If this object possesses the \"gaml_type\" attribute, " - + "it is an instance of the corresponding type, and the members that follow contain the attributes and the values necessary to reconstruct it. If it has the \"agent_reference\" attribute, its value represent the reference to an agent. If any reference to an agent is found, the " - + "json string returned will be an object with two attributes: \"gama_object\", the object containing the references, and \"reference_table\" a dictionary mapping the references to the json description of the agents (their species, name, index, and list of attributes). " + value = "Serializes any object/agent/simulation into a string, using the json format. A flag can be passed to enable/disable pretty printing (`false` by default)." + + "The format used by GAMA follows simple rules. `int`, `float`, `bool`, `string` values are outputted as they are. `nil` is outputted as `null`. A list is outputted as a json array. Any other object or agent is outputted as a json object. If this object possesses the attribute `gaml_type`, " + + "it is an instance of the corresponding type, and the members that follow contain the attributes and the values necessary to reconstruct it. If it has the `agent_reference` attribute, its value represents the reference to an agent. If any reference to an agent is found, the " + + "json string returned will be an object with two attributes: `gama_object`, the object containing the references, and `reference_table` a dictionary mapping the references to the json description of the agents (their `species`, `name`, `index`, and list of attributes). " + "This choice allows to manage cross references between agents", see = { "serialize", "to_gaml" }) public static String toJson(final IScope scope, final Object obj, final boolean pretty) { @@ -297,8 +298,8 @@ public static Object opEvalGaml(final IScope scope, final String gaml) { final IExpression e = GAML.getExpressionFactory().createExpr(gaml, d); return scope.evaluate(e, agent).getValue(); } catch (final GamaRuntimeException e) { - scope.getGui().getConsole().informConsole("Error in evaluating Gaml code : '" + gaml + "' in " - + scope.getAgent() + Strings.LN + "Reason: " + e.getMessage(), scope.getRoot()); + GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.error("Error in evaluating Gaml code : '" + gaml + "' in " + + scope.getAgent() + Strings.LN + "Reason: " + e.getMessage(), scope), false); return null; }