CollisionPairPanel.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
18 package com.generalrobotix.ui.view.simulation;
19 
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Vector;
24 
25 import org.eclipse.jface.dialogs.MessageDialog;
26 import org.eclipse.jface.viewers.ArrayContentProvider;
27 import org.eclipse.jface.viewers.ColumnWeightData;
28 import org.eclipse.jface.viewers.ILabelProviderListener;
29 import org.eclipse.jface.viewers.ITableLabelProvider;
30 import org.eclipse.jface.viewers.TableLayout;
31 import org.eclipse.jface.viewers.TableViewer;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.events.SelectionEvent;
34 import org.eclipse.swt.events.SelectionListener;
35 import org.eclipse.swt.graphics.Image;
36 import org.eclipse.swt.layout.FillLayout;
37 import org.eclipse.swt.layout.GridData;
38 import org.eclipse.swt.layout.GridLayout;
39 import org.eclipse.swt.widgets.Button;
40 import org.eclipse.swt.widgets.Combo;
41 import org.eclipse.swt.widgets.Composite;
42 import org.eclipse.swt.widgets.Control;
43 import org.eclipse.swt.widgets.Label;
44 import org.eclipse.swt.widgets.TableColumn;
45 import org.eclipse.swt.widgets.Text;
46 
55 
56 @SuppressWarnings("serial") //$NON-NLS-1$
57 public class CollisionPairPanel extends Composite {
59  private TableViewer viewer_;
60  private Vector<GrxCollisionPairItem> vecCollision_;
61 
62  private Button btnAdd_;
63  private Button btnRemove_;
64  private Button btnEdit_;
65  private Button btnAddAll_;
67 
68  private String defaultStaticFriction_;
69  private String defaultSlidingFriction_;
70  private String defaultCullingThresh_;
71  private String defaultRestitution_;
72 
73  private static final String ATTR_NAME_STATIC_FRICTION = "staticFriction"; //$NON-NLS-1$
74  private static final String ATTR_NAME_SLIDING_FRICTION = "slidingFriction"; //$NON-NLS-1$
75  private static final String ATTR_NAME_CULLING_THRESH = "cullingThresh"; //$NON-NLS-1$
76  private static final String ATTR_NAME_RESTITUTION = "Restitution";
77 
78  private final String[] clmName_ ={
79  MessageBundle.get("panel.collision.table.obj1"), //$NON-NLS-1$
80  MessageBundle.get("panel.collision.table.link1"), //$NON-NLS-1$
81  MessageBundle.get("panel.collision.table.obj2"), //$NON-NLS-1$
82  MessageBundle.get("panel.collision.table.link2"), //$NON-NLS-1$
83  MessageBundle.get("panel.collision.staticFriction"), //$NON-NLS-1$
84  MessageBundle.get("panel.collision.slidingFriction"),
85  MessageBundle.get("panel.collision.cullingThresh"),
86  MessageBundle.get("panel.collision.restitution")
87  };
88 
89  private final String[] attrName_ ={
90  "objectName1","jointName1", //$NON-NLS-1$ //$NON-NLS-2$
91  "objectName2","jointName2", //$NON-NLS-1$ //$NON-NLS-2$
92  ATTR_NAME_STATIC_FRICTION, ATTR_NAME_SLIDING_FRICTION, ATTR_NAME_CULLING_THRESH, ATTR_NAME_RESTITUTION
93  };
94 
95  private static final int BUTTONS_HEIGHT = 26;
96 
97  public void setEnabled(boolean flag) {
98  super.setEnabled(flag);
99  if (editorPanel_ != null)
100  editorPanel_.doCancel();
101  _setButtonEnabled(flag);
102  }
103  /*
104  private String _getJointName(String linkName){
105  if(linkName.indexOf("_")==-1){
106  return"";
107  }else{
108  return linkName.substring(linkName.indexOf("_") + 1);
109  }
110  }
111  private String _getObjectName(String linkName){
112  if(linkName.indexOf("_")==-1){
113  return linkName;
114  }else{
115  return linkName.substring(0,linkName.indexOf("_") );
116  }
117  }
118  */
119 
120  public CollisionPairPanel(Composite parent,int style,GrxPluginManager manager) {
121  super(parent, style);
122  manager_ = manager;
123  //AttributeProperties props = AttributeProperties.getProperties("CollisionPair");
124  defaultStaticFriction_ = "0.5";//props.getProperty(ATTR_NAME_STATIC_FRICTION,AttributeProperties.PROPERTY_DEFAULT_VALUE); //$NON-NLS-1$
125  defaultSlidingFriction_ = "0.5";//props.getProperty(ATTR_NAME_SLIDING_FRICTION,AttributeProperties.PROPERTY_DEFAULT_VALUE); //$NON-NLS-1$
126  defaultCullingThresh_ = "0.01"; //$NON-NLS-1$
127  defaultRestitution_ = "0.0";
128 
129  vecCollision_ = new Vector<GrxCollisionPairItem>();
130 
131  setLayout(new GridLayout(1,false));
132 
133  viewer_ = new TableViewer(this,SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
134  viewer_.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
135  viewer_.setContentProvider(new ArrayContentProvider());
136  viewer_.setLabelProvider(new InnerTableLabelProvider());
137  viewer_.getTable().addSelectionListener(new SelectionListener(){
138 
139  public void widgetDefaultSelected(SelectionEvent e) {
140  }
141 
142  public void widgetSelected(SelectionEvent e) {
143  int row = viewer_.getTable().getSelectionIndex();
144  if (row >= 0 && row < vecCollision_.size()) {
145  editorPanel_.setNode(vecCollision_.get(row));
146  }
147  }
148  });
149  TableLayout tableLayout = new TableLayout();
150  for(int i=0;i<clmName_.length;i++){
151  new TableColumn(viewer_.getTable(),i).setText(clmName_[i]);;
152  tableLayout.addColumnData(new ColumnWeightData(1,true));
153  }
154  viewer_.getTable().setLayout(tableLayout);
155  viewer_.getTable().setHeaderVisible(true);
156  viewer_.getTable().setLinesVisible(true);
157  viewer_.setInput(vecCollision_);
158  //viewer_.getTable().pack();
159 
160  Composite pnlBttn = new Composite(this,SWT.NONE);
161  GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
162  gridData.heightHint = BUTTONS_HEIGHT;
163  pnlBttn.setLayoutData(gridData);
164  pnlBttn.setLayout(new FillLayout(SWT.HORIZONTAL));
165 
166  btnAdd_ = new Button(pnlBttn,SWT.PUSH);
167  btnAdd_.setText(MessageBundle.get("panel.add")); //$NON-NLS-1$
168  btnAdd_.addSelectionListener(new SelectionListener(){
169 
170  public void widgetDefaultSelected(SelectionEvent e) {
171  }
172 
173  public void widgetSelected(SelectionEvent e) {
174  _setButtonEnabled(false);
175  editorPanel_.startAddMode();
176  }
177 
178  });
179 
180  btnRemove_ = new Button(pnlBttn,SWT.PUSH);
181  btnRemove_.setText(MessageBundle.get("panel.remove")); //$NON-NLS-1$
182  btnRemove_.addSelectionListener(new SelectionListener(){
183 
184  public void widgetDefaultSelected(SelectionEvent e) {
185  }
186 
187  public void widgetSelected(SelectionEvent e) {
188  int row = viewer_.getTable().getSelectionIndex();
189  if (row >= 0 && row < vecCollision_.size()) {
190  if (_checkDialog(MessageBundle.get("collision.remove"))) { //$NON-NLS-1$
191  vecCollision_.get(row).delete();
192  }
193  }
194  }
195 
196  });
197 
198  btnEdit_ = new Button(pnlBttn,SWT.PUSH);
199  btnEdit_.setText(MessageBundle.get("panel.edit")); //$NON-NLS-1$
200  btnEdit_.addSelectionListener(new SelectionListener(){
201 
202  public void widgetDefaultSelected(SelectionEvent e) {
203  }
204 
205  public void widgetSelected(SelectionEvent e) {
206  int row = viewer_.getTable().getSelectionIndex() ;
207  if(row>=0 && row<vecCollision_.size()){
208  _setButtonEnabled(false);
209  editorPanel_.startEditMode(vecCollision_.get(row));
210  }
211  }
212 
213  });
214 
215  btnAddAll_ = new Button(pnlBttn,SWT.PUSH);
216  btnAddAll_.setText(MessageBundle.get("panel.addAll")); //$NON-NLS-1$
217  btnAddAll_.addSelectionListener(new SelectionListener(){
218 
219  public void widgetDefaultSelected(SelectionEvent e) {
220  }
221 
222  public void widgetSelected(SelectionEvent e) {
223  manager_.refuseItemChange();
224  List<GrxModelItem> list = manager_.<GrxModelItem>getSelectedItemList(GrxModelItem.class);
225  for (int i=0; i<list.size(); i++) {
226  GrxModelItem m1 = list.get(i);
227  for (int j=i; j<list.size(); j++) {
228  GrxModelItem m2 = list.get(j);
229  for (int k=0; k<m1.links_.size(); k++) {
230  int l=0;
231  if(i==j) l=k;
232  for (; l<m2.links_.size(); l++) {
233  if (i != j || k != l){
234  editorPanel_.txtStaticFric_.setText(defaultStaticFriction_);
235  editorPanel_.txtSlidingFric_.setText(defaultSlidingFriction_);
236  editorPanel_.txtCullingThresh_.setText(defaultCullingThresh_);
237  editorPanel_.txtRestitution_.setText(defaultRestitution_);
238  _createItem(m1.getName(), m1.links_.get(k).getName(), m2.getName(), m2.links_.get(l).getName());
239  }
240  }
241  }
242  }
243  }
244  manager_.acceptItemChange();
245  }
246 
247  });
248 
249  Composite editorPanelComposite = new Composite(this,SWT.NONE);
250  GridData editorPanelGridData = new GridData(GridData.FILL_HORIZONTAL);
251  editorPanelComposite.setLayoutData(editorPanelGridData);
252  editorPanelComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
253  editorPanel_ = new CollisionPairEditorPanel(editorPanelComposite,SWT.NONE);
254 
255  updateTableFont();
256  }
257 
258  private boolean _checkDialog(String msg) {
259  boolean overwrite = MessageDialog.openQuestion(getShell(), MessageBundle.get("dialog.overwrite"), msg); //$NON-NLS-1$
260  return overwrite;
261  }
262 
263  private void _setButtonEnabled(boolean flag) {
264  btnAdd_.setEnabled(flag);
265  btnRemove_.setEnabled(flag);
266  btnEdit_.setEnabled(flag);
267  btnAddAll_.setEnabled(flag);
268  viewer_.getTable().setEnabled(flag);
269  _repaint();
270  }
271 
272  private void _repaint() {
273  //viewer_.getTable().update();
274  }
275 
276  private class CollisionPairEditorPanel extends Composite {
277 
278  private static final int MODE_ADD = 0 ;
279  private static final int MODE_EDIT = 1 ;
280 
281  private static final int BUTTON_WIDTH = 50;
282 
283  private int mode_;
287  private Button btnOk_, btnCancel_;
288 
289  private Text txtStaticFric_,txtSlidingFric_,txtCullingThresh_,txtRestitution_;
290  private Label lblFriction_,lblStaticFric_,lblSlidingFric_,lblCullingThresh_,lblRestitution_;
291 
292  public CollisionPairEditorPanel(Composite parent,int style) {
293  super(parent,style);
294  setLayout(new GridLayout(2,false));
295 
296  pnlJoint1_ = new JointSelectPanel(this,SWT.NONE,"1"); //$NON-NLS-1$
297  pnlJoint1_.setLayoutData(new GridData(GridData.FILL_BOTH));
298  //pnlJoint1_.setBounds(0,0,180,60);
299 
300  pnlJoint2_ = new JointSelectPanel(this,SWT.NONE,"2"); //$NON-NLS-1$
301  pnlJoint2_.setLayoutData(new GridData(GridData.FILL_BOTH));
302  //pnlJoint2_.setBounds(0 + 180,0,180,60);
303 
304  lblFriction_ = new Label(this,SWT.SHADOW_NONE);
305  lblFriction_.setText(MessageBundle.get("panel.collision.friction")); //$NON-NLS-1$
306  //lblFriction_.setBounds(20,60+24+24+ 24,144,24);
307 
308  new Label(this,SWT.SHADOW_NONE);//dummy
309 
310  lblStaticFric_ = new Label(this,SWT.SHADOW_NONE);
311  lblStaticFric_.setText(MessageBundle.get("panel.collision.staticFriction")); //$NON-NLS-1$
312  lblStaticFric_.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
313  //lblStaticFric_.setBounds(0,60+24 + 24+ 24 + 24,144,24);
314 
315  txtStaticFric_ = new Text(this,SWT.SINGLE | SWT.BORDER);
316  txtStaticFric_.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
317  //txtStaticFric_.setBounds(150,60+24+ 24 + 24+ 24,80,24);
318 
319  lblSlidingFric_ = new Label(this,SWT.SHADOW_NONE);
320  lblSlidingFric_.setText(MessageBundle.get("panel.collision.slidingFriction")); //$NON-NLS-1$
321  lblSlidingFric_.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
322  //lblSlidingFric_.setBounds(0,60+24+24+ 24 + 24 + 24,144,24);
323 
324  txtSlidingFric_ = new Text(this,SWT.SINGLE | SWT.BORDER);
325  txtSlidingFric_.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
326  //txtSlidingFric_.setBounds(150,60+24+24+ 24 + 24+ 24,80,24);
327 
328  lblCullingThresh_ = new Label(this,SWT.SHADOW_NONE);
329  lblCullingThresh_.setText(MessageBundle.get("panel.collision.cullingThresh")); //$NON-NLS-1$
330  lblCullingThresh_.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
331 
332  txtCullingThresh_ = new Text(this,SWT.SINGLE | SWT.BORDER);
333  txtCullingThresh_.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
334 
335  lblRestitution_ = new Label(this,SWT.SHADOW_NONE);
336  lblRestitution_.setText(MessageBundle.get("panel.collision.restitution"));
337  lblRestitution_.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
338 
339  txtRestitution_ = new Text(this,SWT.SINGLE | SWT.BORDER);
340  txtRestitution_.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
341 
342  btnOk_ = new Button(this,SWT.PUSH);
343  btnOk_.setText(MessageBundle.get("dialog.okButton")); //$NON-NLS-1$
344  btnOk_.addSelectionListener(new SelectionListener(){
345 
346  public void widgetDefaultSelected(SelectionEvent e) {
347  }
348 
349  public void widgetSelected(SelectionEvent e) {
350  switch (mode_) {
351  case MODE_ADD:
352  if (pnlJoint1_.getObjectName().equals(pnlJoint2_.getObjectName())
353  && pnlJoint1_.getJointName().equals(pnlJoint2_.getJointName())) {
354  MessageDialog.openWarning(getShell(), "", MessageBundle.get("collision.invalid")); //$NON-NLS-1$ //$NON-NLS-2$
355  return;
356  }
357 
358  GrxCollisionPairItem item = _createItem(pnlJoint1_.getObjectName(), pnlJoint1_.getJointName(),
359  pnlJoint2_.getObjectName(), pnlJoint2_.getJointName());
360 
361  if (item == null ){
362  System.out.println("error: item = "+item); //$NON-NLS-1$
363  return;
364  }
365 
366  break;
367  case MODE_EDIT:
368  _setAttribute(node_);
369  break;
370  }
371  setEnabled(false);
372  }
373 
374 
375 
376  });
377 
378  GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
379  gridData.widthHint = BUTTON_WIDTH;
380  btnOk_.setLayoutData(gridData);
381  //btnOk_.setBounds(24,144+ 24+ 24+ 24,84,24);
382 
383  btnCancel_ = new Button(this,SWT.PUSH);
384  btnCancel_.setText(MessageBundle.get("dialog.cancelButton")); //$NON-NLS-1$
385  btnCancel_.addSelectionListener(new SelectionListener(){
386 
387  public void widgetDefaultSelected(SelectionEvent e) {
388  }
389 
390  public void widgetSelected(SelectionEvent e) {
391  doCancel();
392  }
393 
394  });
395  gridData = new GridData();
396  //gridData.widthHint = BUTTON_WIDTH;
397  btnCancel_.setLayoutData(gridData);
398  //btnCancel_.setBounds(24 + 84 + 12 ,144+ 24+ 24+ 24,84,24);
399  }
400 
401  private boolean _setAttribute(GrxCollisionPairItem node) {
402  try{
403  String sTxtStaticFric_ = txtStaticFric_.getText();
404  String sTxtSlidingFric_ = txtSlidingFric_.getText();
405  String sTxtCullingThresh_ = txtCullingThresh_.getText();
406  String sTxtRestitution_ = txtRestitution_.getText();
407 
408  node.setProperty( ATTR_NAME_STATIC_FRICTION, sTxtStaticFric_ );
409  node.setProperty( ATTR_NAME_SLIDING_FRICTION, sTxtSlidingFric_ );
410  node.setProperty( ATTR_NAME_CULLING_THRESH, sTxtCullingThresh_ );
411  node.setProperty( ATTR_NAME_RESTITUTION, sTxtRestitution_ );
412  } catch (Exception ex) {
413  MessageDialog.openWarning(getShell(), "", MessageBundle.get("message.attributeerror")); //$NON-NLS-1$ //$NON-NLS-2$
414  return false;
415  }
416  return true;
417  }
418 
419  public void startAddMode() {
420  mode_ = MODE_ADD;
421  setEnabled(true);
422  if (pnlJoint1_.entry()){
423  pnlJoint2_.entry();
424  txtStaticFric_.setText(defaultStaticFriction_);
425  txtSlidingFric_.setText(defaultSlidingFriction_);
426  txtCullingThresh_.setText(defaultCullingThresh_);
427  txtRestitution_.setText(defaultRestitution_);
428  node_ = null;
429  }else{
430  doCancel();
431  }
432  }
433 
435  mode_ = MODE_EDIT;
436  setNode(node);
437  setEnabled(true);
438  }
439 
440  public void doCancel() {
441  setEnabled(false);
442  txtStaticFric_.setText(""); //$NON-NLS-1$
443  txtSlidingFric_.setText(""); //$NON-NLS-1$
444  txtCullingThresh_.setText(""); //$NON-NLS-1$
445  txtRestitution_.setText("");
446  }
447 
448  public void setNode(GrxCollisionPairItem node) {
449  try{
450  pnlJoint1_.setJoint(
451  node.getStr("objectName1", ""), //$NON-NLS-1$ //$NON-NLS-2$
452  node.getStr("jointName1", "") //$NON-NLS-1$ //$NON-NLS-2$
453  );
454  pnlJoint2_.setJoint(
455  node.getStr("objectName2", ""), //$NON-NLS-1$ //$NON-NLS-2$
456  node.getStr("jointName2", "") //$NON-NLS-1$ //$NON-NLS-2$
457  );
458  txtStaticFric_.setText(node.getStr(ATTR_NAME_STATIC_FRICTION, "")); //$NON-NLS-1$
459  txtSlidingFric_.setText(node.getStr(ATTR_NAME_SLIDING_FRICTION, "")); //$NON-NLS-1$
460  txtCullingThresh_.setText(node.getStr(ATTR_NAME_CULLING_THRESH, "")); //$NON-NLS-1$
461  txtRestitution_.setText(node.getStr(ATTR_NAME_RESTITUTION, ""));
462  } catch (Exception ex) {
463  ex.printStackTrace();
464  }
465  node_ = node;
466  }
467 
468  public void setEnabled(boolean flag) {
469  super.setEnabled(flag);
470  Control[] cmps = getChildren();
471  for (int i = 0; i < cmps.length; i ++) {
472  cmps[i].setEnabled(flag);
473  }
474 
475  if (mode_ == MODE_EDIT) {
476  pnlJoint1_.setEnabled(false);
477  pnlJoint2_.setEnabled(false);
478  }
479  _setButtonEnabled(!flag);
480 
481  lblStaticFric_.setEnabled(flag);
482  lblSlidingFric_.setEnabled(flag);
483  lblCullingThresh_.setEnabled(flag);
484  lblRestitution_.setEnabled(flag);
485  txtStaticFric_.setEnabled(true);
486  txtStaticFric_.setEditable(flag);
487  txtSlidingFric_.setEnabled(true);
488  txtSlidingFric_.setEditable(flag);
489  txtCullingThresh_.setEnabled(true);
490  txtCullingThresh_.setEditable(flag);
491  txtRestitution_.setEnabled(true);
492  txtRestitution_.setEditable(flag);
493  }
494 
495  private class JointSelectPanel extends Composite {
496  //private TitledBorder border_ = null;
497  private Combo boxObject_;
498  private Combo boxLink_;
499  boolean flag_ = false;
500 
501  //modelItemList_はboxObject_と同期をとってboxObjectに入ってぁE��名前をもつGrxModelItemを保持する
502  private List<GrxModelItem> modelItemList_;
503 
504  public JointSelectPanel(Composite parent,int style,String title) {
505  super(parent,style);
506  modelItemList_ = new ArrayList<GrxModelItem>();
507 
508  setLayout(new GridLayout(2,false));
509 
510  Label label = new Label(this,SWT.SHADOW_NONE);
511  label.setText(MessageBundle.get("panel.joint.object") + title); //$NON-NLS-1$
512  label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
513  //label.setBounds(0,6,48,12);
514 
515  boxObject_ = new Combo(this,SWT.READ_ONLY);
516  boxObject_.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
517  //boxObject_.setBounds(6+48,6 ,126,24);
518 
519  label = new Label(this,SWT.SHADOW_NONE);
520  label.setText(MessageBundle.get("panel.joint.link") + title); //$NON-NLS-1$
521  label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
522  //label.setBounds(0,6 + 24, 48, 12);
523 
524  boxLink_ = new Combo(this,SWT.READ_ONLY);
525  boxLink_.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
526  //boxLink_.setBounds(6+48,6 + 24,126,24);
527  //boxLink_.setLightWeightPopupEnabled(false);
528 
529  boxObject_.addSelectionListener(new SelectionListener(){
530 
531  public void widgetDefaultSelected(SelectionEvent e) {
532  }
533 
534  public void widgetSelected(SelectionEvent e) {
535  if (!flag_) {
536  _entryLink(
537  modelItemList_.get(boxObject_.getSelectionIndex())
538  );
539  }
540  }
541 
542  });
543  }
544 
545  private void _entryLink(GrxModelItem model) {
546  boxLink_.removeAll();
547  //boxLink_.add("");
548  for (int i=0; i<model.links_.size(); i++)
549  boxLink_.add(model.links_.get(i).getName());
550  boxLink_.deselectAll();
551  }
552 
553  public boolean entry() {
554  boolean addFlag = false;
555 
556  flag_ = true;
557  boxObject_.removeAll();
558  flag_ = false;
559 
560  Iterator it = manager_.getItemMap(GrxModelItem.class).values().iterator();
561  while (it.hasNext()) {
562  GrxModelItem model = (GrxModelItem)it.next();
563  modelItemList_.add(model);
564  boxObject_.add(model.toString());
565  addFlag = true;
566  }
567  return addFlag;
568  }
569 
570  public void remove() {
571  flag_ = true;
572  modelItemList_.clear();
573  boxObject_.removeAll();
574  flag_ = false;
575  boxLink_.removeAll();
576  }
577 
578  // TODO bad ←もともとあったメモ
579  public void setJoint(String obj,String joint) {
580  remove();
581  flag_ = true;
582  boxObject_.add(obj);
583  boxLink_.add(joint);
584  flag_ = false;
585  }
586 
587  public String getJointName() {
588  return boxLink_.getText();
589 
590  /*
591  Object link = boxLink_.getSelectedItem();
592  if (link instanceof GrxBaseItem) {
593  String linkName = ((GrxBaseItem)(link)).getName();
594  return linkName;
595  }
596  return "";
597  */
598  }
599 
600  public String getObjectName() {
601  return boxObject_.getText();
602  }
603 
604  public void setEnabled(boolean flag) {
605  super.setEnabled(flag);
606  Control[] cmps = getChildren();
607  for(int i = 0; i < cmps.length; i ++) {
608  cmps[i].setEnabled(flag);
609  }
610  }
611  }
612 
613  }
614 
615  private class InnerTableLabelProvider implements ITableLabelProvider{
616 
617  public Image getColumnImage(Object element, int columnIndex) {
618  return null;
619  }
620 
621  public String getColumnText(Object element, int columnIndex) {
622  GrxBaseItem item = (GrxBaseItem)element;
623  String str = null;
624  try {
625  str = item.getProperty(attrName_[columnIndex], ""); //$NON-NLS-1$
626  } catch (Exception ex) {
627  ex.printStackTrace();
628  }
629  return str;
630  }
631 
632  public void addListener(ILabelProviderListener listener) {
633  }
634 
635  public void dispose() {
636  }
637 
638  public boolean isLabelProperty(Object element, String property) {
639  return false;
640  }
641 
642  public void removeListener(ILabelProviderListener listener) {
643  }
644 
645  }
646 
647  public void updateCollisionPairs(List<GrxCollisionPairItem> clist, List<GrxModelItem> mlist) {
648  editorPanel_.doCancel();
649  vecCollision_ = new Vector<GrxCollisionPairItem>();
650  for (int i=0; i<clist.size(); i++)
651  vecCollision_.add(clist.get(i));
652  viewer_.getTable().deselectAll();
653  viewer_.setInput(vecCollision_);
654  setEnabled(vecCollision_.size() > 0 || !mlist.isEmpty());
655  _repaint();
656  }
657 
658  // TODO 動作確認忁E��EぁE��ぁE��なも�EがリフレチE��ュされなぁE��能性あり
659  public void replaceWorld(GrxWorldStateItem world) {
660  editorPanel_.doCancel();
661 
662  vecCollision_ = new Vector<GrxCollisionPairItem>();
663  viewer_.setInput(vecCollision_);
664  }
665 
667  int i;
668  for (i = 0; i < vecCollision_.size(); i ++) {
669  vecCollision_.get(i);
670  if (vecCollision_.get(i).getName().compareTo(item.getName()) > 0)
671  break;
672  }
673  vecCollision_.add(i, item);
674  _repaint();
675  return;
676  }
677 /*
678  public void childRemoved(SimulationNode node) {
679  if (node instanceof CollisionPairNode) {
680  vecCollision_.remove(node);
681  _repaint();
682  editorPanel_.doCancel();
683  return;
684  } else if (
685  node instanceof RobotNode ||
686  node instanceof EnvironmentNode
687  ){
688  Vector delete = new Vector();
689  for(int i = 0; i < vecCollision_.size(); i ++) {
690  CollisionPairNode col = (CollisionPairNode)vecCollision_.get(i);
691  if (col.isYourObject(node.getName())) {
692  delete.add(col);
693  }
694  }
695 
696  for (int i = 0; i < delete.size(); i ++) {
697  world_.removeChild((SimulationNode)delete.get(i));
698  }
699  editorPanel_.doCancel();
700  }
701  }
702 */
703  public Vector vecCollision(){ return vecCollision_; }
704 
705  private GrxCollisionPairItem _createItem(String oName1, String jName1, String oName2, String jName2) {
707  GrxCollisionPairItem.class,
708  "CP#"+oName1+"_"+jName1+"#"+oName2+"_"+jName2); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
709  if (item != null) {
710  item.setProperty("objectName1", oName1); //$NON-NLS-1$
711  item.setProperty("jointName1", jName1); //$NON-NLS-1$
712  item.setProperty("objectName2", oName2); //$NON-NLS-1$
713  item.setProperty("jointName2", jName2); //$NON-NLS-1$
714  editorPanel_._setAttribute(item);
715  }
716  manager_.itemChange(item, GrxPluginManager.ADD_ITEM);
717  manager_.setSelectedItem(item, true);
718  return item;
719  }
720 
721  public void updateTableFont(){
722  viewer_.getTable().setFont(Activator.getDefault().getFont("preference_table"));
723  }
724 }
static final String get(String key)
void itemChange(GrxBaseItem item, int event)
#define null
our own NULL pointer
Definition: IceTypes.h:57
CollisionPairPanel(Composite parent, int style, GrxPluginManager manager)
GrxBaseItem createItem(Class<?extends GrxBaseItem > cls, String name)
アイテムの作成. 指定したアイテムプラグインに、指定したアイテム名で新しいアイテムを作る。 ...
item corresponds to a robot model
png_uint_32 i
Definition: png.h:2735
void updateCollisionPairs(List< GrxCollisionPairItem > clist, List< GrxModelItem > mlist)
void setSelectedItem(GrxBaseItem item, boolean select)
select/unselect item
def j(str, encoding="cp932")
png_bytepp row
Definition: png.h:1759
Object setProperty(String key, String value)
set property value associated with a keyword
Map<?,?> getItemMap(Class<?extends GrxBaseItem > cls)
final String getStr(String key)
get value associated to keyword
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
final String toString()
convert to String. Currently, name is returned.
org
png_infop png_uint_32 flag
Definition: png.h:2159
GrxCollisionPairItem _createItem(String oName1, String jName1, String oName2, String jName2)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:37