1 24 package org.objectweb.clif.scenario.util.isac.loadprofile; 25 26 import org.apache.log4j.Category; 27 28 35 public class RampDescription { 36 static Category cat = Category.getInstance(RampDescription.class.getName()); 38 39 42 public static final int LINE = 0; 43 44 public static final int ARC = 1; 45 46 public static final int CRENEL_HV = 2; 47 48 public static final int CRENEL_VH = 3; 49 50 public static final String LINE_STRING = "line"; 51 52 public static final String ARC_STRING = "arc"; 53 54 public static final String CRENEL_HV_STRING = "crenelHV"; 55 56 public static final String CRENEL_VH_STRING = "crenelVH"; 57 58 public static final Point DEFAULTPOINT = new Point(0, 0); 59 60 public static final Point UNKNOWNPOINT = new Point(-1, -1); 61 62 public static final String POINT_START = "start"; 63 64 public static final String POINT_END = "end"; 65 66 public static final String POINT_ANGLE = "angle"; 67 68 public static final double UNKNOWN_VALUE = -1; 69 70 73 private int type; 75 76 private String rampId; 78 79 private Point start; 81 82 private Point end; 83 84 private Point angle; 85 86 private double coef = UNKNOWN_VALUE; 88 89 private double real = UNKNOWN_VALUE; 91 92 96 102 public RampDescription(String rampId, int type) { 103 this.type = type; 104 this.rampId = rampId; 105 switch (type) { 107 case LINE: 108 this.start = DEFAULTPOINT; 109 this.end = DEFAULTPOINT; 110 this.angle = UNKNOWNPOINT; 111 break; 112 case ARC: 113 this.start = DEFAULTPOINT; 114 this.end = DEFAULTPOINT; 115 this.angle = DEFAULTPOINT; 116 break; 117 case CRENEL_HV: 118 case CRENEL_VH: 119 this.start = DEFAULTPOINT; 120 this.end = DEFAULTPOINT; 121 this.angle = UNKNOWNPOINT; 122 break; 123 default: 124 cat.warn("THIS TYPE OF RAMP IS UNKNOW !!!"); 125 } 126 } 127 128 140 public RampDescription(String rampId, int type, Point start, Point end, 141 Point angle) { 142 this.type = type; 144 this.rampId = rampId; 145 this.start = new Point(start.x, start.y); 146 this.end = new Point(end.x, end.y); 147 this.angle = new Point(angle.x, angle.y); 148 149 } 150 151 159 public RampDescription(RampDescription c) { 160 this.type = c.getType(); 161 this.rampId = c.getRampId(); 162 this.start = new Point(c.getStart().x, c.getStart().y); 163 this.end = new Point(c.getEnd().x, c.getEnd().y); 164 this.angle = new Point(c.getAngle().x, c.getAngle().y); 165 this.coef = c.getCoef(); 166 this.real = c.getReal(); 167 } 168 169 173 public static boolean isDefinedStyle(String style) { 174 if (style.equals(LINE_STRING)||style.equals(CRENEL_HV_STRING)||style.equals(CRENEL_VH_STRING)) { 175 return true ; 176 } 177 return false ; 178 } 179 180 183 public Object clone() { 184 return new RampDescription(this); 185 } 186 187 public void updateRampData() { 188 switch (type) { 189 case LINE: 190 cat.debug("Found a Line Ramp"); 191 if (((double) start.x) - ((double) end.x) != 0) { 192 this.coef = (((double) start.y) - ((double) end.y)) 193 / (((double) start.x) - ((double) end.x)); 194 } else 195 this.coef = 0; 196 197 this.real = ((double) end.y) - (this.coef * ((double) end.x)); 198 break; 199 case ARC: 200 cat.debug("Found an Arc Ramp"); 201 break; 202 case CRENEL_HV: 203 cat.debug("Found a Crenel_HV Ramp"); 204 break; 205 case CRENEL_VH: 206 cat.debug("Found a Crenel_VH Ramp"); 207 break; 208 default: 209 cat.warn("THIS TYPE OF RAMP IS UNKNOW !!!"); 210 } 211 cat.debug("RAMPDESCRIPTION updated: " + this.toString()); 212 213 } 214 215 222 public int getCorrespondingY(int x) { 223 int result = -1; 224 switch (type) { 225 case LINE: 226 result = (int) (this.coef * ((double) x) + this.real); 227 break; 228 case ARC: 229 cat.debug("Found an Arc Ramp"); 230 break; 231 case CRENEL_HV: 232 result = this.start.x; 233 break; 234 case CRENEL_VH: 235 result = this.start.y; 236 break; 237 default: 238 cat.warn("THIS TYPE OF RAMP IS UNKNOW !!!"); 239 } 240 241 return result; 242 } 243 244 248 251 public Point getAngle() { 252 return angle; 253 } 254 255 259 public void setAngle(Point angle) { 260 this.angle = angle; 261 } 262 263 266 public Point getEnd() { 267 return end; 268 } 269 270 274 public void setEnd(Point end) { 275 this.end = end; 276 } 277 278 281 public Point getStart() { 282 return start; 283 } 284 285 289 public void setStart(Point start) { 290 this.start = start; 291 } 292 293 296 public int getType() { 297 return type; 298 } 299 300 303 public String getRampId() { 304 return rampId; 305 } 306 307 311 public void setRampId(String rampId) { 312 this.rampId = rampId; 313 } 314 315 318 public double getCoef() { 319 return coef; 320 } 321 322 326 public void setCoef(double coef) { 327 this.coef = coef; 328 } 329 330 333 public double getReal() { 334 return real; 335 } 336 337 341 public void setReal(double real) { 342 this.real = real; 343 } 344 345 public String toString() { 346 return "[" + rampId + "(" + type + ") -> start point : " + start 347 + ",end point : " + end + ",angle point : " + angle 348 + ",coef : " + coef + ",real : " + real + "]"; 349 } 350 } | Popular Tags |