Commit 1ac551cf authored by gsavin's avatar gsavin

Add a new parameter to add a value in the 'ui.class' attribute of boid nodes...

Add a new parameter to add a value in the 'ui.class' attribute of boid nodes to allow a by-species custom css.
parent 90861151
......@@ -478,9 +478,16 @@ public class BoidGraph extends AdjacencyListGraph {
else
species = getOrCreateSpecies(name);
if (key != null)
species.set(key, newValue == null ? null : newValue
.toString());
if (key != null) {
try {
species.set(key, newValue == null ? null : newValue
.toString());
} catch (IllegalArgumentException e) {
System.err.printf("(WW) invalid parameter '%s'\n",
key);
System.err.printf(" ignoring it.\n");
}
}
break;
}
......
......@@ -45,7 +45,7 @@ public class BoidSpecies implements Iterable<Boid> {
* Kinds of parameters.
*/
public static enum Parameter {
COUNT, ANGLE_OF_VIEW, VIEW_ZONE, SPEED_FACTOR, MAX_SPEED, MIN_SPEED, DIRECTION_FACTOR, ATTRACTION_FACTOR, REPULSION_FACTOR, INERTIA, FEAR_FACTOR
COUNT, ANGLE_OF_VIEW, VIEW_ZONE, SPEED_FACTOR, MAX_SPEED, MIN_SPEED, DIRECTION_FACTOR, ATTRACTION_FACTOR, REPULSION_FACTOR, INERTIA, FEAR_FACTOR, ADD_SPECIES_NAME_IN_UI_CLASS
}
/**
......@@ -135,6 +135,8 @@ public class BoidSpecies implements Iterable<Boid> {
*/
protected HashMap<String, Boid> boids;
protected boolean addSpeciesNameInUIClass;
private int currentIndex = 0;
private long timestamp = System.nanoTime();
......@@ -164,6 +166,7 @@ public class BoidSpecies implements Iterable<Boid> {
repulsionFactor = 0.001f;
inertia = 1.1f;
fearFactor = 1;
addSpeciesNameInUIClass = true;
this.color = new Color(ctx.random.nextFloat(), ctx.random.nextFloat(),
ctx.random.nextFloat());
......@@ -242,6 +245,9 @@ public class BoidSpecies implements Iterable<Boid> {
case ANGLE_OF_VIEW:
angleOfView = Double.parseDouble(val);
break;
case ADD_SPECIES_NAME_IN_UI_CLASS:
addSpeciesNameInUIClass = Boolean.parseBoolean(val);
break;
}
}
......@@ -278,10 +284,32 @@ public class BoidSpecies implements Iterable<Boid> {
void register(Boid b) {
boids.put(b.getId(), b);
if (addSpeciesNameInUIClass) {
String uiClass = b.getAttribute("ui.class");
if (uiClass == null)
uiClass = name;
else
uiClass = uiClass + " " + name;
b.setAttribute("ui.class", uiClass);
}
}
void unregister(Boid b) {
boids.remove(b.getId());
if (addSpeciesNameInUIClass) {
String uiClass = b.getAttribute("ui.class");
if (uiClass != null && uiClass.indexOf(name) != -1) {
uiClass = uiClass.replaceAll("(^|\\s)" + name + "($|\\s)", " ");
uiClass = uiClass.trim();
b.setAttribute("ui.class", uiClass);
}
}
}
/**
......
......@@ -6,7 +6,7 @@ null 0 0
#
cg ui.quality ui.antialias
cg ui.stylesheet="node { size: 4px; } edge { fill-color: grey; }"
cg ui.stylesheet="node { size: 4px; } node.moustik { fill-color: #1d1d1d; } edge { fill-color: grey; }"
#
# gs-boids attributes
......@@ -15,22 +15,26 @@ cg ui.stylesheet="node { size: 4px; } edge { fill-color: grey; }"
cg boids.max_steps=8000
cg boids.random_seed=2132134879
cg boids.area=1
cg boids.sleep_time=20
cg boids.sleep_time=30
#
# Moustik species
#
cg boids.species.moustik=org.graphstream.boids.BoidSpecies
cg boids.species.moustik.angle_of_view=0
cg boids.species.moustik.view_zone=0.15
cg boids.species.moustik.speed_factor=0.3
cg boids.species.moustik.max_speed=1
cg boids.species.moustik.min_speed=0.04
cg boids.species.moustik.direction_factor=0.1
cg boids.species.moustik.attraction_factor=0.5
cg boids.species.moustik.repulsion_factor=0.001
cg boids.species.moustik.inertia=1.1
cg boids.species.moustik.trail=0
cg boids.species.moustik.width=4
cg boids.species.moustik=org.graphstream.boids.BoidSpecies # Create a new species using class BoidSpecies
cg boids.species.moustik.angle_of_view=0 # Set angleOfView of this species to 0
cg boids.species.moustik.view_zone=0.15 # Set viewZone
cg boids.species.moustik.speed_factor=0.3 # Set speedFactor
cg boids.species.moustik.max_speed=1 # Set maxSpeed
cg boids.species.moustik.min_speed=0.04 # Set minSpeed
cg boids.species.moustik.direction_factor=0.1 # Set directionFactor
cg boids.species.moustik.attraction_factor=0.5 # Set attractionFactor
cg boids.species.moustik.repulsion_factor=0.001 # Set repulsionFactor
cg boids.species.moustik.inertia=1.1 # Set inertia
cg boids.species.moustik.add_species_name_in_ui_class=true # Tell species to add its name in the 'ui.class' attribute
# of node, so we can define a custom css for each species.
#
# This last command create 100 boids of the moustik species
#
cg boids.species.moustik.count=100
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