18 package com.generalrobotix.ui.view.simulation;
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Vector;
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;
56 @SuppressWarnings(
"serial")
73 private static final String ATTR_NAME_STATIC_FRICTION =
"staticFriction";
74 private static final String ATTR_NAME_SLIDING_FRICTION =
"slidingFriction";
75 private static final String ATTR_NAME_CULLING_THRESH =
"cullingThresh";
76 private static final String ATTR_NAME_RESTITUTION =
"Restitution";
78 private final String[] clmName_ ={
89 private final String[] attrName_ ={
90 "objectName1",
"jointName1",
91 "objectName2",
"jointName2",
92 ATTR_NAME_STATIC_FRICTION, ATTR_NAME_SLIDING_FRICTION, ATTR_NAME_CULLING_THRESH, ATTR_NAME_RESTITUTION
95 private static final int BUTTONS_HEIGHT = 26;
98 super.setEnabled(flag);
99 if (editorPanel_ !=
null)
101 _setButtonEnabled(flag);
121 super(parent, style);
124 defaultStaticFriction_ =
"0.5";
125 defaultSlidingFriction_ =
"0.5";
126 defaultCullingThresh_ =
"0.01";
127 defaultRestitution_ =
"0.0";
129 vecCollision_ =
new Vector<GrxCollisionPairItem>();
131 setLayout(
new GridLayout(1,
false));
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());
137 viewer_.getTable().addSelectionListener(
new SelectionListener(){
139 public void widgetDefaultSelected(SelectionEvent e) {
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));
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));
154 viewer_.getTable().setLayout(tableLayout);
155 viewer_.getTable().setHeaderVisible(
true);
156 viewer_.getTable().setLinesVisible(
true);
157 viewer_.setInput(vecCollision_);
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));
166 btnAdd_ =
new Button(pnlBttn,SWT.PUSH);
168 btnAdd_.addSelectionListener(
new SelectionListener(){
170 public void widgetDefaultSelected(SelectionEvent e) {
173 public void widgetSelected(SelectionEvent e) {
174 _setButtonEnabled(
false);
180 btnRemove_ =
new Button(pnlBttn,SWT.PUSH);
182 btnRemove_.addSelectionListener(
new SelectionListener(){
184 public void widgetDefaultSelected(SelectionEvent e) {
187 public void widgetSelected(SelectionEvent e) {
188 int row = viewer_.getTable().getSelectionIndex();
189 if (row >= 0 && row < vecCollision_.size()) {
191 vecCollision_.get(row).delete();
198 btnEdit_ =
new Button(pnlBttn,SWT.PUSH);
200 btnEdit_.addSelectionListener(
new SelectionListener(){
202 public void widgetDefaultSelected(SelectionEvent e) {
205 public void widgetSelected(SelectionEvent e) {
206 int row = viewer_.getTable().getSelectionIndex() ;
207 if(row>=0 && row<vecCollision_.size()){
208 _setButtonEnabled(
false);
215 btnAddAll_ =
new Button(pnlBttn,SWT.PUSH);
217 btnAddAll_.addSelectionListener(
new SelectionListener(){
219 public void widgetDefaultSelected(SelectionEvent e) {
222 public void widgetSelected(SelectionEvent e) {
225 for (
int i=0;
i<list.size();
i++) {
227 for (
int j=
i;
j<list.size();
j++) {
229 for (
int k=0; k<m1.
links_.size(); k++) {
232 for (; l<m2.
links_.size(); l++) {
233 if (
i !=
j || k != l){
235 editorPanel_.txtSlidingFric_.setText(defaultSlidingFriction_);
236 editorPanel_.txtCullingThresh_.setText(defaultCullingThresh_);
237 editorPanel_.txtRestitution_.setText(defaultRestitution_);
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));
259 boolean overwrite = MessageDialog.openQuestion(getShell(),
MessageBundle.
get(
"dialog.overwrite"), msg);
264 btnAdd_.setEnabled(flag);
265 btnRemove_.setEnabled(flag);
266 btnEdit_.setEnabled(flag);
267 btnAddAll_.setEnabled(flag);
268 viewer_.getTable().setEnabled(flag);
278 private static final int MODE_ADD = 0 ;
279 private static final int MODE_EDIT = 1 ;
281 private static final int BUTTON_WIDTH = 50;
290 private Label
lblFriction_,lblStaticFric_,lblSlidingFric_,lblCullingThresh_,lblRestitution_;
294 setLayout(
new GridLayout(2,
false));
297 pnlJoint1_.setLayoutData(
new GridData(GridData.FILL_BOTH));
301 pnlJoint2_.setLayoutData(
new GridData(GridData.FILL_BOTH));
304 lblFriction_ =
new Label(
this,SWT.SHADOW_NONE);
308 new Label(
this,SWT.SHADOW_NONE);
310 lblStaticFric_ =
new Label(
this,SWT.SHADOW_NONE);
311 lblStaticFric_.setText(
MessageBundle.
get(
"panel.collision.staticFriction"));
312 lblStaticFric_.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
315 txtStaticFric_ =
new Text(
this,SWT.SINGLE | SWT.BORDER);
316 txtStaticFric_.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
319 lblSlidingFric_ =
new Label(
this,SWT.SHADOW_NONE);
320 lblSlidingFric_.setText(
MessageBundle.
get(
"panel.collision.slidingFriction"));
321 lblSlidingFric_.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
324 txtSlidingFric_ =
new Text(
this,SWT.SINGLE | SWT.BORDER);
325 txtSlidingFric_.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
328 lblCullingThresh_ =
new Label(
this,SWT.SHADOW_NONE);
329 lblCullingThresh_.setText(
MessageBundle.
get(
"panel.collision.cullingThresh"));
330 lblCullingThresh_.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
332 txtCullingThresh_ =
new Text(
this,SWT.SINGLE | SWT.BORDER);
333 txtCullingThresh_.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
335 lblRestitution_ =
new Label(
this,SWT.SHADOW_NONE);
337 lblRestitution_.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
339 txtRestitution_ =
new Text(
this,SWT.SINGLE | SWT.BORDER);
340 txtRestitution_.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
342 btnOk_ =
new Button(
this,SWT.PUSH);
344 btnOk_.addSelectionListener(
new SelectionListener(){
346 public void widgetDefaultSelected(SelectionEvent e) {
349 public void widgetSelected(SelectionEvent e) {
354 MessageDialog.openWarning(getShell(),
"",
MessageBundle.
get(
"collision.invalid"));
362 System.out.println(
"error: item = "+item);
368 _setAttribute(node_);
378 GridData gridData =
new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
379 gridData.widthHint = BUTTON_WIDTH;
380 btnOk_.setLayoutData(gridData);
383 btnCancel_ =
new Button(
this,SWT.PUSH);
385 btnCancel_.addSelectionListener(
new SelectionListener(){
387 public void widgetDefaultSelected(SelectionEvent e) {
390 public void widgetSelected(SelectionEvent e) {
395 gridData =
new GridData();
397 btnCancel_.setLayoutData(gridData);
403 String sTxtStaticFric_ = txtStaticFric_.getText();
404 String sTxtSlidingFric_ = txtSlidingFric_.getText();
405 String sTxtCullingThresh_ = txtCullingThresh_.getText();
406 String sTxtRestitution_ = txtRestitution_.getText();
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"));
422 if (pnlJoint1_.
entry()){
424 txtStaticFric_.setText(defaultStaticFriction_);
425 txtSlidingFric_.setText(defaultSlidingFriction_);
426 txtCullingThresh_.setText(defaultCullingThresh_);
427 txtRestitution_.setText(defaultRestitution_);
442 txtStaticFric_.setText(
"");
443 txtSlidingFric_.setText(
"");
444 txtCullingThresh_.setText(
"");
445 txtRestitution_.setText(
"");
451 node.
getStr(
"objectName1",
""),
452 node.
getStr(
"jointName1",
"")
455 node.
getStr(
"objectName2",
""),
456 node.
getStr(
"jointName2",
"")
458 txtStaticFric_.setText(node.
getStr(ATTR_NAME_STATIC_FRICTION,
""));
459 txtSlidingFric_.setText(node.
getStr(ATTR_NAME_SLIDING_FRICTION,
""));
460 txtCullingThresh_.setText(node.
getStr(ATTR_NAME_CULLING_THRESH,
""));
461 txtRestitution_.setText(node.
getStr(ATTR_NAME_RESTITUTION,
""));
462 }
catch (Exception ex) {
463 ex.printStackTrace();
469 super.setEnabled(flag);
470 Control[] cmps = getChildren();
471 for (
int i = 0;
i < cmps.length;
i ++) {
472 cmps[
i].setEnabled(flag);
475 if (mode_ == MODE_EDIT) {
479 _setButtonEnabled(!flag);
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);
499 boolean flag_ =
false;
506 modelItemList_ =
new ArrayList<GrxModelItem>();
508 setLayout(
new GridLayout(2,
false));
510 Label label =
new Label(
this,SWT.SHADOW_NONE);
512 label.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
515 boxObject_ =
new Combo(
this,SWT.READ_ONLY);
516 boxObject_.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
519 label =
new Label(
this,SWT.SHADOW_NONE);
521 label.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
524 boxLink_ =
new Combo(
this,SWT.READ_ONLY);
525 boxLink_.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
529 boxObject_.addSelectionListener(
new SelectionListener(){
531 public void widgetDefaultSelected(SelectionEvent e) {
534 public void widgetSelected(SelectionEvent e) {
537 modelItemList_.get(boxObject_.getSelectionIndex())
546 boxLink_.removeAll();
548 for (
int i=0;
i<model.
links_.size();
i++)
549 boxLink_.add(model.
links_.get(
i).getName());
550 boxLink_.deselectAll();
554 boolean addFlag =
false;
557 boxObject_.removeAll();
561 while (it.hasNext()) {
563 modelItemList_.add(model);
570 public void remove() {
572 modelItemList_.clear();
573 boxObject_.removeAll();
575 boxLink_.removeAll();
588 return boxLink_.getText();
601 return boxObject_.getText();
605 super.setEnabled(flag);
606 Control[] cmps = getChildren();
607 for(
int i = 0;
i < cmps.length;
i ++) {
608 cmps[
i].setEnabled(flag);
625 str = item.getProperty(attrName_[columnIndex],
"");
626 }
catch (Exception ex) {
627 ex.printStackTrace();
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());
662 vecCollision_ =
new Vector<GrxCollisionPairItem>();
663 viewer_.setInput(vecCollision_);
668 for (i = 0; i < vecCollision_.size(); i ++) {
669 vecCollision_.get(i);
670 if (vecCollision_.get(i).getName().compareTo(item.
getName()) > 0)
673 vecCollision_.add(i, item);
708 "CP#"+oName1+
"_"+jName1+
"#"+oName2+
"_"+jName2);
boolean _checkDialog(String msg)
static final String get(String key)
GrxCollisionPairItem node_
CollisionPairEditorPanel(Composite parent, int style)
List< GrxModelItem > modelItemList_
void itemChange(GrxBaseItem item, int event)
String defaultSlidingFriction_
#define null
our own NULL pointer
CollisionPairPanel(Composite parent, int style, GrxPluginManager manager)
GrxBaseItem createItem(Class<?extends GrxBaseItem > cls, String name)
アイテムの作成. 指定したアイテムプラグインに、指定したアイテム名で新しいアイテムを作る。 ...
item corresponds to a robot model
static final int ADD_ITEM
void startEditMode(GrxCollisionPairItem node)
void updateCollisionPairs(List< GrxCollisionPairItem > clist, List< GrxModelItem > mlist)
void _setButtonEnabled(boolean flag)
static Activator getDefault()
void _entryLink(GrxModelItem model)
void setSelectedItem(GrxBaseItem item, boolean select)
select/unselect item
Vector< GrxLinkItem > links_
def j(str, encoding="cp932")
JointSelectPanel pnlJoint2_
boolean _setAttribute(GrxCollisionPairItem node)
String defaultRestitution_
Object setProperty(String key, String value)
set property value associated with a keyword
Font getFont(String fontName)
GrxPluginManager manager_
Map<?,?> getItemMap(Class<?extends GrxBaseItem > cls)
JointSelectPanel pnlJoint1_
void removeListener(ILabelProviderListener listener)
final String getStr(String key)
get value associated to keyword
JointSelectPanel(Composite parent, int style, String title)
String defaultStaticFriction_
String defaultCullingThresh_
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
final String toString()
convert to String. Currently, name is returned.
String getColumnText(Object element, int columnIndex)
final String getName()
get name
Image getColumnImage(Object element, int columnIndex)
void setEnabled(boolean flag)
void setEnabled(boolean flag)
void childAdded(GrxCollisionPairItem item)
void addListener(ILabelProviderListener listener)
Vector< GrxCollisionPairItem > vecCollision_
png_infop png_uint_32 flag
void setNode(GrxCollisionPairItem node)
void replaceWorld(GrxWorldStateItem world)
GrxCollisionPairItem _createItem(String oName1, String jName1, String oName2, String jName2)
void setEnabled(boolean flag)
CollisionPairEditorPanel editorPanel_
void setJoint(String obj, String joint)
boolean isLabelProperty(Object element, String property)