View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.usarcommands;
2   
3   import cz.cuni.amis.pogamut.base.communication.messages.*;
4   import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.CustomTypes.*;
5   import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.TraceColor;
6   
7   /**
8    *
9    * USARSim has the capability of tracing the path that a robot takes. Colored
10   * Navigation Points are dropped into the world as the robot travels;
11   * effectively “tracing” the robot’s path. Tracing can be used with the *
12   * Corresponding GameBots command is Trace.
13   *
14   */
15  public class Trace extends CommandMessage
16  {
17      public Trace(boolean On, double Interval, TraceColor Color)
18      {
19          this.On = On;
20          this.Interval = Interval;
21          this.Color = Color.getName();
22      }
23  
24      public Trace(boolean On, double Interval, String Color)
25      {
26          this.On = On;
27          this.Interval = Interval;
28          this.Color = Color;
29      }
30  
31      public Trace(String Clear)
32      {
33          this.Clear = Clear;
34      }
35  
36      /**
37       * <p></p>WARNING: this is empty-command constructor, you have to use
38       * setters to fill it up!
39       */
40      public Trace()
41      {
42      }
43      /////// Properties BEGIN
44      //tells USARSim to start/stop tracing the robot’s path. Default value is false. 
45      protected boolean On = false;
46  
47      public boolean isOn()
48      {
49          return On;
50      }
51  
52      public Trace setOn(boolean On)
53      {
54          this.On = On;
55          return this;
56      }
57      /*
58       * is a number that dictates how many seconds will go by before USARSim
59       * drops a Navigation Point. Please note that this number is in unreal units
60       * and that its default value is 0.
61       */
62      protected double Interval = 0;
63  
64      public double getInterval()
65      {
66          return Interval;
67      }
68  
69      public Trace setInterval(double Interval)
70      {
71          this.Interval = Interval;
72          return this;
73      }
74      /*
75       * The value for this parameter can be entered as an int or a string. It
76       * determines the color of the trace as follows: ‘0’ or ‘Red’ – Red Trace
77       * [DEFAULT] ‘1’ or ‘Yellow’ – Yellow Trace ‘2’ or ‘Green’ – Green Trace ‘3’
78       * or ‘Cyan’ – Cyan Trace ‘4’ or ‘White’ – White Trace ‘5’ or ‘Blue’ – Blue
79       * Trace ‘6’ or ‘Purple’ – Purple Trace
80       */
81      protected String Color = null;
82  
83      public String getColor()
84      {
85          return Color;
86      }
87  
88      public Trace setColor(String Color)
89      {
90          this.Color = Color;
91          return this;
92      }
93      protected String Clear = null;
94  
95      public String getClear()
96      {
97          return Clear;
98      }
99  
100     /////// Properties END
101     /////// Extra Java code BEGIN
102     /////// Additional code from xslt BEGIN
103     /////// Additional code from xslt END
104     /////// Extra Java from XML BEGIN
105     /////// Extra Java from XML END
106     /////// Extra Java code END
107     /**
108      * Cloning constructor.
109      */
110     public Trace(Trace original)
111     {
112         this.On = original.On;
113         this.Interval = original.Interval;
114         this.Color = original.Color;
115     }
116 
117     @Override
118     public String toString()
119     {
120         return toMessage();
121     }
122 
123     public String toHtmlString()
124     {
125         return super.toString()
126                 + "<b>On</b> : "
127                 + String.valueOf(On)
128                 + " <br/> "
129                 + "<b>Interval</b> : "
130                 + String.valueOf(Interval)
131                 + " <br/> "
132                 + "<b>Color</b> : "
133                 + String.valueOf(Color)
134                 + " <br/> "
135                 + "<b>Clear</b> : "
136                 + String.valueOf(Clear)
137                 + " <br/> "
138                 + "";
139     }
140 
141     public String toMessage()
142     {
143         StringBuilder buf = new StringBuilder();
144 
145         buf.append("Trace");
146 
147         if(Clear != null)
148         {
149             //We dont want to say that trace is of, we just want to send "trace {clear ROBOT}" message without any other confusing parameters
150             buf.append(" {Clear ").append(Clear).append("}");
151             return buf.toString();
152         }
153 
154         buf.append(" {On ").append(On).append("}");
155         buf.append(" {Interval ").append(Interval).append("}");
156 
157         if(Color != null)
158         {
159             buf.append(" {Color ").append(Color).append("}");
160         }
161 
162 
163         return buf.toString();
164     }
165 }