File |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
283 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
342 |
answer = controlButtonResponse(getSimulator() != null, started);
break;
}
case "animate":
{
answer = animationPanel.getDrawingCommands();
break;
}
case "arrowDown":
{
animationPanel.pan(HtmlGridPanel.DOWN, 0.1);
break;
}
case "arrowUp":
{
animationPanel.pan(HtmlGridPanel.UP, 0.1);
break;
}
case "arrowLeft":
{
animationPanel.pan(HtmlGridPanel.LEFT, 0.1);
break;
}
case "arrowRight":
{
animationPanel.pan(HtmlGridPanel.RIGHT, 0.1);
break;
}
case "pan":
{
if (parts.length == 3)
{
// TODO: probably use the animatinPanel.pan()
int dx = Integer.parseInt(parts[1]);
int dy = Integer.parseInt(parts[2]);
double scaleX = animationPanel.getRenderableScale().getXScale(animationPanel.getExtent(),
animationPanel.getSize());
double scaleY = animationPanel.getRenderableScale().getYScale(animationPanel.getExtent(),
animationPanel.getSize());
Bounds2d extent = animationPanel.getExtent();
animationPanel.setExtent(new Bounds2d(extent.getMinX() - dx * scaleX,
extent.getMinX() - dx * scaleX + extent.getDeltaX(), extent.getMinY() + dy * scaleY,
extent.getMinY() + dy * scaleY + extent.getDeltaY()));
}
break;
}
case "introspect":
{
if (parts.length == 3)
{
int x = Integer.parseInt(parts[1]);
int y = Integer.parseInt(parts[2]);
List<Locatable> targets = new ArrayList<Locatable>();
try
{
Point2d point = animationPanel.getRenderableScale().getWorldCoordinates(new Point2D.Double(x, y),
animationPanel.getExtent(), animationPanel.getSize());
for (Renderable2dInterface<?> renderable : animationPanel.getElements())
{
if (animationPanel.isShowElement(renderable)
&& renderable.contains(point, animationPanel.getExtent()))
{
targets.add(renderable.getSource());
}
}
}
catch (Exception exception)
{
this.simulator.getLogger().always().warn(exception, "getSelectedObjects"); |
File |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
543 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
602 |
setSpeedFactor(speedFactor);
// System.out.println("speed factor changed to " + speedFactor);
}
catch (NumberFormatException exception)
{
answer = "<message>Error: " + exception.getMessage() + "</message>";
}
}
// System.out.println(answer);
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.setContentLength(answer.length());
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(answer);
response.flushBuffer();
baseRequest.setHandled(true);
}
/**
* @param active boolean; is the simulation active?
* @param started boolean; has the simulation been started?
* @return XML message to send to the server
*/
private String controlButtonResponse(final boolean active, final boolean started)
{
if (!active)
{
return "<controls>\n" + "<oneEventActive>false</oneEventActive>\n" + "<allEventsActive>false</allEventsActive>\n"
+ "<startStop>start</startStop>\n" + "<startStopActive>false</startStopActive>\n"
+ "<resetActive>false</resetActive>\n" + "</controls>\n";
}
if (started)
{
return "<controls>\n" + "<oneEventActive>false</oneEventActive>\n" + "<allEventsActive>false</allEventsActive>\n"
+ "<startStop>stop</startStop>\n" + "<startStopActive>true</startStopActive>\n"
+ "<resetActive>false</resetActive>\n" + "</controls>\n";
}
else
{
return "<controls>\n" + "<oneEventActive>true</oneEventActive>\n" + "<allEventsActive>true</allEventsActive>\n"
+ "<startStop>start</startStop>\n" + "<startStopActive>true</startStopActive>\n"
+ "<resetActive>false</resetActive>\n" + "</controls>\n";
}
}
/**
* Return the toggle button info for the toggle panel.
* @param panel the HtmlAnimationPanel
* @return the String that can be parsed by the select.html iframe
*/
private String getToggles(final HtmlAnimationPanel panel)
{
String ret = "<toggles>\n";
for (ToggleButtonInfo toggle : panel.getToggleButtons())
{
if (toggle instanceof ToggleButtonInfo.Text)
{
ret += "<text>" + toggle.getName() + "</text>\n";
}
else if (toggle instanceof ToggleButtonInfo.LocatableClass)
{
ret += "<class>" + toggle.getName() + "," + toggle.isVisible() + "</class>\n";
}
else if (toggle instanceof ToggleButtonInfo.Gis)
{
ret += "<gis>" + toggle.getName() + "," + ((ToggleButtonInfo.Gis) toggle).getLayerName() + ","
+ toggle.isVisible() + "</gis>\n";
}
}
ret += "</toggles>\n";
return ret;
}
/**
* Returns the simulation speed.
* @param simTime double; simulation time
* @return simulation speed
*/
private double getSimulationSpeed(final double simTime)
{
long now = System.currentTimeMillis();
if (this.lastWallTIme < 0 || this.lastWallTIme == now)
{
this.lastWallTIme = now;
this.prevSimTime = simTime;
return Double.NaN;
}
double speed = (simTime - this.prevSimTime) / (0.001 * (now - this.lastWallTIme));
this.prevSimTime = simTime;
this.lastWallTIme = now;
return speed;
}
} |
File |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
466 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
525 |
Object simTimeObject = getSimulator().getSimulatorTime();
double simTime = 0.0;
if (simTimeObject instanceof Double)
simTime = (double) simTimeObject;
else if (simTimeObject instanceof Float)
simTime = (float) simTimeObject;
else if (simTimeObject instanceof DoubleScalar)
simTime = ((DoubleScalar<?, ?>) simTimeObject).si;
else if (simTimeObject instanceof FloatScalar)
simTime = ((FloatScalar<?, ?>) simTimeObject).si;
else if (simTimeObject instanceof Calendar)
simTime = ((Calendar) simTimeObject).getTimeInMillis();
double speed = getSimulationSpeed(simTime);
String speedText = "";
if (!Double.isNaN(speed))
{
speedText = String.format("% 5.2fx ", speed);
}
answer = speedText;
break;
}
case "getToggles":
{
answer = getToggles(animationPanel);
break;
}
// we expect something of the form toggle|class|Node|true or toggle|gis|streets|false
case "toggle":
{
if (parts.length != 4)
System.err.println("wrong toggle commmand: " + message);
else
{
String toggleName = parts[1];
boolean gis = parts[2].equals("gis");
boolean show = parts[3].equals("true");
if (gis)
{
if (show)
animationPanel.showGISLayer(toggleName);
else
animationPanel.hideGISLayer(toggleName);
}
else
{
if (show)
animationPanel.showClass(toggleName);
else
animationPanel.hideClass(toggleName);
}
}
break;
}
default:
{
System.err.println("Got unknown message from client: " + command);
answer = "<message>" + request.getParameter("message") + "</message>";
break;
}
}
}
if (request.getParameter("slider") != null)
{
// System.out.println(request.getParameter("slider") + "\n");
try
{
int value = Integer.parseInt(request.getParameter("slider"));
// values range from 100 to 1400. 100 = 0.1, 400 = 1, 1399 = infinite
double speedFactor = 1.0;
if (value > 1398)
speedFactor = Double.MAX_VALUE;
else
speedFactor = Math.pow(2.15444, value / 100.0) / 21.5444; |
File |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
87 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
126 |
}
}
/**
* @return title
*/
public String getTitle()
{
return this.title;
}
/**
* @return simulator
*/
public SimulatorInterface<?> getSimulator()
{
return this.simulator;
}
/**
* @return animationPanel
*/
public HtmlAnimationPanel getAnimationPanel()
{
return this.animationPanel;
}
/**
* Try to start the simulator, and return whether the simulator has been started.
* @return whether the simulator has been started or not
*/
protected boolean startSimulator()
{
if (getSimulator() == null)
{
System.out.println("SIMULATOR == NULL");
return false;
}
try
{
System.out.println("START THE SIMULATOR");
getSimulator().start();
}
catch (SimRuntimeException exception)
{
this.simulator.getLogger().always().warn(exception, "Problem starting Simulator");
}
if (getSimulator().isStartingOrRunning())
{
return true;
}
this.dirtyControls = false; // undo the notification
return false;
}
/**
* Try to stop the simulator, and return whether the simulator has been stopped.
* @return whether the simulator has been stopped or not
*/
protected boolean stopSimulator()
{
if (getSimulator() == null)
{
return true;
}
try
{
System.out.println("STOP THE SIMULATOR");
getSimulator().stop();
}
catch (SimRuntimeException exception)
{
this.simulator.getLogger().always().warn(exception, "Problem stopping Simulator");
}
if (!getSimulator().isStartingOrRunning())
{
return true;
}
this.dirtyControls = false; // undo the notification
return false;
}
/**
* @param speedFactor double; the new speed factor
*/
protected void setSpeedFactor(final double speedFactor)
{
if (this.simulator instanceof DevsRealTimeAnimator)
{
((DevsRealTimeAnimator<?>) this.simulator).setSpeedFactor(speedFactor);
}
}
/** {@inheritDoc} */
@Override
public void notify(final Event event) throws RemoteException
{
if (event.getType().equals(SimulatorInterface.START_EVENT))
{
this.dirtyControls = true;
}
else if (event.getType().equals(SimulatorInterface.STOP_EVENT))
{
this.dirtyControls = true;
}
}
/**
* Delegate handle method from the main web server for this particular model.
* @param target t
* @param baseRequest br
* @param request r
* @param response re
* @throws IOException on error
* @throws ServletException on error
*/
public void handle(final String target, final Request baseRequest, final HttpServletRequest request, |
File |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
429 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
488 |
Object simTime = getSimulator().getSimulatorTime();
if (simTime instanceof Double || simTime instanceof Float)
{
double now = Math.round(((double) simTime) * 1000) / 1000d;
int seconds = (int) Math.floor(now);
int fractionalSeconds = (int) Math.floor(1000 * (now - seconds));
String timeText = String.format(" %02d:%02d:%02d.%03d ", seconds / 3600, seconds / 60 % 60,
seconds % 60, fractionalSeconds);
answer = timeText;
}
else if (simTime instanceof DoubleScalar)
{
double now = Math.round(((DoubleScalar<?, ?>) simTime).si * 1000) / 1000d;
int seconds = (int) Math.floor(now);
int fractionalSeconds = (int) Math.floor(1000 * (now - seconds));
String timeText = String.format(" %02d:%02d:%02d.%03d ", seconds / 3600, seconds / 60 % 60,
seconds % 60, fractionalSeconds);
answer = timeText;
}
else if (simTime instanceof FloatScalar)
{
double now = Math.round(((FloatScalar<?, ?>) simTime).si * 1000) / 1000d;
int seconds = (int) Math.floor(now);
int fractionalSeconds = (int) Math.floor(1000 * (now - seconds));
String timeText = String.format(" %02d:%02d:%02d.%03d ", seconds / 3600, seconds / 60 % 60,
seconds % 60, fractionalSeconds);
answer = timeText;
}
else
{
answer = simTime.toString();
}
break;
}
case "getSpeed":
{
Object simTimeObject = getSimulator().getSimulatorTime(); |
File |
Line |
nl/tudelft/simulation/dsol/web/DsolWebModel.java |
358 |
nl/tudelft/simulation/dsol/web/DsolWebServer.java |
417 |
this.simulator.getLogger().always().warn(exception, "getSelectedObjects");
}
if (targets.size() > 0)
{
Object introspectedObject = targets.get(0);
Property[] properties = new BeanIntrospector().getProperties(introspectedObject);
SortedMap<String, Property> propertyMap = new TreeMap<>();
for (Property property : properties)
propertyMap.put(property.getName(), property);
answer = "<introspection>\n";
for (Property property : propertyMap.values())
{
answer += "<property><field>" + property.getName() + "</field><value>" + property.getValue()
+ "</value></property>\n";
}
answer += "<introspection>\n";
}
else
{
answer = "<none />";
}
}
break;
}
case "zoomIn":
{
if (parts.length == 1)
animationPanel.zoom(0.9);
else
{
int x = Integer.parseInt(parts[1]);
int y = Integer.parseInt(parts[2]);
animationPanel.zoom(0.9, x, y);
}
break;
}
case "zoomOut":
{
if (parts.length == 1)
animationPanel.zoom(1.1);
else
{
int x = Integer.parseInt(parts[1]);
int y = Integer.parseInt(parts[2]);
animationPanel.zoom(1.1, x, y);
}
break;
}
case "zoomAll":
{
animationPanel.zoomAll();
break;
}
case "home":
{
animationPanel.home();
break;
}
case "toggleGrid":
{
animationPanel.setShowGrid(!animationPanel.isShowGrid());
break;
}
case "getTime":
{
Object simTime = getSimulator().getSimulatorTime(); |
File |
Line |
nl/tudelft/simulation/dsol/web/animation/HtmlGraphics2D.java |
277 |
nl/tudelft/simulation/dsol/web/animation/HtmlGraphics2D.java |
351 |
protected void addTransformPathFloat(Path2D.Float path, boolean fill)
{
if (fill)
this.commands.append("<transformPath>FILL");
else
this.commands.append("<transformPath>DRAW");
addAffineTransform();
addColor(this.color);
if (fill)
{
if (path.getWindingRule() == Path2D.WIND_EVEN_ODD)
this.commands.append(",WIND_EVEN_ODD");
else
this.commands.append(",WIND_NON_ZERO");
}
else
{
if (this.stroke instanceof BasicStroke)
this.commands.append("," + ((BasicStroke) this.stroke).getLineWidth());
else
this.commands.append(", 0.1");
} |
File |
Line |
nl/tudelft/simulation/dsol/web/AbstractTestDemoServer.java |
372 |
nl/tudelft/simulation/dsol/web/AbstractTestDemoServer.java |
389 |
answer.append("<doubleScalar key='" + pds.getExtendedKey() + "' name='" + pds.getShortName() + "' description='"
+ pds.getDescription() + "'><value>" + val + "</value>\n");
for (String unit : units)
{
Unit<?> unitValue = pds.getUnitParameter().getOptions().get(unit);
if (unitValue.equals(pds.getUnitParameter().getValue()))
answer.append("<unit chosen='true'>" + unit + "</unit>\n");
else
answer.append("<unit chosen='false'>" + unit + "</unit>\n");
}
answer.append("</doubleScalar>\n"); |