19 package com.generalrobotix.ui.view;
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.events.PaintEvent;
29 import org.eclipse.swt.events.PaintListener;
30 import org.eclipse.swt.events.SelectionEvent;
31 import org.eclipse.swt.events.SelectionListener;
32 import org.eclipse.swt.graphics.Rectangle;
33 import org.eclipse.swt.layout.GridData;
34 import org.eclipse.swt.layout.GridLayout;
35 import org.eclipse.swt.widgets.Canvas;
36 import org.eclipse.swt.widgets.Combo;
37 import org.eclipse.swt.widgets.Composite;
54 @SuppressWarnings(
"serial")
56 public static final String TITLE =
"Range Sensor View";
62 private SensorState currentSensorState_ =
null;
77 super(name, manager, vp, parent);
79 GridLayout layout =
new GridLayout(1,
false);
80 composite_.setLayout(layout);
82 Composite northPane =
new Composite(composite_,SWT.NONE);
83 northPane.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
84 GridLayout gridLayout =
new GridLayout(2,
true);
85 northPane.setLayout(gridLayout);
87 comboModelName_ =
new Combo(northPane,SWT.READ_ONLY);
88 comboModelName_.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
89 modelList_ =
new ArrayList<GrxModelItem>();
91 comboModelName_.addSelectionListener(
new SelectionListener(){
92 public void widgetSelected(SelectionEvent e) {
94 if (item ==
null || item == currentModel_)
98 List<GrxSensorItem> sensors = currentModel_.
getSensors(
"Range");
99 comboSensorName_.removeAll();
101 if (sensors !=
null){
102 for (
int i=0;
i<sensors.size();
i++){
103 comboSensorName_.add(sensors.get(
i).getName());
104 sensorList_.add(sensors.get(
i));
106 if(sensors.size()>0){
107 comboSensorName_.select(0);
108 comboSensorName_.notifyListeners(SWT.Selection,
null);
114 public void widgetDefaultSelected(SelectionEvent e) {
118 comboSensorName_ =
new Combo(northPane,SWT.READ_ONLY);
119 comboSensorName_.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
120 sensorList_ =
new ArrayList<GrxSensorItem>();
122 comboSensorName_.addSelectionListener(
new SelectionListener(){
123 public void widgetSelected(SelectionEvent e){
124 currentSensor_ = sensorList_.get(comboSensorName_.getSelectionIndex());
125 if(currentWorld_!=
null)
126 updateCanvas(currentWorld_.
getValue());
128 public void widgetDefaultSelected(SelectionEvent e) {
131 canvas_ =
new Canvas(composite_,SWT.NONE);
132 canvas_.addPaintListener(
this);
133 canvas_.setLayoutData(
new GridData(GridData.FILL_BOTH));
136 manager_.registerItemChangeListener(
this,
GrxModelItem.class);
141 Iterator<GrxModelItem> it = modelList_.iterator();
143 comboModelName_.remove(it.next().getName());
145 it = modelList_.iterator();
147 comboModelName_.add(it.next().getName());
148 if(comboModelName_.getItemCount()>0){
149 comboModelName_.select(0);
150 comboModelName_.notifyListeners(SWT.Selection,
null);
153 if(currentWorld_ !=
null){
158 if(currentWorld_!=
null){
161 updateCanvas(currentWorld_.
getValue());
172 if (currentSensor_ !=
null && currentSensorState_ !=
null){
173 double step = currentSensor_.
getDbl(
"scanStep", 0.1);
174 double maxD = currentSensor_.
getDbl(
"maxDistance", 10.0);
175 if (currentSensor_.
id_ >= 0 && currentSensor_.
id_ < currentSensorState_.range.length){
176 Rectangle bounds = canvas_.getBounds();
177 if(bounds.height < bounds.width) {
178 bounds.x = (bounds.width - bounds.height) / 2;
179 bounds.width = bounds.height;
182 bounds.y = (bounds.height - bounds.width) / 2;
183 bounds.height = bounds.width;
186 e.gc.drawArc(bounds.x, bounds.y, bounds.width-1, bounds.height-1,0,360);
187 double [] distances = currentSensorState_.range[currentSensor_.
id_];
188 int centerx = bounds.x + bounds.width / 2;
189 int centery = bounds.y + bounds.height / 2;
190 double scale = bounds.width/(maxD*2);
192 int stepAngle = (
int)(step*57.29579+0.5);
193 int half = (
int)(distances.length/2);
194 double startAngle = 1.570796-step*half-step/2;
195 for(
int i=0;
i<distances.length;
i++){
196 double distance = distances[
i];
199 int iDistance = (
int)(scale*distance);
200 e.gc.fillArc(centerx-iDistance, centery-iDistance, iDistance*2, iDistance*2, (
int)(startAngle*57.29579), stepAngle);
208 if(currentWorld_!=plugin)
return;
210 int pos = arg_pos.intValue();
216 if (state !=
null && currentModel_ !=
null) {
218 if (charStat !=
null ) {
223 currentSensorState_ =
null;
230 GrxModelItem modelItem = (GrxModelItem) item;
233 if(!modelList_.contains(modelItem)){
234 modelList_.add(modelItem);
235 comboModelName_.add(modelItem.
getName());
236 if(currentModel_==
null){
237 comboModelName_.select(0);
238 comboModelName_.notifyListeners(SWT.Selection,
null);
243 if(modelList_.contains(modelItem)){
244 modelList_.remove(modelItem);
245 comboModelName_.remove(modelItem.
getName());
246 if(currentModel_==modelItem){
247 if(modelList_.size()>0){
248 comboModelName_.select(0);
249 comboModelName_.notifyListeners(SWT.Selection,
null);
259 GrxWorldStateItem worldStateItem = (GrxWorldStateItem) item;
262 if(currentWorld_!=worldStateItem){
263 currentWorld_ = worldStateItem;
266 updateCanvas(currentWorld_.
getValue());
271 if(currentWorld_==worldStateItem){
274 currentWorld_ =
null;
285 manager_.removeItemChangeListener(
this,
GrxModelItem.class);
287 if(currentWorld_!=
null) {
void addObserver(GrxObserver v)
#define null
our own NULL pointer
List< GrxSensorItem > sensorList_
png_infop png_charpp name
CharacterStateEx get(int idx)
item corresponds to a robot model
void updateCanvas(WorldStateEx state)
void deleteObserver(GrxObserver v)
static final int ADD_ITEM
void paintControl(PaintEvent e)
draw range sensor output if sensor is choosed
static final int SELECTED_ITEM
void deletePosObserver(GrxPositionObserver v)
void registerItemChange(GrxBaseItem item, int event)
List< GrxModelItem > modelList_
static Activator getDefault()
void updatePosition(GrxBasePlugin plugin, Integer arg_pos)
List< GrxSensorItem > getSensors(String type)
static final int REMOVE_ITEM
final Double getDbl(String key, Double defaultVal)
get double value associated to key
void addPosObserver(GrxPositionObserver v)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
final String getName()
get name
static final int NOTSELECTED_ITEM
Range Sensor output viewer.
GrxRangeSensorView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
constructor