All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentrafficsim.draw.road.GtuGeneratorPositionAnimation Maven / Gradle / Ivy

The newest version!
package org.opentrafficsim.draw.road;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Path2D;
import java.awt.image.ImageObserver;
import java.rmi.RemoteException;

import javax.naming.NamingException;

import org.opentrafficsim.base.geometry.OtsLocatable;
import org.opentrafficsim.base.geometry.OtsRenderable;
import org.opentrafficsim.draw.DrawLevel;
import org.opentrafficsim.draw.TextAlignment;
import org.opentrafficsim.draw.TextAnimation;
import org.opentrafficsim.draw.road.GtuGeneratorPositionAnimation.GtuGeneratorPositionData;

import nl.tudelft.simulation.naming.context.Contextualized;

/**
 * Animates a GtuGeneratorPosition.
 * 

* Copyright (c) 2022-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License. *

* @author Alexander Verbraeck * @author Peter Knoppers * @author Wouter Schakel */ public class GtuGeneratorPositionAnimation extends OtsRenderable { /** */ private static final long serialVersionUID = 20230204L; /** Chevron path to draw. */ private static final Path2D.Float PATH; static { PATH = new Path2D.Float(); addChevron(PATH, 0); addChevron(PATH, 1); addChevron(PATH, 2); } /** * Add chevron to drawing path. * @param path Path2D.Float; path. * @param number int; number of the chevron. */ private static void addChevron(final Path2D.Float path, final int number) { float x = number * 1.5f; path.moveTo(x, -1.0); path.lineTo(x + 1.0, 0.0); path.lineTo(x, 1.0); path.lineTo(x + 0.75, 1.0); path.lineTo(x + 1.75, 0.0); path.lineTo(x + 0.75, -1.0); path.lineTo(x, -1.0); } /** * Constructor. * @param source GtuGeneratorPositionData; source. * @param contextProvider OtsSimulatorInterface; simulator. * @throws NamingException when animation context cannot be created or retrieved * @throws RemoteException when remote context cannot be found */ public GtuGeneratorPositionAnimation(final GtuGeneratorPositionData source, final Contextualized contextProvider) throws RemoteException, NamingException { super(source, contextProvider); new Queue(source, contextProvider); } /** {@inheritDoc} */ @Override public void paint(final Graphics2D graphics, final ImageObserver observer) { graphics.setColor(Color.BLUE); setRendering(graphics); graphics.fill(PATH); resetRendering(graphics); } /** * Paints a queue counter with a GtuGeneratorPosition. *

* Copyright (c) 2022-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. *
* BSD-style license. See OpenTrafficSim License. *

* @author Alexander Verbraeck * @author Peter Knoppers * @author Wouter Schakel */ public class Queue extends TextAnimation { /** */ private static final long serialVersionUID = 20230204L; /** * Constructor. * @param source GtuGeneratorPositionData; source. * @param contextualized Contextualized; context provider * @throws NamingException when animation context cannot be created or retrieved * @throws RemoteException when remote context cannot be found */ public Queue(final GtuGeneratorPositionData source, final Contextualized contextualized) throws RemoteException, NamingException { super(source, () -> Integer.toString(source.getQueueCount()), 0.0f, 0.0f, TextAlignment.CENTER, Color.BLACK, 3.0f, 12.0f, 50f, contextualized, null, TextAnimation.RENDERWHEN10); } } /** * GtuGeneratorPositionData provides the information required to draw a GTU generator position. *

* Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. *
* BSD-style license. See OpenTrafficSim License. *

* @author Wouter Schakel */ public interface GtuGeneratorPositionData extends OtsLocatable { /** * Returns the queue count. * @return int; queue count. */ int getQueueCount(); /** {@inheritDoc} */ @Override default double getZ() { return DrawLevel.OBJECT.getZ(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy