/* File: ArticulationParameter.java CVS Info: $Id: ArticulationParameter.java,v 1.2 1998/01/27 18:43:54 mcgredo Exp $ Compiler: jdk 1.3 */ package mil.navy.nps.dis; // package we belong to import mil.navy.nps.util.*; // General-purpose utilities import mil.navy.nps.disEnumerations.*; // Enumerations for DIS import java.io.*; // input/output library import java.util.*; // utilities /** * Articulation parameters are components of an entity that can move - this data is appended * to the EntityState PDU. * *@version 1.0 *@author Don McGregor (http://www.npsnet.org/~mcgredo) * *
* * This is a subclass of the PduElement class, the abstract class that all parts of a * PDU inherit from. It knows how to serialize, deserialize, and clone itself. It * is kept as a part of the EntityStatePdu.
* *
sizeOf = 16 bytes
.
*/
public static final int sizeOf = 16; // size, in bytes, of a serialized articulation parameter */
/**
*Default constructor--fills with zeros for all values.
*/
public ArticulationParameter() // default constructor
{
parameterTypeDesignator = new UnsignedByte(0);
changeIndicator = new UnsignedByte(0);
articulationAttachmentID = new UnsignedShort(0);
parameterType = new UnsignedInt(0);
parameterValue = 0.0;
return;
}
public Object clone()
{
ArticulationParameter newArticulationParam = new ArticulationParameter();
newArticulationParam.setParameterTypeDesignator(this.getParameterTypeDesignator());
newArticulationParam.setChangeIndicator(this.getChangeIndicator());
newArticulationParam.setArticulationAttachmentID(this.getArticulationAttachmentID());
newArticulationParam.setParameterType(this.getParameterType());
newArticulationParam.setParameterValue(this.getParameterValue());
newArticulationParam.decrementChangeIndicator();
return newArticulationParam;
}
/*
*@exception RuntimeException when IO Error occurs.
*/
public void serialize(DataOutputStream outputStream)
{
//super.serialize(outputStream); // No need to call super, since no ivars are in our direct superclass
try
{
parameterTypeDesignator.serialize(outputStream);
changeIndicator.serialize(outputStream);
articulationAttachmentID.serialize(outputStream);
parameterType.serialize(outputStream);
outputStream.writeDouble(parameterValue);
}
catch(IOException ioException) // catch-all for all IO exceptions in the above code
{
throw new
RuntimeException("Exception in ArticulationParameter. Error serializing unit.");
}
return;
}
/*
*@exception RuntimeException when IO Error occurs.
*/
public void deSerialize(DataInputStream inputStream)
{
// no need to call super, since there are no ivars in the superclass.
try
{
parameterTypeDesignator.deSerialize(inputStream);
changeIndicator.deSerialize(inputStream);
articulationAttachmentID.deSerialize(inputStream);
parameterType.deSerialize(inputStream);
parameterValue = inputStream.readDouble();
}
catch(IOException ioException) // catch-all for all IO exceptions in the above code
{
throw new
RuntimeException("Exception in ArticulationParameter. Error deSerializing unit.");
}
return;
}
public int length()
{
return sizeOf; // articulation parameters are sizeOf bytes long, defined above
}
public void printValues(int indentLevel, PrintStream printStream)
{
StringBuffer buf = ProtocolDataUnit.getPaddingOfLength(indentLevel);
int idx, superclassIndent = indentLevel;
printStream.println("ArticulationParameter ");
printStream.println(buf + "parameterTypeDesignator: " + parameterTypeDesignator.intValue());
printStream.println(buf + "changeIndicator: " + changeIndicator.intValue());
printStream.println(buf + "articulationAttachmentID: " + articulationAttachmentID.intValue());
printStream.println(buf + "parameterType: " + parameterType.longValue());
printStream.println(buf + "parameterValue: " + parameterValue);
return;
}
/**
Include index of which ArticulationPararameter is being printed.
*/
public void printValues(int indentLevel, PrintStream printStream, int idx)
{
StringBuffer buf = ProtocolDataUnit.getPaddingOfLength(indentLevel);
int superclassIndent = indentLevel;
printStream.println("ArticulationParameter " + idx);
printStream.println(buf + "parameterTypeDesignator: " + parameterTypeDesignator.intValue());
printStream.println(buf + "changeIndicator: " + changeIndicator.intValue());
printStream.println(buf + "articulationAttachmentID: " + articulationAttachmentID.intValue());
printStream.println(buf + "parameterType: " + parameterType.longValue());
printStream.println(buf + "parameterValue: " + parameterValue);
return;
}
public String toString ()
{
return "ArticulationParameter\n"
+ "parameterTypeDesignator: " + parameterTypeDesignator + "\n"
+ "changeIndicator: " + changeIndicator + "\n"
+ "articulationAttachmentID: " + articulationAttachmentID + "\n"
+ "parameterType: " + parameterType + "\n"
+ "parameterValue: " + parameterValue + "\n";
}
// accessor methods. The get() methods return a copy of the instance variable, rather than
// the instance variable itself.
public UnsignedByte getParameterTypeDesignator()
{ return (UnsignedByte)parameterTypeDesignator.clone();
}
public void setParameterTypeDesignator(UnsignedByte pParameterTypeDesignator)
{parameterTypeDesignator = pParameterTypeDesignator;
}
public void setParameterTypeDesignator(int pParameterTypeDesignator)
{ parameterTypeDesignator = new UnsignedByte(pParameterTypeDesignator);
}
public UnsignedByte getChangeIndicator()
{ return (UnsignedByte)changeIndicator.clone();
}
/**
* incremented automatically when parameterValue is changed, also available to users.
*/
public void incrementChangeIndicator()
{
if (changeIndicator.intValue() == UnsignedByte.MAX_UNSIGNED_BYTE_VALUE)
{
changeIndicator = new UnsignedByte (0);
}
else
{
changeIndicator = new UnsignedByte (changeIndicator.intValue() + 1);
}
return;
}
public void decrementChangeIndicator()
{
if (changeIndicator.intValue() == 0)
{
changeIndicator =
new UnsignedByte (UnsignedByte.MAX_UNSIGNED_BYTE_VALUE);
}
else
{
changeIndicator = new UnsignedByte (changeIndicator.intValue() - 1);
}
return;
}
public void setChangeIndicator(UnsignedByte pChangeIndicator)
{changeIndicator = pChangeIndicator;
}
public void setChangeIndicator(int pChangeIndicator)
{ changeIndicator = new UnsignedByte(pChangeIndicator);
}
public UnsignedShort getArticulationAttachmentID()
{ return (UnsignedShort)articulationAttachmentID.clone();
}
public void setArticulationAttachmentID(UnsignedShort pArticulationAttachmentID)
{articulationAttachmentID = pArticulationAttachmentID;
}
public void setArticulationAttachmentID(int pArticulationAttachmentID)
{ articulationAttachmentID = new UnsignedShort(pArticulationAttachmentID);
}
public UnsignedInt getParameterType()
{ return (UnsignedInt)parameterType.clone();
}
public void setParameterType(UnsignedInt pParameterType)
{parameterType = pParameterType;
}
public void setParameterType(int pParameterType)
{ parameterType = new UnsignedInt(pParameterType);
}
/**
* changed type of parameterValue from long to double (but note that value gets downcasted to float when sent to VRML)
*/
public double getParameterValue()
{ return parameterValue; // Don't have to copy, since this is a basic type, not an object
}
/**
*@deprecated 31 MAR 99, use setParameterValue(double) -- changed type of parameterValue from long to double
* to match DIS specification (nevertheless note that value gets further downcasted to float if sent to VRML)
*/
public void setParameterValue(long pParameterValue)
{
parameterValue = (double) pParameterValue;
incrementChangeIndicator();
}
public void setParameterValue(double pParameterValue)
{
parameterValue = pParameterValue;
incrementChangeIndicator();
}
} // end of class ArticulationParameter