1 package com.generalrobotix.ui.view;
4 import java.io.IOException;
6 import java.lang.reflect.InvocationTargetException;
8 import java.util.ArrayList;
10 import java.util.Vector;
12 import javax.media.j3d.Appearance;
13 import javax.media.j3d.BranchGroup;
14 import javax.media.j3d.GeometryArray;
15 import javax.media.j3d.Group;
16 import javax.media.j3d.LineArray;
17 import javax.media.j3d.Material;
18 import javax.media.j3d.Shape3D;
19 import javax.media.j3d.Switch;
20 import javax.media.j3d.Transform3D;
21 import javax.media.j3d.TransformGroup;
22 import javax.media.j3d.TransparencyAttributes;
23 import javax.vecmath.Color3f;
24 import javax.vecmath.Point3d;
25 import javax.vecmath.Vector3d;
38 import org.eclipse.core.runtime.FileLocator;
39 import org.eclipse.core.runtime.IProgressMonitor;
40 import org.eclipse.core.runtime.Path;
41 import org.eclipse.jface.dialogs.MessageDialog;
42 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
43 import org.eclipse.jface.operation.IRunnableWithProgress;
44 import org.eclipse.swt.SWT;
45 import org.eclipse.swt.events.FocusEvent;
46 import org.eclipse.swt.events.FocusListener;
47 import org.eclipse.swt.events.KeyEvent;
48 import org.eclipse.swt.events.KeyListener;
49 import org.eclipse.swt.events.SelectionAdapter;
50 import org.eclipse.swt.events.SelectionEvent;
51 import org.eclipse.swt.events.SelectionListener;
52 import org.eclipse.swt.layout.GridData;
53 import org.eclipse.swt.layout.GridLayout;
54 import org.eclipse.swt.widgets.Button;
55 import org.eclipse.swt.widgets.Combo;
56 import org.eclipse.swt.widgets.Composite;
57 import org.eclipse.swt.widgets.Control;
58 import org.eclipse.swt.widgets.Display;
59 import org.eclipse.swt.widgets.Label;
60 import org.eclipse.swt.widgets.Text;
79 import com.sun.j3d.utils.geometry.Box;
81 @SuppressWarnings(
"serial")
86 public static final String TITLE =
"Path Planning";
101 private static final String
FORMAT =
"%.3f";
102 private static final int TEXT_WIDTH = 64;
131 final double DEFAULT_CARPET_Z = 0.01;
144 super(name, manager, vp, parent);
146 GridLayout gl =
new GridLayout(1,
false);
147 getComposite().setLayout( gl );
175 private Composite
getComp(
int grid,
int style){
176 Composite comp =
new Composite( getComposite(), style );
177 GridLayout layout =
new GridLayout( grid,
false );
178 comp.setLayout( layout );
179 comp.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL) );
194 comp = getComp( 5, SWT.NONE );
196 l =
new Label(comp, SWT.NONE);
198 modelSelect =
new Combo( comp, SWT.NONE|SWT.READ_ONLY );
199 modelSelect.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL) );
200 modelSelect.addSelectionListener(
new SelectionListener(){
201 public void widgetDefaultSelected(SelectionEvent e) {
203 public void widgetSelected(SelectionEvent e) {
204 ppaItem_.
setProperty(
"model", modelSelect.getItem(modelSelect.getSelectionIndex()));
208 l =
new Label(comp, SWT.NONE);
210 mobilitySelect =
new Combo( comp, SWT.NONE|SWT.READ_ONLY );
211 mobilitySelect.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL) );
212 mobilitySelect.addSelectionListener(
new SelectionListener(){
213 public void widgetDefaultSelected(SelectionEvent e) {
215 public void widgetSelected(SelectionEvent e) {
216 ppaItem_.
setProperty(
"mobility", mobilitySelect.getItem(mobilitySelect.getSelectionIndex()));
222 comp = getComp( 8, SWT.NONE);
224 btnSetStartPoint =
new Button( comp, SWT.NONE );
225 btnSetStartPoint.setText(
MessageBundle.
get(
"GrxPathPlanningView.button.start"));
226 btnSetStartPoint.addSelectionListener(
new SelectionAdapter(){
227 public void widgetSelected(SelectionEvent e){
233 l =
new Label( comp, SWT.NONE );
235 textStartX =
new Text( comp, SWT.SINGLE | SWT.BORDER);
237 gd.widthHint = TEXT_WIDTH;
238 textStartX.setLayoutData( gd );
239 textStartX.addKeyListener(
new KeyListener(){
240 public void keyPressed(KeyEvent e) {
242 public void keyReleased(KeyEvent e) {
243 Double d = Double.parseDouble(textStartX.getText());
245 ppaItem_.
setDbl(
"startX", d);
250 l =
new Label( comp, SWT.NONE );
252 textStartY =
new Text( comp, SWT.SINGLE | SWT.BORDER);
254 gd.widthHint = TEXT_WIDTH;
255 textStartY.setLayoutData( gd );
256 textStartY.addKeyListener(
new KeyListener(){
257 public void keyPressed(KeyEvent e) {
259 public void keyReleased(KeyEvent e) {
260 Double d = Double.parseDouble(textStartY.getText());
262 ppaItem_.
setDbl(
"startY", d);
268 l =
new Label( comp, SWT.NONE );
270 textStartTheta =
new Text( comp, SWT.SINGLE | SWT.BORDER);
272 gd.widthHint = TEXT_WIDTH;
273 textStartTheta.setLayoutData( gd );
274 textStartTheta.addKeyListener(
new KeyListener(){
275 public void keyPressed(KeyEvent e) {
277 public void keyReleased(KeyEvent e) {
278 Double d = Double.parseDouble(textStartTheta.getText());
280 ppaItem_.
setDbl(
"startTheta", d);
286 Button setStart =
new Button( comp, SWT.NONE );
288 setStart.addSelectionListener(
new SelectionAdapter(){
289 public void widgetSelected(SelectionEvent e){
295 btnSetEndPoint =
new Button( comp, SWT.NONE );
296 btnSetEndPoint.setText(
MessageBundle.
get(
"GrxPathPlanningView.button.end"));
297 btnSetEndPoint.addSelectionListener(
new SelectionAdapter(){
298 public void widgetSelected(SelectionEvent e){
303 l =
new Label( comp, SWT.NONE );
305 textEndX =
new Text( comp, SWT.SINGLE | SWT.BORDER);
307 gd.widthHint = TEXT_WIDTH;
308 textEndX.setLayoutData( gd );
309 textEndX.addKeyListener(
new KeyListener(){
310 public void keyPressed(KeyEvent e) {
312 public void keyReleased(KeyEvent e) {
313 Double d = Double.parseDouble(textEndX.getText());
315 ppaItem_.
setDbl(
"goalX", d);
322 l =
new Label( comp, SWT.NONE );
324 textEndY =
new Text( comp, SWT.SINGLE | SWT.BORDER);
326 gd.widthHint = TEXT_WIDTH;
327 textEndY.setLayoutData( gd );
328 textEndY.addKeyListener(
new KeyListener(){
329 public void keyPressed(KeyEvent e) {
331 public void keyReleased(KeyEvent e) {
332 Double d = Double.parseDouble(textEndY.getText());
334 ppaItem_.
setDbl(
"goalY", d);
339 l =
new Label( comp, SWT.NONE );
341 textEndTheta =
new Text( comp, SWT.SINGLE | SWT.BORDER);
343 gd.widthHint = TEXT_WIDTH;
344 textEndTheta.setLayoutData( gd );
345 textEndTheta.addKeyListener(
new KeyListener(){
346 public void keyPressed(KeyEvent e) {
348 public void keyReleased(KeyEvent e) {
349 Double d = Double.parseDouble(textEndTheta.getText());
351 ppaItem_.
setDbl(
"goalTheta", d);
356 Button setEnd =
new Button( comp, SWT.NONE );
358 setEnd.addSelectionListener(
new SelectionAdapter(){
359 public void widgetSelected(SelectionEvent e){
365 Composite roboZComp = getComp( 4, SWT.NONE );
367 l =
new Label(roboZComp, SWT.NONE);
370 tolerance_ =
new Text(roboZComp, SWT.SINGLE | SWT.BORDER);
371 tolerance_.setText(
"0");
373 gd.widthHint = TEXT_WIDTH;
374 tolerance_.setLayoutData( gd );
375 tolerance_.addFocusListener(
new FocusListener(){
376 public void focusGained(FocusEvent e) {
378 public void focusLost(FocusEvent e) {
379 Double d = Double.parseDouble(tolerance_.getText());
381 ppaItem_.
setDbl(
"tolerance", d);
386 chkRebuildRoadmap_ =
new Button(roboZComp,SWT.CHECK);
387 chkRebuildRoadmap_.setText(
MessageBundle.
get(
"GrxPathPlanningView.button.rebuild"));
388 chkRebuildRoadmap_.addSelectionListener(
new SelectionListener(){
389 public void widgetDefaultSelected(SelectionEvent e) {
391 public void widgetSelected(SelectionEvent e) {
392 if (chkRebuildRoadmap_.getSelection()){
399 chkRebuildRoadmap_.setSelection(
true);
404 Composite algoComp = getComp( 3, SWT.NONE );
406 l =
new Label(algoComp, SWT.NONE);
408 algoSelect =
new Combo( algoComp, SWT.READ_ONLY );
409 algoSelect.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL) );
410 algoSelect.addSelectionListener(
new SelectionListener(){
411 public void widgetDefaultSelected(SelectionEvent e) {
413 public void widgetSelected(SelectionEvent e) {
414 ppaItem_.
setProperty(
"algorithm", algoSelect.getItem(algoSelect.getSelectionIndex()));
418 updatePropertyButton =
new Button(algoComp, SWT.NONE);
419 updatePropertyButton.setText(
MessageBundle.
get(
"GrxPathPlanningView.button.getProperties"));
420 updatePropertyButton.addSelectionListener(
new SelectionAdapter(){
421 public void widgetSelected(SelectionEvent e){
428 Composite calcComp = getComp( 5, SWT.NONE );
430 btnCalcStart =
new Button( calcComp, SWT.NONE );
431 btnCalcStart.setText(
MessageBundle.
get(
"GrxPathPlanningView.button.calcStart"));
432 btnCalcStart.addSelectionListener(
new SelectionAdapter(){
433 public void widgetSelected(SelectionEvent e){
441 imgLabel =
new Label(calcComp, SWT.BORDER);
445 l =
new Label(calcComp, SWT.NONE);
447 optimizerSelect =
new Combo( calcComp, SWT.NONE|SWT.READ_ONLY );
448 optimizerSelect.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL) );
449 optimizerSelect.addSelectionListener(
new SelectionListener(){
450 public void widgetDefaultSelected(SelectionEvent e) {
452 public void widgetSelected(SelectionEvent e) {
453 ppaItem_.
setProperty(
"optimizer", optimizerSelect.getItem(optimizerSelect.getSelectionIndex()));
457 optimizeButton =
new Button( calcComp, SWT.NONE );
458 optimizeButton.setText(
MessageBundle.
get(
"GrxPathPlanningView.button.optimize"));
459 optimizeButton.addSelectionListener(
new SelectionAdapter(){
460 public void widgetSelected(SelectionEvent e){
470 Composite carpetComp = getComp( 5, SWT.NONE );
472 l =
new Label(carpetComp, SWT.NONE);
475 btnVisible =
new Button( carpetComp, SWT.TOGGLE );
476 btnVisible.setText(
MessageBundle.
get(
"GrxPathPlanningView.button.visible"));
477 btnVisible.setSelection(
true);
478 btnVisible.addSelectionListener(
new SelectionAdapter(){
479 public void widgetSelected(SelectionEvent e){
480 boolean selection = btnVisible.getSelection();
482 System.out.println(
"TRUE");
483 switcher_.setWhichChild(0);
485 System.out.println(
"FALSE");
486 switcher_.setWhichChild(Switch.CHILD_NONE);
492 l =
new Label(carpetComp, SWT.NONE);
495 carpetZ =
new Text(carpetComp, SWT.SINGLE | SWT.BORDER );
496 carpetZ.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL) );
497 carpetZ.setText( String.valueOf(DEFAULT_CARPET_Z) );
498 carpetZ.addKeyListener(
new KeyListener(){
499 public void keyPressed(KeyEvent e) {}
500 public void keyReleased(KeyEvent e) {
501 if (e.character == SWT.CR) {
506 carpetZ.addFocusListener(
new FocusListener(){
507 public void focusGained(FocusEvent e) {
509 public void focusLost(FocusEvent e) {
510 Double d = Double.parseDouble(carpetZ.getText());
512 ppaItem_.
setDbl(
"carpetZ", d);
517 setScrollMinSize(SWT.DEFAULT,SWT.DEFAULT);
522 carpet_ =
new BranchGroup();
523 carpet_.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
524 carpet_.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
525 carpet_.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
526 carpet_.setCapability(BranchGroup.ALLOW_DETACH);
528 carpetTrans =
new Transform3D();
529 carpetTrans.setTranslation(
new Vector3d(0,0, getCarpetZPosition()) );
531 carpetTransGroup =
new TransformGroup();
532 carpetTransGroup.setCapability( TransformGroup.ALLOW_TRANSFORM_READ );
533 carpetTransGroup.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE );
534 carpetTransGroup.setCapability( Group.ALLOW_CHILDREN_WRITE);
535 carpetTransGroup.setCapability( Group.ALLOW_CHILDREN_EXTEND);
536 carpetTransGroup.setTransform( carpetTrans );
537 carpetTransGroup.addChild( carpet_ );
539 switcher_ =
new Switch();
540 switcher_.setCapability(Switch.ALLOW_SWITCH_READ);
541 switcher_.setCapability(Switch.ALLOW_SWITCH_WRITE);
542 switcher_.addChild( carpetTransGroup );
543 switcher_.setWhichChild(0);
552 algoSelect.removeAll();
553 for( String s: algoNames )
558 mobilitySelect.removeAll();
559 for( String s: mobilityNames )
560 mobilitySelect.add( s );
564 optimizerSelect.removeAll();
565 for( String s: optimizerNames )
566 optimizerSelect.add( s );
568 if (ppaItem_ !=
null){
569 String algorithmName = ppaItem_.
getStr(
"algorithm",
"");
570 if (algoSelect.indexOf(algorithmName) >= 0){
571 algoSelect.select(algoSelect.indexOf(algorithmName));
573 String mobilityName = ppaItem_.
getStr(
"mobility",
"");
574 if (mobilitySelect.indexOf(mobilityName) >= 0){
575 mobilitySelect.select(mobilitySelect.indexOf(mobilityName));
577 String optimizerName = ppaItem_.
getStr(
"optimizer",
"");
578 if (optimizerSelect.indexOf(optimizerName) >= 0){
579 optimizerSelect.select(optimizerSelect.indexOf(optimizerName));
589 carpetTransGroup.removeChild( carpet_ );
590 carpet_.removeAllChildren();
591 carpetTransGroup.addChild( carpet_ );
592 }
catch( Exception e ){
602 String robotName = modelSelect.getText();
606 double [] tr = robot.
getDblAry(getRobotBaseLink(robot)+
".translation",
null);
607 double [] rot = robot.
getDblAry(getRobotBaseLink(robot)+
".rotation",
null);
609 textStartX.setText( String.format( FORMAT, tr[0]) );
610 textStartY.setText( String.format( FORMAT, tr[1]) );
611 textStartTheta.setText( String.format( FORMAT, rot[3] / (2
f*Math.PI) * 360
f) );
612 if (ppaItem_ !=
null){
613 ppaItem_.
setDbl(
"startX", tr[0]);
614 ppaItem_.
setDbl(
"startY", tr[1]);
615 ppaItem_.
setDbl(
"startTheta", rot[3]);
623 String robotName = modelSelect.getText();
627 double [] tr = robot.
getDblAry(getRobotBaseLink(robot)+
".translation",
null);
628 double [] rot = robot.
getDblAry(getRobotBaseLink(robot)+
".rotation",
null);
630 textEndX.setText( String.format( FORMAT, tr[0]) );
631 textEndY.setText( String.format( FORMAT, tr[1]) );
632 textEndTheta.setText( String.format( FORMAT, rot[3] / (2
f*Math.PI) * 360
f) );
633 if (ppaItem_ !=
null){
634 ppaItem_.
setDbl(
"goalX", tr[0]);
635 ppaItem_.
setDbl(
"goalY", tr[1]);
636 ppaItem_.
setDbl(
"goalTheta", rot[3]);
652 for(
int i=0;
i+1<path.length;
i++ ) {
653 double []p1 = path[
i], p2 = path[
i+1];
664 double carpetHeight=0.01;
665 double dx = goal[0] - start[0], dy = goal[1] - start[1], len = Math.sqrt( dx/2*dx/2+dy/2*dy/2 );
671 theta = Math.atan2( dy,dx );
674 Point3d centerPoint =
new Point3d( (start[0]+goal[0])/2, (start[1]+goal[1])/2, 0 );
677 Appearance appea =
new Appearance( );
678 Material material =
new Material( );
679 Color3f color =
new Color3f( 0, 1
f, 0 );
680 material.setDiffuseColor( color );
681 appea.setMaterial( material );
682 appea.setTransparencyAttributes(
new TransparencyAttributes( TransparencyAttributes.NICEST,0.7f ) );
684 Box
box =
new Box( (
float)len, 0.1
f, (
float) carpetHeight, appea );
686 Transform3D tr =
new Transform3D();
687 tr.setTranslation(
new Vector3d( centerPoint ) );
688 Transform3D rot =
new Transform3D();
692 BranchGroup bg =
new BranchGroup();
693 TransformGroup newtg =
new TransformGroup( tr );
694 bg.addChild( newtg );
695 newtg.addChild( box );
696 carpet_.addChild( bg );
705 if ( view_ ==
null ){
708 BranchGroup bg =
new BranchGroup();
709 bg.addChild( switcher_ );
718 Vector<Point3d> vertex =
new Vector<Point3d>();
721 for( RoadmapNode
n : tree ){
722 Point3d
start =
new Point3d(
n.cfg[0],
n.cfg[1], 0 );
723 for(
int l :
n.neighbors ){
725 Point3d to =
new Point3d(tree[l].cfg[0],tree[l].cfg[1],0);
733 if (vertex.size() == 0)
return;
734 LineArray geometry =
new LineArray(vertex.size(), GeometryArray.COORDINATES | GeometryArray.COLOR_3);
735 geometry.setCoordinates(0, vertex.toArray(
new Point3d[vertex.size()]) );
736 for(
int i=0;
i<vertex.size();
i++)
737 geometry.setColor(
i,
new Color3f(Color.red));
740 Shape3D graph =
new Shape3D(geometry);
741 graph.setPickable(
false);
743 Transform3D tr =
new Transform3D();
744 tr.setTranslation(
new Vector3d( 0,0,0 ) );
745 BranchGroup bg =
new BranchGroup();
746 TransformGroup newtg =
new TransformGroup( tr );
747 bg.addChild( newtg );
748 newtg.addChild( graph );
750 carpet_.addChild( bg );
758 GrxPathPlanningAlgorithmItem ppa = (GrxPathPlanningAlgorithmItem) item;
785 String modelName =
null;
786 if (ppaItem_ !=
null){
789 modelName = modelSelect.getText();
792 Object[] items = manager_.getSelectedItemList(
GrxModelItem.class ).toArray();
793 modelSelect.removeAll();
794 for( Object o: items ){
797 modelSelect.add( o.toString() );
800 if (modelName !=
null && modelSelect.indexOf(modelName) >= 0){
801 modelSelect.select(modelSelect.indexOf(modelName));
804 if (ppaItem_ !=
null){
805 String mobilityName = ppaItem_.
getStr(
"mobility",
"");
806 if (mobilitySelect.indexOf(mobilityName) >= 0){
807 mobilitySelect.select(mobilitySelect.indexOf(mobilityName));
809 mobilitySelect.deselectAll();
811 String optimizerName = ppaItem_.
getStr(
"optimizer",
"");
812 if (optimizerSelect.indexOf(optimizerName) >= 0){
813 optimizerSelect.select(optimizerSelect.indexOf(optimizerName));
815 optimizerSelect.deselectAll();
817 String algorithmName = ppaItem_.
getStr(
"algorithm",
"");
818 if (algoSelect.indexOf(algorithmName) >= 0){
819 algoSelect.select(algoSelect.indexOf(algorithmName));
821 algoSelect.deselectAll();
825 textStartX.setText(sx.toString());
827 textStartX.setText(
"");
831 textStartY.setText(sy.toString());
833 textStartY.setText(
"");
835 Double st = ppaItem_.
getDbl(
"startTheta",
null);
837 textStartTheta.setText(st.toString());
839 textStartTheta.setText(
"");
843 textEndX.setText(ex.toString());
845 textEndX.setText(
"");
849 textEndY.setText(ey.toString());
851 textEndY.setText(
"");
853 Double et = ppaItem_.
getDbl(
"goalTheta",
null);
855 textEndTheta.setText(et.toString());
857 textEndTheta.setText(
"");
859 chkRebuildRoadmap_.setSelection(ppaItem_.
isTrue(
"rebuildRoadmap",
true));
860 tolerance_.setText(ppaItem_.
getDbl(
"tolerance",0.0).toString());
861 carpetZ.setText(ppaItem_.
getDbl(
"carpetZ",0.01).toString());
870 double getCarpetZPosition(){
873 z= Double.valueOf( carpetZ.getText() );
886 carpetTrans.setTranslation(
new Vector3d(0,0, getCarpetZPosition() ) );
887 carpetTransGroup.setTransform( carpetTrans );
895 Control[] ctl = getComposite().getChildren();
896 for (
int i=0;
i<ctl.length;
i++){
897 ctl[
i].setEnabled(b);
898 if (ctl[
i] instanceof Composite){
899 Composite cmp = (Composite)ctl[
i];
900 Control[] ctl2 = cmp.getChildren();
901 for (
int j=0; j<ctl2.length; j++){
902 ctl2[j].setEnabled(b);
909 if(ppaItem_==plugin){
910 if(((String)
arg[0]).equals(
"connected")){
Button updatePropertyButton
static final String get(String key)
void removeCarpet()
カーペットを削除
final boolean isTrue(String key)
check whether value associated to key includes a word "true"
String [] getAlgorithms()
void addObserver(GrxObserver v)
final double [] getDblAry(String key, double[] defaultVal)
get double array associated to key
#define null
our own NULL pointer
Composite getComp(int grid, int style)
String getRobotBaseLink(GrxModelItem model)
png_infop png_charpp name
item corresponds to a robot model
void deleteObserver(GrxObserver v)
Image getImage(String iconName)
final void setDbl(String key, double value)
associate double value to key
static final int SELECTED_ITEM
static Activator getDefault()
Button chkRebuildRoadmap_
GrxLinkItem rootLink()
get root link
static final int REMOVE_ITEM
void update(GrxBasePlugin plugin, Object... arg)
static void println(String s)
Object setProperty(String key, String value)
set property value associated with a keyword
RoadmapNode [] getRoadmap()
void registerItemChange(GrxBaseItem item, int event)
final Double getDbl(String key, Double defaultVal)
get double value associated to key
String [] getMobilityNames()
final String getStr(String key)
get value associated to keyword
TransformGroup carpetTransGroup
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
void propertyUpdate()
移動動作設計コンポーネントから現在選択している経路計画アルゴリズムに対するプロパティを取得し、選択し...
void attachUnclickable(BranchGroup bg)
final String getName()
get name
void carpet(double[] start, double[] goal)
void update()
移動動作設計コンポーネントから経路計画アルゴリズム名、移動アルゴリズム名、経路最適化アルゴリズム名を...
GrxPathPlanningView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
constructor
static final int NOTSELECTED_ITEM
void setEnabled(boolean b)
String [] getOptimizerNames()