19 package com.generalrobotix.ui.view;
21 import java.text.DecimalFormat;
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Vector;
29 import org.eclipse.jface.layout.AbstractColumnLayout;
30 import org.eclipse.jface.layout.TableColumnLayout;
31 import org.eclipse.jface.viewers.ArrayContentProvider;
32 import org.eclipse.jface.viewers.ColumnWeightData;
33 import org.eclipse.jface.viewers.ILabelProviderListener;
34 import org.eclipse.jface.viewers.ITableColorProvider;
35 import org.eclipse.jface.viewers.ITableFontProvider;
36 import org.eclipse.jface.viewers.ITableLabelProvider;
37 import org.eclipse.jface.viewers.TableViewer;
38 import org.eclipse.swt.SWT;
39 import org.eclipse.swt.events.ControlEvent;
40 import org.eclipse.swt.events.ControlListener;
41 import org.eclipse.swt.events.SelectionAdapter;
42 import org.eclipse.swt.events.SelectionEvent;
43 import org.eclipse.swt.graphics.Color;
44 import org.eclipse.swt.graphics.Font;
45 import org.eclipse.swt.graphics.Image;
46 import org.eclipse.swt.graphics.Point;
47 import org.eclipse.swt.layout.GridData;
48 import org.eclipse.swt.layout.GridLayout;
49 import org.eclipse.swt.widgets.Combo;
50 import org.eclipse.swt.widgets.Composite;
51 import org.eclipse.swt.widgets.Event;
52 import org.eclipse.swt.widgets.Listener;
53 import org.eclipse.swt.widgets.TableColumn;
68 @SuppressWarnings(
"serial")
70 public static final String TITLE =
"Robot State";
72 private static final DecimalFormat FORMAT1 =
new DecimalFormat(
" 0.0;-0.0");
73 private static final DecimalFormat FORMAT2 =
new DecimalFormat(
" 0.000;-0.000");
86 private List<GrxLinkItem> jointList_ =
new ArrayList<GrxLinkItem>();
107 private String osName_ =
"Windows";
109 private static final int COMBO_WIDTH = 100;
110 private int [][] columnWidth_ =
new int[][]{
111 {5,16,11,11,11,7,7,7,7,9,9},
112 {22,13,13,13,13,13,13},
113 {30,90,60,60,60,40,40,40,40,50,50},
114 {110,75,75,75,75,75,75}
116 private Composite[] viewPanel_ =
new Composite[2];
120 super(name, manager,vp,parent);
121 osName_ = System.getProperty(
"os.name");
129 mainPanel_ =
new Composite(composite_, SWT.NONE);
130 GridLayout gridLayout =
new GridLayout(1,
false);
131 gridLayout.marginHeight = 0;
132 gridLayout.verticalSpacing = 0;
133 mainPanel_.setLayout(gridLayout);
134 modelList_ =
new ArrayList<GrxModelItem>();
136 comboModelName_ =
new Combo(mainPanel_,SWT.READ_ONLY);
137 GridData gridData =
new GridData();
138 gridData.widthHint = COMBO_WIDTH;
139 comboModelName_.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
141 comboModelName_.addSelectionListener(
new SelectionAdapter(){
143 public void widgetSelected(SelectionEvent e) {
145 if (item ==
null || item == currentModel_)
148 currentModel_ =
item;
155 String[][] header =
new String[][] {
156 {
"No",
"Joint",
"Angle",
"Target",
"Torque",
"PWR",
"SRV",
"ARM",
"T",
"Pgain",
"Dgain" },
157 {
"1",
"2",
"3",
"4",
"5",
"6",
"7"},
159 boolean showheader[] = {
true,
false};
160 int[][] alignment =
new int[][] {
161 { SWT.RIGHT, SWT.LEFT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.CENTER, SWT.CENTER, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT },
162 { SWT.LEFT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT },
165 for(
int i=0;
i<2;
i++){
166 viewPanel_[
i] =
new Composite(mainPanel_, SWT.NONE);
167 viewPanel_[
i].setLayoutData(
new GridData(GridData.FILL_BOTH));
168 GridLayout gridLayout1 =
new GridLayout();
169 gridLayout1.marginHeight = 0;
170 gridLayout1.marginWidth = 0;
171 gridLayout1.horizontalSpacing = 0;
172 gridLayout1.verticalSpacing = 0;
173 viewPanel_[
i].setLayout(gridLayout1);
176 jointTV_ =
new TableViewer(viewPanel_[0],SWT.BORDER|SWT.FULL_SELECTION|SWT.VIRTUAL);
177 sensorTV_ =
new TableViewer(viewPanel_[1],SWT.BORDER|SWT.FULL_SELECTION|SWT.VIRTUAL);
179 jointTV_.setContentProvider(
new ArrayContentProvider());
180 sensorTV_.setContentProvider(
new ArrayContentProvider());
182 jointTV_.setLabelProvider(
new JointTableLabelProvider());
183 sensorTV_.setLabelProvider(
new SensorTableLabelProvider());
185 viewers_ =
new TableViewer[]{jointTV_,sensorTV_};
186 TableColumnLayout[] layout =
new TableColumnLayout[2];
187 for(
int i=0;
i<viewers_.length;
i++){
188 layout[
i] =
new TableColumnLayout();
189 for(
int j=0;j<header[
i].length;j++){
190 TableColumn column =
new TableColumn(viewers_[
i].getTable(),SWT.NULL);
191 column.setText(header[
i][j]);
192 column.setAlignment(alignment[
i][j]);
193 layout[
i].setColumnData(column,
new ColumnWeightData(columnWidth_[
i][j],columnWidth_[
i+2][j]));
195 column.addControlListener(
new ControlListener(){
196 public void controlMoved(ControlEvent e) {
198 public void controlResized(ControlEvent e) {
199 TableColumn column = (TableColumn)e.getSource();
200 int i = jointTV_.getTable().indexOf(column);
201 int width = column.getWidth();
202 setInt(
"jcolumnWidth"+i, width);
206 column.addControlListener(
new ControlListener(){
207 public void controlMoved(ControlEvent e) {
209 public void controlResized(ControlEvent e) {
210 TableColumn column = (TableColumn)e.getSource();
211 int i = sensorTV_.getTable().indexOf(column);
212 int width = column.getWidth();
213 setInt(
"scolumnWidth"+i, width);
217 viewPanel_[
i].setLayout(layout[
i]);
218 viewers_[
i].getTable().setHeaderVisible(showheader[i]);
219 viewers_[
i].getTable().setLinesVisible(
true);
220 viewers_[
i].getTable().setLayoutData(
new GridData(GridData.FILL_BOTH));
225 manager_.registerItemChangeListener(
this,
GrxModelItem.class);
231 Iterator<GrxModelItem> it = modelList_.iterator();
235 comboModelName_.remove(modelItem.
getName());
238 if(!modelList_.isEmpty()){
239 it = modelList_.iterator();
242 comboModelName_.add(model.
getName());
245 comboModelName_.select(0);
246 currentModel_ = modelList_.get(0);
249 currentModel_ =
null;
250 if(currentWorld_ !=
null ){
255 if(currentWorld_!=
null){
256 currentState_ = currentWorld_.
getValue();
259 updatePosition(currentWorld_, currentWorld_.
getPosition());
273 Integer[] input =
new Integer[jointList_.size()];
274 for(
int i=0;
i<input.length;
i++){
282 if(forceName_ !=
null){
283 length += forceName_.length;
284 if (forceName_.length >= 2 && forceName_[0].equals(
"rfsensor") && forceName_[1].equals(
"lfsensor")){
288 if(gyroName_ !=
null)
289 length += gyroName_.length;
291 length += accName_.length;
293 Integer[] input =
new Integer[
length];
294 for(
int i=0;
i<input.length;
i++){
301 if (super.propertyChanged(key, value)){
304 if (key.startsWith(
"jcolumnWidth")){
305 int i = Integer.parseInt(key.replace(
"jcolumnWidth",
""));
306 int width = Integer.parseInt(value.trim());
307 int w = jointTV_.getTable().getSize().x;
308 int width0 = width*100/w;
310 if(width < columnWidth_[2][i])
313 width1 = columnWidth_[2][
i];
314 ((AbstractColumnLayout) viewPanel_[0].getLayout()).setColumnData(jointTV_.getTable().getColumn(i),
new ColumnWeightData(width0,width1));
315 viewPanel_[0].layout(
true);
316 final String key_ = key;
317 final String value_ =
value;
320 setProperty(key_, value_);
324 }
else if (key.startsWith(
"scolumnWidth")){
325 int i = Integer.parseInt(key.replace(
"scolumnWidth",
""));
326 int width = Integer.parseInt(value.trim());
327 int w = sensorTV_.getTable().getSize().x;
328 int width0 = width*100/w;
330 if(width < columnWidth_[3][i])
333 width1 = columnWidth_[3][
i];
334 ((AbstractColumnLayout) viewPanel_[1].getLayout()).setColumnData(sensorTV_.getTable().getColumn(i),
new ColumnWeightData(width0,width1));
335 viewPanel_[1].layout(
true);
336 final String key_ = key;
337 final String value_ =
value;
340 setProperty(key_, value_);
352 Vector<GrxLinkItem> lInfo = currentModel_.
links_;
353 for (
int i = 0;
i < lInfo.size();
i++) {
354 for (
int j = 0; j < lInfo.size(); j++) {
355 if (
i == lInfo.get(j).jointId_) {
356 jointList_.add(lInfo.get(j));
368 GrxModelItem modelItem = (GrxModelItem) item;
371 if(!modelList_.contains(modelItem)){
372 modelList_.add(modelItem);
373 comboModelName_.add(modelItem.
getName());
375 if(currentModel_ ==
null){
376 currentModel_ = modelItem;
377 comboModelName_.select(comboModelName_.indexOf(modelItem.
getName()));
385 if(modelList_.contains(modelItem)){
386 int index = modelList_.indexOf(modelItem);
387 modelList_.remove(modelItem);
389 comboModelName_.remove(modelItem.
getName());
390 if(currentModel_ == modelItem){
391 if(index < modelList_.size()){
392 currentModel_ = modelList_.get(index);
393 comboModelName_.select(comboModelName_.indexOf(currentModel_.
getName()));
399 currentModel_ = modelList_.get(index);
400 comboModelName_.select(comboModelName_.indexOf(currentModel_.
getName()));
404 currentModel_ =
null;
417 GrxWorldStateItem worldStateItem = (GrxWorldStateItem) item;
420 if(currentWorld_ != worldStateItem){
421 currentWorld_ = worldStateItem;
422 currentState_ = currentWorld_.
getValue();
423 updatePosition(currentWorld_, currentWorld_.
getPosition());
430 if(currentWorld_ == worldStateItem){
433 currentWorld_ =
null;
434 currentState_ =
null;
445 if(currentWorld_ == plugin ){
446 if((String)
arg[0]==
"ClearLog"){
447 currentState_ =
null;
449 }
else if(modelList_.contains(plugin)){
450 if( (String)
arg[0] ==
"PropertyChange" ){
451 if( (String)
arg[1] ==
"name" ){
453 comboModelName_.setItem(index, (String)
arg[2]);
460 if(currentWorld_ != plugin)
463 int pos = arg_pos.intValue();
464 currentState_ = currentWorld_.
getValue(pos);
469 if (currentModel_ ==
null ){
470 jointTV_.setInput(
new Integer[0]);
471 sensorTV_.setInput(
new Integer[0]);
474 currentSensor_ =
null;
475 currentRefAng_ =
null;
476 currentSvStat_ =
null;
477 currentPower_ =
null;
478 if (currentState_ !=
null) {
480 if (charStat !=
null) {
487 jointTV_.setInput(_createJointTVInput());
488 sensorTV_.setInput(_createSensorTVInput());
489 viewPanel_[0].layout();
490 viewPanel_[1].layout();
492 Point point = jointTV_.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT);
493 jointTV_.getTable().setSize(point);
494 Point point1 = sensorTV_.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT);
495 sensorTV_.getTable().setSize(point1);
496 setScrollMinSize(0, point.y+point1.y);
497 mainPanel_.layout(
true);
501 if (currentModel_ ==
null )
return;
502 currentSensor_ =
null;
503 currentRefAng_ =
null;
504 currentSvStat_ =
null;
505 currentPower_ =
null;
506 if (currentState_ !=
null) {
508 if (charStat !=
null) {
519 class JointTableLabelProvider
implements ITableLabelProvider,ITableColorProvider,ITableFontProvider {
520 final int CALIB_STATE_MASK = 0x00000001;
521 final int SERVO_STATE_MASK = 0x00000002;
522 final int POWER_STATE_MASK = 0x00000004;
523 final int SERVO_ALARM_MASK = 0x0007fff8;
524 final int SERVO_ALARM_SHIFT = 3;
525 final int DRIVER_TEMP_MASK = 0xff000000;
526 final int DRIVER_TEMP_SHIFT = 24;
528 public Image getColumnImage(Object element,
int columnIndex) {
532 public String getColumnText(Object element,
int columnIndex) {
533 int rowIndex = ((Integer)element).intValue();
542 switch (columnIndex) {
544 return Integer.toString(rowIndex);
546 if (jointList_.size() <= 0)
548 return jointList_.get(rowIndex).getName();
550 if (currentSensor_ ==
null)
552 return FORMAT2.format(Math.toDegrees(currentSensor_.q[rowIndex]));
554 if (currentRefAng_ ==
null)
556 return FORMAT2.format(Math.toDegrees(currentRefAng_[rowIndex]));
558 if (currentSensor_ ==
null || currentSensor_.u ==
null)
560 return FORMAT2.format(currentSensor_.u[rowIndex]);
563 if (currentSvStat_ ==
null)
565 if (_isPowerOn(currentSvStat_[rowIndex])){
571 if (currentSvStat_ ==
null)
573 if (_isServoOn(currentSvStat_[rowIndex])) {
577 if (currentSvStat_ ==
null)
break;
578 int alarm = _getAlarm(currentSvStat_[rowIndex]);
579 return String.format(
"%03x", alarm);
581 if (currentSvStat_ ==
null)
break;
582 int temp = _getDriverTemperature(currentSvStat_[rowIndex]);
586 return String.format(
"%3d", temp);
598 public void addListener(ILabelProviderListener listener) {
601 public void dispose() {
604 public boolean isLabelProperty(Object element, String property) {
608 public void removeListener(ILabelProviderListener listener) {
611 public Color getBackground(Object element,
int columnIndex) {
612 int rowIndex = ((Integer)element).intValue();;
615 if (jointList_.get(rowIndex) == (GrxLinkItem)bitem) {
622 public Color getForeground(Object element,
int columnIndex) {
623 int rowIndex = ((Integer)element).intValue();
624 if (currentSvStat_ ==
null)
return black_;
625 switch (columnIndex) {
627 if (!_isCalibrated(currentSvStat_[rowIndex])) {
633 if (jointList_.size() <= 0)
637 && (currentSensor_.q[rowIndex] <= info.
llimit_[0] || info.
ulimit_[0] <= currentSensor_.q[rowIndex])) {
642 if (_isPowerOn(currentSvStat_[rowIndex]))
646 if (_isServoOn(currentSvStat_[rowIndex]))
650 if (_getAlarm(currentSvStat_[rowIndex]) != 0)
654 if (_getDriverTemperature(currentSvStat_[rowIndex]) > 60){
665 public Font getFont(Object element,
int columnIndex) {
666 int rowIndex = ((Integer)element).intValue();
668 switch (columnIndex) {
670 if (currentSvStat_ !=
null 671 && !_isCalibrated(currentSvStat_[rowIndex])) {
676 if(jointList_.isEmpty())
688 if (currentSvStat_ ==
null)
690 if (_isPowerOn(currentSvStat_[rowIndex])) {
695 if (currentSvStat_ ==
null)
697 if (_isServoOn(currentSvStat_[rowIndex])) {
702 if (currentSvStat_ ==
null)
704 if (_getAlarm(currentSvStat_[rowIndex]) != 0){
709 if (currentSvStat_ ==
null)
711 if (_getDriverTemperature(currentSvStat_[rowIndex]) > 60){
721 private boolean _isServoOn(
int state) {
722 if ((state & SERVO_STATE_MASK) != 0){
728 private boolean _isPowerOn(
int state) {
729 if ((state & POWER_STATE_MASK) != 0){
735 private boolean _isCalibrated(
int state) {
736 if ((state & CALIB_STATE_MASK) != 0){
742 private int _getAlarm(
int state){
743 return (state&SERVO_ALARM_MASK)>>SERVO_ALARM_SHIFT;
745 private int _getDriverTemperature(
int state){
746 return (state&DRIVER_TEMP_MASK)>>DRIVER_TEMP_SHIFT;
752 class SensorTableLabelProvider
implements ITableLabelProvider,ITableColorProvider,ITableFontProvider{
754 public Image getColumnImage(Object element,
int columnIndex) {
758 public String getColumnText(Object element,
int columnIndex) {
759 int rowIndex = ((Integer)element).intValue();
762 numForce = forceName_.length;
765 numAccel = accName_.length;
768 numGyro = gyroName_.length;
769 boolean showzmp = numForce >= 2 && forceName_[0].equals(
"rfsensor") && forceName_[1].equals(
"lfsensor");
770 if (columnIndex == 0) {
771 if (rowIndex < numForce)
772 return forceName_[rowIndex] +
" [N],[Nm]";
773 if (rowIndex < numForce+numAccel)
774 return accName_[rowIndex-numForce] +
" [m/s^2]";
775 if (rowIndex < numForce+numAccel+numGyro)
776 return gyroName_[rowIndex-numForce-numAccel] +
" [rad/s]";
777 if (rowIndex == numForce+numAccel+numGyro && showzmp)
778 return "ZMP(right)[m]";
779 return "Voltage [V]";
782 if (currentSensor_ ==
null)
return "---";
783 if (rowIndex < numForce){
784 if (currentSensor_.force ==
null || columnIndex >= 7){
787 return FORMAT2.format(currentSensor_.force[rowIndex][columnIndex - 1]);
789 }
else if (rowIndex < numForce+numAccel){
790 if (currentSensor_.accel ==
null || columnIndex >= 4){
793 return FORMAT2.format(currentSensor_.accel[rowIndex - numForce][columnIndex - 1]);
795 }
else if (rowIndex < numForce+numAccel+numGyro){
796 if (currentSensor_.rateGyro ==
null || columnIndex >= 4){
799 return FORMAT2.format(currentSensor_.rateGyro[rowIndex - numForce - numAccel][columnIndex - 1]);
801 }
else if (rowIndex == numForce+numAccel+numGyro && showzmp){
802 if (columnIndex == 1){
803 if (currentSensor_.force[0][2]>25){
804 return FORMAT2.format(-currentSensor_.force[0][4]/currentSensor_.force[0][2]);
806 return FORMAT2.format(0);
808 }
else if (columnIndex == 2){
809 if (currentSensor_.force[0][2]>25){
810 return FORMAT2.format(currentSensor_.force[0][3]/currentSensor_.force[0][2]);
812 return FORMAT2.format(0);
814 }
else if(columnIndex == 3){
815 return "ZMP(left)[m]";
816 }
else if (columnIndex == 4){
817 if (currentSensor_.force[1][2]>25){
818 return FORMAT2.format(-currentSensor_.force[1][4]/currentSensor_.force[1][2]);
820 return FORMAT2.format(0);
822 }
else if (columnIndex == 5){
823 if (currentSensor_.force[1][2]>25){
824 return FORMAT2.format(currentSensor_.force[1][3]/currentSensor_.force[1][2]);
826 return FORMAT2.format(0);
832 if(currentPower_ ==
null || columnIndex >= 4)
834 if(columnIndex == 2){
837 return FORMAT1.format(currentPower_[columnIndex/2]);
842 public void addListener(ILabelProviderListener listener) {
845 public void dispose() {
848 public boolean isLabelProperty(Object element, String property) {
852 public void removeListener(ILabelProviderListener listener) {
855 public Color getBackground(Object element,
int columnIndex) {
856 int rowIndex = ((Integer)element).intValue();;
860 numForce = forceName_.length;
863 numAccel = accName_.length;
866 numGyro = gyroName_.length;
867 if (rowIndex < numForce){
869 if (forceName_[rowIndex].equals(((GrxSensorItem)bitem).getName())) {
873 }
else if (rowIndex < numForce + numAccel){
875 if (accName_[rowIndex-numForce].equals(((GrxSensorItem)bitem).getName())) {
879 }
else if (rowIndex < numForce + numAccel + numGyro){
881 if (gyroName_[rowIndex-numForce-numAccel].equals(((GrxSensorItem)bitem).getName())) {
889 public Color getForeground(Object element,
int columnIndex) {
893 public Font getFont(Object element,
int columnIndex) {
900 manager_.removeItemChangeListener(
this,
GrxModelItem.class);
902 if(currentWorld_ !=
null){
907 if(!modelList_.isEmpty()){
908 Iterator<GrxModelItem> it = modelList_.iterator();
910 it.next().deleteObserver(
this);
919 for(
int i=0;
i<viewers_.length;
i++){
921 viewers_[
i].refresh();
void addObserver(GrxObserver v)
#define null
our own NULL pointer
SensorState currentSensor_
png_infop png_charpp name
CharacterStateEx get(int idx)
item corresponds to a robot model
void deleteObserver(GrxObserver v)
png_bytep png_bytep png_size_t length
void updatePosition(GrxBasePlugin plugin, Integer arg_pos)
Integer [] _createSensorTVInput()
png_infop png_uint_32 * width
void registerItemChange(GrxBaseItem item, int event)
static final int SELECTED_ITEM
void deletePosObserver(GrxPositionObserver v)
boolean propertyChanged(String key, String value)
static Activator getDefault()
Vector< GrxLinkItem > links_
static final int REMOVE_ITEM
GrxRobotStatView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
String [] getSensorNames(String type)
Font getFont(String fontName)
void addPosObserver(GrxPositionObserver v)
void update(GrxBasePlugin plugin, Object... arg)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
final String getName()
get name
static final int NOTSELECTED_ITEM
Integer [] _createJointTVInput()
List< GrxModelItem > modelList_