Placement.java
Go to the documentation of this file.
00001 package edu.wpi.rail.jinteractiveworld.ros.msgs.interactiveworldmsgs;
00002 
00003 import edu.wpi.rail.jrosbridge.messages.Message;
00004 import edu.wpi.rail.jrosbridge.messages.geometry.Point;
00005 import edu.wpi.rail.jrosbridge.messages.geometry.Pose;
00006 
00007 import javax.json.Json;
00008 import javax.json.JsonArray;
00009 import javax.json.JsonObject;
00010 import java.io.StringReader;
00011 import java.util.Arrays;
00012 
00019 public class Placement extends Message {
00020 
00024         public static final String FIELD_ITEM = "item";
00025 
00029         public static final String FIELD_ROOM = "room";
00030 
00034         public static final String FIELD_SURFACE = "surface";
00035 
00039         public static final String FIELD_REFERENCE_FRAME_ID = "reference_frame_id";
00040 
00044         public static final String FIELD_POSITION = "position";
00045 
00049         public static final String FIELD_ROTATION = "rotation";
00050 
00054         public static final String TYPE = "interactive_world_msgs/Placement";
00055 
00056         private final Item item;
00057         private final Room room;
00058         private final Surface surface;
00059         private final String referenceFrameId;
00060         private final Point position;
00061         private final double rotation;
00062 
00066         public Placement() {
00067                 this(new Item(), new Room(), new Surface(), "", new Point(), 0.0);
00068         }
00069 
00086         public Placement(Item item, Room room, Surface surface, String referenceFrameId, Point position, double rotation) {
00087                 // build the JSON object
00088                 super(Json.createObjectBuilder().add(Placement.FIELD_ITEM, item.toJsonObject())
00089                                 .add(Placement.FIELD_ROOM, room.toJsonObject())
00090                                 .add(Placement.FIELD_SURFACE, surface.toJsonObject())
00091                                 .add(Placement.FIELD_REFERENCE_FRAME_ID, referenceFrameId)
00092                                 .add(Placement.FIELD_POSITION, position.toJsonObject())
00093                                 .add(Placement.FIELD_ROTATION, rotation).build(), Placement.TYPE);
00094                 this.item = item;
00095                 this.room = room;
00096                 this.surface = surface;
00097                 this.referenceFrameId = referenceFrameId;
00098                 this.position = position;
00099                 this.rotation = rotation;
00100         }
00101 
00107         public Item getItem() {
00108                 return this.item;
00109         }
00110 
00116         public Room getRoom() {
00117                 return this.room;
00118         }
00119 
00125         public Surface getSurface() {
00126                 return this.surface;
00127         }
00128 
00134         public String getReferenceFrameId() {
00135                 return this.referenceFrameId;
00136         }
00137 
00143         public Point getPosition() {
00144                 return this.position;
00145         }
00146 
00152         public double getRotation() {
00153                 return this.rotation;
00154         }
00155 
00159         @Override
00160         public Placement clone() {
00161                 return new Placement(this.item, this.room, this.surface, this.referenceFrameId, this.position, this.rotation);
00162         }
00163 
00172         public static Placement fromJsonString(String jsonString) {
00173                 // convert to a message
00174                 return Placement.fromMessage(new Message(jsonString));
00175         }
00176 
00185         public static Placement fromMessage(Message m) {
00186                 // get it from the JSON object
00187                 return Placement.fromJsonObject(m.toJsonObject());
00188         }
00189 
00198         public static Placement fromJsonObject(JsonObject jsonObject) {
00199                 // check the fields
00200                 Item item = jsonObject.containsKey(Placement.FIELD_ITEM) ? Item
00201                                 .fromJsonObject(jsonObject.getJsonObject(Placement.FIELD_ITEM))
00202                                 : new Item();
00203                 Room room = jsonObject.containsKey(Placement.FIELD_ROOM) ? Room
00204                                 .fromJsonObject(jsonObject.getJsonObject(Placement.FIELD_ROOM))
00205                                 : new Room();
00206                 Surface surface = jsonObject.containsKey(Placement.FIELD_SURFACE) ? Surface
00207                                 .fromJsonObject(jsonObject.getJsonObject(Placement.FIELD_SURFACE))
00208                                 : new Surface();
00209                 String referenceFrameId = jsonObject.containsKey(Placement.FIELD_REFERENCE_FRAME_ID) ? jsonObject
00210                                 .getString(Placement.FIELD_REFERENCE_FRAME_ID) : "";
00211                 Point position = jsonObject.containsKey(Placement.FIELD_POSITION) ? Point
00212                                 .fromJsonObject(jsonObject.getJsonObject(Placement.FIELD_POSITION))
00213                                 : new Point();
00214                 double rotation = jsonObject.containsKey(Placement.FIELD_ROTATION) ? jsonObject
00215                                 .getJsonNumber(Placement.FIELD_ROTATION).doubleValue() : 0.0;
00216 
00217                 return new Placement(item, room, surface, referenceFrameId, position, rotation);
00218         }
00219 }


jinteractiveworld
Author(s): Russell Toris
autogenerated on Sun Dec 14 2014 11:27:03