Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provides a fix for #379 #380

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions gama.core/src/gama/core/outputs/InspectDisplayOutput.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*******************************************************************************************************
*
* InspectDisplayOutput.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform
* .
* InspectDisplayOutput.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform .
*
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
Expand All @@ -15,15 +14,15 @@
import java.util.List;
import java.util.Map;

import gama.annotations.precompiler.IConcept;
import gama.annotations.precompiler.ISymbolKind;
import gama.annotations.precompiler.GamlAnnotations.doc;
import gama.annotations.precompiler.GamlAnnotations.example;
import gama.annotations.precompiler.GamlAnnotations.facet;
import gama.annotations.precompiler.GamlAnnotations.facets;
import gama.annotations.precompiler.GamlAnnotations.inside;
import gama.annotations.precompiler.GamlAnnotations.symbol;
import gama.annotations.precompiler.GamlAnnotations.usage;
import gama.annotations.precompiler.IConcept;
import gama.annotations.precompiler.ISymbolKind;
import gama.core.common.interfaces.IGui;
import gama.core.common.interfaces.IKeyword;
import gama.core.common.util.StringUtils;
Expand Down Expand Up @@ -333,22 +332,34 @@ public IAgent[] getLastValue() {
return EMPTY;
}

/**
* Gets the species.
*
* @return the species
*/
public ISpecies getSpecies() {
// /**
// * Gets the species.
// *
// * @return the species
// */
// public ISpecies getSpecies() {
// final IExpression valueExpr = getValue();
// if (valueExpr == null) return null;
// final IType theType = valueExpr.getGamlType().getContentType();
// 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();
// String speciesName = sd.getName();
// if (speciesName == null) { speciesName = IKeyword.AGENT; }
// return rootAgent.getSpecies().getMicroSpecies(speciesName);
// }

public SpeciesDescription getSpeciesDescription() {
final IExpression valueExpr = getValue();
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().getDescription();
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 Types.AGENT.getDenotedSpecies();
String speciesName = sd.getName();
if (speciesName == null) { speciesName = IKeyword.AGENT; }
return rootAgent.getSpecies().getMicroSpecies(speciesName);
if (speciesName == null) return Types.AGENT.getDenotedSpecies();
return rootAgent.getSpecies().getDescription().getMicroSpecies(speciesName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
import gama.core.runtime.exceptions.GamaRuntimeException;
import gama.core.util.file.csv.CsvWriter;
import gama.dev.DEBUG;
import gama.gaml.descriptions.SpeciesDescription;
import gama.gaml.descriptions.VariableDescription;
import gama.gaml.expressions.IExpression;
import gama.gaml.expressions.types.SpeciesConstantExpression;
import gama.gaml.operators.Files;
import gama.gaml.species.ISpecies;
import gama.gaml.types.IType;
import gama.gaml.types.Types;
import gama.gaml.variables.IVariable;
import gama.ui.experiment.menus.AgentsMenu;
import gama.ui.shared.controls.SwitchButton;
import gama.ui.shared.menus.GamaMenu;
Expand Down Expand Up @@ -256,7 +256,7 @@ public void addOutput(final IOutput output) {
* Update species.
*/
void updateSpecies() {
final ISpecies species = getOutput().getSpecies();
final SpeciesDescription species = getOutput().getSpeciesDescription();
final IExpression expr = getOutput().getValue();

final String name = species == null ? IKeyword.AGENT : species.getName();
Expand All @@ -269,7 +269,7 @@ void updateSpecies() {
selectedColumns.get(name).addAll(attributes.keySet());
} else if (getOutput().getValue() != null) {
if (species == null) return;
selectedColumns.get(name).addAll(species.getVarNames());
selectedColumns.get(name).addAll(species.getAttributeNames());
selectedColumns.get(name).removeAll(DONT_INSPECT_BY_DEFAULT);
}
Collections.sort(selectedColumns.get(name));
Expand Down Expand Up @@ -356,9 +356,9 @@ void fillAttributeMenu() {
attributesMenu.setToolTipText(tooltipText);
final boolean hasPreviousSelection = selectedColumns.get(speciesName) != null;
final InspectDisplayOutput output = getOutput();
final ISpecies species = output.getSpecies();
final List<String> names = new ArrayList(
getOutput().getAttributes() == null ? species.getVarNames() : getOutput().getAttributes().keySet());
final SpeciesDescription species = output.getSpeciesDescription();
final List<String> names = new ArrayList(getOutput().getAttributes() == null ? species.getAttributeNames()
: getOutput().getAttributes().keySet());
Collections.sort(names);
DEBUG.OUT("" + names);
for (final String name : names) {
Expand Down Expand Up @@ -452,7 +452,7 @@ public void widgetSelected(final SelectionEvent e) {
*/
String getSpeciesName() {
if (getOutput() == null) return "";
final ISpecies species = getOutput().getSpecies();
final SpeciesDescription species = getOutput().getSpeciesDescription();
if (species == null) return IKeyword.AGENT;
return species.getName();
}
Expand Down Expand Up @@ -699,8 +699,8 @@ public int compare(final Object e1, final Object e2) {
if (v2 == null) {
rc = 1;
} else {
final IVariable v = getOutput().getSpecies().getVar(attribute);
final int id = v.getType().id();
final VariableDescription v = getOutput().getSpeciesDescription().getAttribute(attribute);
final int id = v.getGamlType().id();
rc = switch (id) {
case IType.INT -> ((Integer) v1).compareTo((Integer) v2);
case IType.FLOAT -> ((Double) v1).compareTo((Double) v2);
Expand Down
Loading