/** * Declaration for OctTransform object * * @version a1 Oct 1996 * @author Francis Chan */ public class OctTransform extends OctObject{ // values that transformType can/should take public static final int NO_TRANSFORM = 0; public static final int MIRROR_X = 1; public static final int MIRROR_Y = 2; public static final int ROT90 = 3; public static final int ROT180 = 4; public static final int ROT270 = 5; public static final int MX_ROT90 = 6; public static final int MY_ROT90 = 7; public static final int FULL_TRANSFORM = 8; // class info public static final String className = "OctTransform"; public static final int octFields = 3; public static final int objFields = 1; // fields /** * Point of Translation */ public OctPoint translation; /** * TransformType */ public int transformType; /** * 2D array indicating transformation */ public double[][] generalTransform = new double[2][2]; private double[] arrayHelper; // to help array transformation /** * Constructor of an OctTransform (for dynamic creation) * * @param octCell The OctCell that the object resides in * @param translation Point of translation * @param transformType Takes on values of octTransformType * @param generalTransform 2d array indicating transformation */ public OctTransform(OctCell octCell, OctPoint translation, int transformType, double[][] generalTransform) { this.translation = translation; this.transformType = transformType; this.generalTransform = generalTransform; this.octCell = octCell; octCell.AddElement(this); OctObjSetup(octCell.port, octFields, className); SetNumObjField(objFields); } /*----------------------------------------------------------- * * the code below is for data backend management * *-----------------------------------------------------------*/ /** * Constructor of an OctTransform (for loading from data back-end server) * @param octCell The OctCell that the object resides in */ public OctTransform(OctCell octCell) { this.octCell = octCell; OctObjSetup(octCell.port, octFields, className); } /** * Performs the neccessary overhead to allow this object to be * manipulated over the network */ protected void SetObjFields() { SetField(0, this.translation, PersistentObject.OBJECT); SetField(1, this.transformType, PersistentObject.INT); // 2-d double array too specific to be a Basic type // user has to choose a representation and map the array. // In other words, user has the freedom translate and hence // parse any (complicated) object into a supported form, // (most easily would be String) // double[][] generalTransform = new double[2][2]; arrayHelper = new double[5]; // 1 more for the number of entries arrayHelper[0] = 4; if (generalTransform != null) { arrayHelper[1] = generalTransform[0][0]; arrayHelper[2] = generalTransform[0][1]; arrayHelper[3] = generalTransform[1][0]; arrayHelper[4] = generalTransform[1][1]; } else { arrayHelper[1] = 0; arrayHelper[2] = 0; arrayHelper[3] = 0; arrayHelper[4] = 0; } SetField(2, this.arrayHelper, PersistentObject.ARRAY); OctSetField(octFields); } /** * Loads the fields of an OctBag from data back-end * * @param intId The integer (unique) Id for the object */ public boolean Load(int intId) { // double[][] generalTransform = new double[2][2]; if (LoadObject(this.objectClassName, null, intId) == false) { System.out.println("Couldn't load object " + className + " with intId " + intId); return false; } // sets up paramVector so it's ready for field assignment // this.transformType = GetField(1, PersistentObject.INT_INDICATOR); this.arrayHelper = GetField(2, PersistentObject.ARRAY_INDICATOR); // do something to set the values in the 2d double array...!! // overhead user has to bear to use non-basic types // not really a way to completely overcome if (arrayHelper[0] != 4){ System.out.println("Something went wrong, not 4 numbers were returned"); } else { generalTransform[0][0] = arrayHelper[1]; generalTransform[0][1] = arrayHelper[2]; generalTransform[1][0] = arrayHelper[3]; generalTransform[1][1] = arrayHelper[4]; } GetObjFields(); OctGetField(octFields); octCell.AddElement(this); OctObjSetup(octCell.port, octFields, className); SetNumObjField(objFields); return succeedTransmit; } /** * Should not be called */ public boolean Load(String strId) { return false; } /** * Filled if any of the fields are objects */ protected int GetObjFields() { this.translation = (OctPoint) GetField(0, PersistentObject.OBJECT_INDICATOR, 0); return OCT.OK; } }