1 package com.generalrobotix.ui.view.simulation;
3 import java.io.BufferedReader;
4 import java.io.BufferedWriter;
6 import java.io.FileNotFoundException;
7 import java.io.FileReader;
8 import java.io.FileWriter;
9 import java.io.IOException;
10 import java.util.HashMap;
11 import java.util.Iterator;
12 import java.util.Vector;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.jface.viewers.ArrayContentProvider;
18 import org.eclipse.jface.viewers.CellEditor;
19 import org.eclipse.jface.viewers.ComboBoxCellEditor;
20 import org.eclipse.jface.viewers.DialogCellEditor;
21 import org.eclipse.jface.viewers.ICellModifier;
22 import org.eclipse.jface.viewers.ILabelProviderListener;
23 import org.eclipse.jface.viewers.ITableLabelProvider;
24 import org.eclipse.jface.viewers.TableViewer;
25 import org.eclipse.jface.viewers.TextCellEditor;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.custom.PopupList;
28 import org.eclipse.swt.custom.StyledText;
29 import org.eclipse.swt.dnd.DND;
30 import org.eclipse.swt.dnd.DragSource;
31 import org.eclipse.swt.dnd.DragSourceEvent;
32 import org.eclipse.swt.dnd.DragSourceListener;
33 import org.eclipse.swt.dnd.DropTarget;
34 import org.eclipse.swt.dnd.DropTargetEvent;
35 import org.eclipse.swt.dnd.DropTargetListener;
36 import org.eclipse.swt.dnd.TextTransfer;
37 import org.eclipse.swt.dnd.Transfer;
38 import org.eclipse.swt.events.ModifyEvent;
39 import org.eclipse.swt.events.ModifyListener;
40 import org.eclipse.swt.events.MouseEvent;
41 import org.eclipse.swt.events.MouseListener;
42 import org.eclipse.swt.events.SelectionEvent;
43 import org.eclipse.swt.events.SelectionListener;
44 import org.eclipse.swt.graphics.Color;
45 import org.eclipse.swt.graphics.Image;
46 import org.eclipse.swt.graphics.Rectangle;
47 import org.eclipse.swt.layout.FillLayout;
48 import org.eclipse.swt.layout.GridData;
49 import org.eclipse.swt.layout.GridLayout;
50 import org.eclipse.swt.layout.RowLayout;
51 import org.eclipse.swt.widgets.Button;
52 import org.eclipse.swt.widgets.Composite;
53 import org.eclipse.swt.widgets.Control;
54 import org.eclipse.swt.widgets.FileDialog;
55 import org.eclipse.swt.widgets.Item;
56 import org.eclipse.swt.widgets.Label;
57 import org.eclipse.swt.widgets.Shell;
58 import org.eclipse.swt.widgets.Table;
59 import org.eclipse.swt.widgets.TableColumn;
60 import org.eclipse.swt.widgets.Text;
79 private Vector<Inport>
inport_ =
new Vector<Inport>();
80 private Vector<Outport>
outport_ =
new Vector<Outport>();
81 private HashMap<String, String>
connection_ =
new HashMap<String, String>();
91 public static enum NUMID_CODE {INVALID_TYPE, NOT_USED,
USED, ONLY_ONE, NUMBER};
93 String[] s =
new String[values().length];
113 int ordinal =
DataTypeId.valueOf(type).ordinal();
114 if(ordinal <= 3 || (8<=ordinal && ordinal <=11) )
116 if(4<=ordinal && ordinal<=7)
120 if(13<=ordinal && ordinal<=15)
155 if(System.getProperty(
"os.name").equals(
"Linux") || System.getProperty(
"os.name").equals(
"Mac OS X")){
162 commentChar_ =
"REM";
168 super.configureShell(newShell);
173 Composite composite = (Composite)super.createDialogArea(parent);
174 composite.setLayout(
new GridLayout(1,
true));
176 Composite panel0 =
new Composite(composite,SWT.NONE);
177 panel0.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
178 panel0.setLayout(
new GridLayout(3,
false));
179 Label label =
new Label(panel0, SWT.LEFT );
181 final Text text =
new Text(panel0, SWT.BORDER);
182 text.setText(controllerName_);
183 text.addModifyListener(
new ModifyListener(){
184 public void modifyText(ModifyEvent e) {
185 String newName = text.getText();
186 if(projectControllerName_.equals(newName))
190 controllerName_ = newName;
196 GridData gridData =
new GridData(GridData.FILL_HORIZONTAL);
197 gridData.horizontalSpan = 2;
198 text.setLayoutData(gridData);
199 Label label0 =
new Label(panel0, SWT.LEFT );
200 label0.setText(
MessageBundle.
get(
"panel.Bridge.robotName")+
":"+robotName_+
" ");
201 Label label1 =
new Label(panel0, SWT.LEFT);
203 label1.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
204 rrnText_ =
new Text(panel0, SWT.BORDER);
205 GridData gridData0 =
new GridData();
206 gridData0.horizontalAlignment = GridData.FILL;
207 gridData0.grabExcessHorizontalSpace =
true;
208 rrnText_.setLayoutData(gridData0);
210 rrnText_.addModifyListener(
new ModifyListener(){
211 public void modifyText(ModifyEvent e) {
212 if(rrnText_.isFocusControl()){
213 robotRtcName_ = rrnText_.getText();
219 tableviewer_ =
new TableViewer(composite, SWT.FULL_SELECTION | SWT.BORDER);
220 Table table = tableviewer_.getTable();
222 table.setLinesVisible(
true);
223 table.setHeaderVisible(
true);
224 TableColumn column =
new TableColumn(table,SWT.NONE);
225 column.setText(
"Type");
226 column.setWidth(100);
227 column =
new TableColumn(table,SWT.NONE);
228 column.setText(
"name");
229 column.setWidth(100);
230 column =
new TableColumn(table,SWT.NONE);
231 column.setText(
"property");
232 column.setWidth(100);
233 column =
new TableColumn(table,SWT.NONE);
234 column.setText(
"id");
235 column.setWidth(100);
236 column =
new TableColumn(table,SWT.NONE);
237 column.setText(
"output Time");
238 column.setWidth(100);
239 column =
new TableColumn(table,SWT.NONE);
240 column.setText(
"Controller : Port name");
241 column.setWidth(200);
242 GridData gridData1 =
new GridData(GridData.FILL_VERTICAL);
243 gridData1.minimumHeight = 200;
244 tableviewer_.getControl().setLayoutData(gridData1);
245 tableviewer_.setContentProvider(
new ArrayContentProvider());
247 tableviewer_.setInput(portTable_);
248 tableviewer_.setColumnProperties(
new String[] {
"type",
"name",
"property",
"id",
"time",
"portName"});
249 DialogCellEditor idCellEditor =
new DialogCellEditor(tableviewer_.getTable()){
250 protected Object openDialogBox(Control cellEditorWindow) {
252 dialog.
setId((String)getValue());
253 if(dialog.open() == IDialogConstants.OK_ID)
254 setValue(dialog.
getId());
258 CellEditor[] editors =
new CellEditor[] {
259 new ComboBoxCellEditor(tableviewer_.getTable(),
new String[]{
"IN",
"OUT" }),
260 new TextCellEditor(tableviewer_.getTable()),
263 new TextCellEditor(tableviewer_.getTable()),
264 new TextCellEditor(tableviewer_.getTable()) };
265 tableviewer_.setCellEditors(editors);
267 tableviewer_.getControl().addMouseListener(
new MouseListener(){
268 public void mouseDoubleClick(MouseEvent e) {
270 public void mouseDown(MouseEvent e) {
272 PopupList list =
new PopupList(getShell());
275 Rectangle rectangle = getShell().getBounds();
276 String s = list.open(
new Rectangle(rectangle.x+e.x, rectangle.y+e.y, 100, 100));
282 _port.
id_ =
"All joints";
285 portTable_.add(_port);
286 tableviewer_.refresh();
289 int row = tableviewer_.getTable().getSelectionIndex();
290 portTable_.remove(row);
291 tableviewer_.refresh();
296 public void mouseUp(MouseEvent e) {
301 Composite panel1 =
new Composite(composite,SWT.NONE);
302 panel1.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
303 panel1.setLayout(
new GridLayout(3,
false));
304 Label label2 =
new Label(panel1, SWT.LEFT );
306 Label label3 =
new Label(panel1, SWT.LEFT );
308 nshText_ =
new Text(panel1, SWT.BORDER);
309 Label dumy =
new Label(panel1, SWT.LEFT );
310 Label label4 =
new Label(panel1, SWT.LEFT );
312 nspText_ =
new Text(panel1, SWT.BORDER);
313 nshText_.setText(nameServer_.
host_);
314 nshText_.setLayoutData(gridData0);
315 nspText_.setText(nameServer_.
port_);
316 nspText_.setLayoutData(gridData0);
317 ModifyListener nsModifyListener =
new ModifyListener(){
318 public void modifyText(ModifyEvent e) {
319 nameServer_.
host_ = nshText_.getText();
320 nameServer_.
port_ = nspText_.getText();
324 nshText_.addModifyListener(nsModifyListener);
325 nspText_.addModifyListener(nsModifyListener);
327 Composite panel5 =
new Composite(composite,SWT.NONE);
328 panel5.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
329 panel5.setLayout(
new GridLayout(4,
false));
330 Label label8 =
new Label(panel5, SWT.LEFT );
332 final Text text4 =
new Text(panel5, SWT.BORDER);
333 text4.setLayoutData(gridData0);
334 text4.setText(moduleName_);
335 text4.addModifyListener(
new ModifyListener(){
336 public void modifyText(ModifyEvent e) {
337 moduleName_ = text4.getText();
341 Label label9 =
new Label(panel5, SWT.LEFT );
343 final Text text5 =
new Text(panel5, SWT.BORDER);
344 text5.setLayoutData(gridData0);
345 text5.setText(controllerRtcName_);
346 text5.addModifyListener(
new ModifyListener(){
347 public void modifyText(ModifyEvent e) {
348 controllerRtcName_ = text5.getText();
353 Composite panel6 =
new Composite(composite,SWT.NONE);
354 panel6.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
355 panel6.setLayout(
new GridLayout(2,
false));
356 final Button configFileButton =
new Button(panel6, SWT.CHECK);
358 configFileButton.addSelectionListener(
new SelectionListener(){
359 public void widgetDefaultSelected(SelectionEvent e) {
361 public void widgetSelected(SelectionEvent e) {
362 useConfigFile_ = configFileButton.getSelection();
367 configFileButton.setSelection(
true);
368 final Text text6 =
new Text(panel6, SWT.BORDER);
369 text6.setLayoutData(gridData0);
370 text6.setText(configFileName_);
371 text6.addModifyListener(
new ModifyListener(){
372 public void modifyText(ModifyEvent e) {
373 configFileName_ = text6.getText();
374 bridgeConfFileNameLabel_.setText(configFileName_);
379 Composite panel4 =
new Composite(composite,SWT.NONE);
380 panel4.setLayout(
new GridLayout(1,
false));
381 Button button =
new Button(panel4, SWT.PUSH);
383 button.addSelectionListener(
new SelectionListener(){
384 public void widgetDefaultSelected(SelectionEvent e) {
386 public void widgetSelected(SelectionEvent e) {
393 emText_.setText(errorMessage_);
396 fileNameLabel_ =
new Label(panel4, SWT.LEFT);
398 fileNameLabel_.setText(
"new file");
400 fileNameLabel_.setText(fileName_);
401 cbtext_ =
new StyledText(panel4, SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL);
402 GridData gridData2 =
new GridData();
403 gridData2.horizontalAlignment = GridData.FILL;
404 gridData2.grabExcessHorizontalSpace =
true;
405 gridData2.verticalAlignment = GridData.FILL;
406 gridData2.grabExcessVerticalSpace =
true;
407 gridData2.minimumHeight = 100;
408 gridData2.widthHint = 700;
409 cbtext_.setLayoutData(gridData2);
411 cbtext_.setEditable(
false);
412 bridgeConfFileNameLabel_ =
new Label(panel4, SWT.LEFT);
413 bridgeConfFileNameLabel_.setLayoutData(gridData0);
414 bridgeConfFileNameLabel_.setText(configFileName_);
415 bctext_ =
new StyledText(panel4, SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL);
416 GridData gridData5 =
new GridData();
417 gridData5.horizontalAlignment = GridData.FILL;
418 gridData5.grabExcessHorizontalSpace =
true;
419 gridData5.verticalAlignment = GridData.FILL;
420 gridData5.grabExcessVerticalSpace =
true;
421 gridData5.minimumHeight = 100;
422 gridData5.widthHint = 700;
423 bctext_.setLayoutData(gridData5);
425 bctext_.setEditable(
false);
428 Composite panel3 =
new Composite(composite,SWT.NONE);
429 panel3.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
430 panel3.setLayout(
new GridLayout(1,
false));
431 rtcConfFileNameLabel_ =
new Label(panel3, SWT.LEFT);
432 if(rtcConfFileName_.equals(
""))
433 rtcConfFileNameLabel_.setText(
"rtc.conf");
435 rtcConfFileNameLabel_.setText(rtcConfFileName_);
436 rctext_ =
new StyledText(panel3, SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL );
437 GridData gridData4 =
new GridData();
438 gridData4.horizontalAlignment = GridData.FILL;
439 gridData4.grabExcessHorizontalSpace =
true;
440 gridData4.verticalAlignment = GridData.FILL;
441 gridData4.grabExcessVerticalSpace =
true;
442 gridData4.widthHint = 700;
443 gridData4.minimumHeight = 50;
444 rctext_.setLayoutData(gridData4);
447 rctext_.setEditable(
false);
449 emText_ =
new StyledText(panel3, SWT.NONE );
450 GridData gridData3 =
new GridData();
451 gridData3.horizontalAlignment = GridData.FILL;
452 gridData3.grabExcessHorizontalSpace =
true;
453 gridData3.verticalAlignment = GridData.FILL;
454 gridData3.grabExcessVerticalSpace =
true;
455 gridData3.minimumHeight = 50;
456 emText_.setLayoutData(gridData3);
457 emText_.setBackground(panel3.getBackground());
458 emText_.setEditable(
false);
459 emText_.setText(errorMessage_);
465 private final int SAVE_ID = IDialogConstants.CLIENT_ID;
468 saveButton_ = createButton(parent, SAVE_ID,
MessageBundle.
get(
"GrxTextItem.menu.save"),
false);
469 saveAsButton_ = createButton(parent, SAVE_AS_ID,
MessageBundle.
get(
"GrxTextItem.menu.saveAs"),
false);
471 createButton(parent, IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL,
false);
475 if (buttonId == SAVE_ID) {
477 }
else if(buttonId == SAVE_AS_ID){
480 }
else if(buttonId == IDialogConstants.CLOSE_ID){
520 public boolean canModify(Object element, String property) {
524 public Object
getValue(Object element, String property) {
526 if(property.equals(
"type"))
527 return port.
type_.equals(
"IN") ? 0 : 1 ;
528 else if(property.equals(
"name"))
530 else if(property.equals(
"property")){
532 }
else if(property.equals(
"id"))
534 else if(property.equals(
"time"))
536 else if(property.equals(
"portName"))
541 public void modify(Object element, String property, Object
value) {
542 if (element instanceof Item) {
543 element = ((Item) element).getData();
546 if(property.equals(
"type"))
547 port.
type_ = (Integer)value==0 ?
"IN" :
"OUT";
548 else if(property.equals(
"name"))
550 else if(property.equals(
"property")){
552 }
else if(property.equals(
"id"))
554 else if(property.equals(
"time"))
556 else if(property.equals(
"portName"))
559 tableviewer_.update(element,
null);
563 public boolean load(String fileName){
565 if (file ==
null || !file.isFile())
568 fileName_ = fileName;
570 BufferedReader
reader =
new BufferedReader(
new FileReader(file));
572 boolean comline =
false;
574 while (reader.ready()) {
575 String
string = reader.readLine();
576 if(
string.startsWith(commentChar_))
578 controllerBridgeFile_.add(
string);
579 int index =
string.indexOf(
"openhrp-controller-bridge");
582 string =
string.substring(index+25).trim();
583 commandLineStart_ =
i;
586 string =
string.trim();
587 if(
string.endsWith(endChar_)){
588 option +=
string.substring(0,
string.
length()-1);
598 if(!option.equals(
"")){
599 String[] options = option.split(
"--");
600 rtcConfFileName_ = file.getCanonicalFile().getParent()+
File.separator+
"rtc.conf";
610 }
catch (FileNotFoundException e) {
613 }
catch (IOException e) {
622 if (file ==
null || !file.isFile())
625 BufferedReader
reader =
new BufferedReader(
new FileReader(file));
626 while (reader.ready()) {
627 String
string = reader.readLine();
628 if(
string.startsWith(
"#"))
630 rtcConfFile_.add(
string);
631 String string0 =
string.trim();
632 if(string0.startsWith(
"corba.nameservers:")){
633 String[] s=string0.substring(18).trim().split(
":");
635 rtcNameServer_.
host_ = s[0];
636 rtcNameServer_.
port_ = s[1];
638 }
else if(
string.trim().startsWith(
"manager.modules.preload:"))
639 moduleName_ = string0.substring(24).trim();
640 else if(
string.trim().startsWith(
"manager.components.precreate:"))
641 controllerRtcName_ = string0.substring(29).trim();
645 }
catch (FileNotFoundException e) {
648 }
catch (IOException e) {
657 rtcConfFileName_ =
"";
658 controllerBridgeFile_.clear();
660 controllerBridgeFile_.add(
"#!/bin/sh");
661 commandLineStart_ = 1;
664 commandLineStart_ = 0;
667 controllerBridgeFile_.add(
"openhrp-controller-bridge "+endChar_);
670 controllerName_ =
"";
675 nameServer_.
host_ =
"127.0.0.1";
676 nameServer_.
port_ =
"2809";
678 useConfigFile_ =
false;
679 configFileName_ =
"";
684 rtcConfFile_.clear();
685 rtcConfFile_.add(
"corba.nameservers: "+host+
":"+port);
686 rtcConfFile_.add(
"naming.formats: %n.rtc");
687 rtcConfFile_.add(
"logger.log_level: TRACE");
688 rtcConfFile_.add(
"exec_cxt.periodic.type: SynchExtTriggerEC");
689 rtcConfFile_.add(
"exec_cxt.periodic.rate: 1000000");
690 rtcConfFile_.add(
"manager.modules.load_path: .");
691 rtcConfFile_.add(
"manager.modules.abs_path_allowed: yes");
692 rtcConfFile_.add(
"manager.modules.preload: ");
693 rtcConfFile_.add(
"manager.components.precreate: ");
694 rtcNameServer_.
host_ = host;
695 rtcNameServer_.
port_ = port;
697 controllerRtcName_ =
"";
703 controllerBridgeFile_.clear();
705 controllerName_ =
"";
710 nameServer_.
host_ =
"127.0.0.1";
711 nameServer_.
port_ =
"2809";
714 rtcConfFile_.clear();
715 rtcNameServer_.
host_ =
"";
716 rtcNameServer_.
port_ =
"";
718 controllerRtcName_ =
"";
719 useConfigFile_ =
false;
720 configFileName_ =
"";
723 private void parse(String[] options){
724 for(
int i=0;
i<options.length;
i++){
725 options[
i] = options[
i].trim();
726 int endIndex = options[
i].indexOf(
" ");
729 String
option = options[
i].substring(0,endIndex);
730 String parameter = options[
i].substring(endIndex).trim();
731 if(option.equals(
"server-name")){
732 controllerName_ = parameter;
733 }
else if(option.equals(
"in-port")){
735 String[] s = parameter.split(
":");
737 _inport.
name_ = s[0].trim();
740 }
else if(s.length==3){
741 _inport.
name_ = s[0].trim();
743 _inport.
id_ = s[1].split(
",");
744 for(
int j=0; j<_inport.
id_.length; j++)
745 _inport.
id_[j] = _inport.
id_[j].trim();
748 inport_.add(_inport);
750 }
else if(option.equals(
"out-port")){
752 String[] s = parameter.split(
":");
753 _outport.
name_ = s[0].trim();
763 }
catch(IllegalArgumentException e){
767 String[] _id = s[j].split(
",");
768 _outport.
idName_ =
new String[_id.length];
769 for(
int k=0; k<_id.length; k++){
771 _outport.
idNo_ = Integer.parseInt(_id[k]);
773 }
catch(NumberFormatException ex){
774 _outport.
idName_[k] = _id[k].trim();
785 outport_.add(_outport);
786 }
else if(option.equals(
"connection")){
787 String[] s = parameter.split(
":");
788 String controllerPortName=
"";
790 controllerPortName = controllerRtcName_+
"0:"+s[1].trim();
791 }
else if(s.length ==3){
792 controllerPortName = s[1].trim()+
":"+s[2].trim();
794 connection_.put(s[0].trim(), controllerPortName);
795 }
else if(option.equals(
"robot-name")){
796 robotRtcName_ = parameter;
797 }
else if(option.equals(
"name-server")){
798 String[] s = parameter.split(
":");
799 nameServer_.
host_ = s[0].trim();
800 nameServer_.
port_ = s[1].trim();
801 }
else if(option.equals(
"config-file")){
803 useConfigFile_ =
true;
804 configFileName_ = parameter;
812 fileName = file.getCanonicalFile().getParent()+
File.separator+fileName;
813 }
catch (IOException e) {
816 file =
new File(fileName);
817 if (file ==
null || !file.isFile())
820 BufferedReader
reader =
new BufferedReader(
new FileReader(file));
821 Vector<String> options =
new Vector<String>();
822 while (reader.ready()) {
823 String
string = reader.readLine();
824 if(
string.startsWith(
"#"))
826 bridgeConfFile_.append(
string+
"\n");
827 String[] s =
string.split(
"=");
829 options.add(s[0]+
" "+s[1]);
831 parse(options.toArray(
new String[0]));
833 }
catch (FileNotFoundException e) {
836 }
catch (IOException e) {
844 Iterator<Inport> it = inport_.iterator();
852 _port.
id_ =
"All joints";
855 for(
int i=0;
i<inport.
id_.length-1;
i++)
856 _port.
id_ += inport.
id_[
i] +
",";
857 _port.
id_ += inport.
id_[inport.
id_.length-1];
860 String controllerPort = connection_.get(inport.
name_);
861 if(controllerPort==
null)
864 portTable_.add(_port);
866 Iterator<Outport> it0 = outport_.iterator();
867 while(it0.hasNext()){
874 _port.
id_ =
"All joints";
875 else if(outport.
idNo_ != -1){
876 _port.
id_ = String.valueOf(outport.
idNo_);
887 String controllerPort = connection_.get(outport.
name_);
888 if(controllerPort==
null)
891 portTable_.add(_port);
929 projectControllerName_ = _controllerName;
930 if(projectControllerName_.equals(controllerName_))
937 controllerName_ = _controllerName;
941 if(nameServer_.
host_.equals(rtcNameServer_.
host_) && nameServer_.
port_.equals(rtcNameServer_.
port_))
953 if(fileName_.equals(
""))
957 if(rtcConfFileName_.equals(
"")){
959 rtcConfFileName_ = file.getCanonicalFile().getParent()+
File.separator+
"rtc.conf";
960 }
catch (IOException e) {
964 String bridgeConfFileName=
null;
968 }
catch (IOException e) {
973 BufferedWriter
writer =
new BufferedWriter(
new FileWriter(fileName_));
974 Iterator<String> it = controllerBridgeFile_.iterator();
976 writer.write(it.next());
982 writer =
new BufferedWriter(
new FileWriter(rtcConfFileName_));
983 it = rtcConfFile_.iterator();
985 writer.write(it.next());
992 writer =
new BufferedWriter(
new FileWriter(bridgeConfFileName));
993 writer.write(bridgeConfFile_.toString());
997 }
catch (IOException e) {
1000 fileNameLabel_.setText(fileName_);
1001 rtcConfFileNameLabel_.setText(rtcConfFileName_);
1007 String fileName = fdlg.open();
1008 if( fileName !=
null ) {
1009 fileName_ = fileName;
1012 rtcConfFileName_ = file.getCanonicalFile().getParent()+
File.separator+
"rtc.conf";
1013 file =
new File(rtcConfFileName_);
1015 if(!MessageDialog.openQuestion(getShell(), rtcConfFileName_,
MessageBundle.
get(
"Grx3DView.dialog.message.fileExist"))){
1016 fdlg.setFileName(rtcConfFileName_);
1017 rtcConfFileName_ = fdlg.open();
1018 if(rtcConfFileName_==
null)
1022 }
catch (IOException e) {
1023 e.printStackTrace();
1031 String commandLine = controllerBridgeFile_.get(commandLineStart_);
1032 int index = commandLine.indexOf(
"openhrp-controller-bridge");
1034 commandLine = commandLine.substring(0,index+25)+
" ";
1037 controllerBridgeFile_.remove(
i);
1038 bridgeConfFile_ =
new StringBuffer();
1041 controllerBridgeFile_.insertElementAt( commandLine+
"--config-file "+configFileName_,commandLineStart_);
1046 controllerBridgeFile_.insertElementAt(commandLine+endChar_, i++);
1047 if(!controllerName_.equals(
"")){
1048 String
string =
"--server-name "+controllerName_ +
" "+
endChar_;
1049 controllerBridgeFile_.insertElementAt(
string, i++);
1051 Iterator<Port> it = portTable_.iterator();
1052 while(it.hasNext()){
1054 Port port = it.next();
1055 if(port.
type_.equals(
"IN")){
1056 string +=
"--in-port "+port.
name_;
1057 if(!port.
id_.equals(
"All joints") && !port.
id_.equals(
""))
1058 string +=
":"+port.
id_;
1061 string +=
"--out-port "+port.
name_;
1062 if(!port.
id_.equals(
"All joints") && !port.
id_.equals(
""))
1063 string +=
":"+port.
id_;
1069 controllerBridgeFile_.insertElementAt(
string, i++);
1073 if(s.length==2 && s[0].equals(controllerRtcName_+
"0"))
1074 controllerPortName = s[1];
1075 string =
"--connection "+port.
name_+
":"+controllerPortName+
" "+
endChar_;
1076 controllerBridgeFile_.insertElementAt(
string, i++);
1079 if(!robotRtcName_.equals(
"")){
1080 String
string =
"--robot-name "+robotRtcName_ +
" "+
endChar_;
1081 controllerBridgeFile_.insertElementAt(
string, i++);
1083 if(!nameServer_.
host_.equals(
"127.0.0.1") || !nameServer_.
port_.equals(
"2809")){
1084 String
string =
"--name-server "+nameServer_.
host_+
":"+nameServer_.
port_+
" " +
endChar_;
1085 controllerBridgeFile_.insertElementAt(
string, i++);
1088 commandLineEnd_ = i-1;
1089 String
string = controllerBridgeFile_.get(commandLineEnd_);
1090 string =
string.substring(0,
string.
length()-1);
1091 controllerBridgeFile_.setElementAt(
string, commandLineEnd_);
1096 String lineSeparator = System.getProperty(
"line.separator");
1097 if(!controllerName_.equals(
"")){
1098 bridgeConfFile_.append(
"server-name = "+controllerName_ +lineSeparator);
1100 Iterator<Port> it = portTable_.iterator();
1101 while(it.hasNext()){
1103 Port port = it.next();
1104 if(port.
type_.equals(
"IN")){
1105 string +=
"in-port = "+port.
name_;
1106 if(!port.
id_.equals(
"All joints") && !port.
id_.equals(
""))
1107 string +=
":"+port.
id_;
1110 string +=
"out-port = "+port.
name_;
1111 if(!port.
id_.equals(
"All joints") && !port.
id_.equals(
""))
1112 string +=
":"+port.
id_;
1117 bridgeConfFile_.append(
string+lineSeparator);
1121 if(s.length==2 && s[0].equals(controllerRtcName_+
"0"))
1122 controllerPortName = s[1];
1123 string =
"connection = "+port.
name_+
":"+controllerPortName+lineSeparator;
1124 bridgeConfFile_.append(
string);
1127 if(!robotRtcName_.equals(
"")){
1128 String
string =
"robot-name = "+robotRtcName_ +lineSeparator;
1129 bridgeConfFile_.append(
string);
1131 if(!nameServer_.
host_.equals(
"127.0.0.1") || !nameServer_.
port_.equals(
"2809")){
1132 String
string =
"name-server = "+nameServer_.
host_+
":"+nameServer_.
port_+lineSeparator;
1133 bridgeConfFile_.append(
string);
1138 for(
int i=0;
i<rtcConfFile_.size();
i++){
1139 String
string = rtcConfFile_.get(
i).trim();
1140 if(
string.startsWith(
"corba.nameservers:")){
1141 String s=
string.substring(0,18)+
" "+ nameServer_.
host_+
":"+nameServer_.
port_;
1142 rtcConfFile_.setElementAt(s,
i);
1143 }
else if(
string.startsWith(
"manager.modules.preload:")){
1145 rtcConfFile_.setElementAt(s,
i);
1146 }
else if(
string.startsWith(
"manager.components.precreate:")){
1148 rtcConfFile_.setElementAt(s,
i);
1155 Iterator<String> it = controllerBridgeFile_.iterator();
1157 s += it.next() +
"\n";
1159 bctext_.setText(bridgeConfFile_.toString());
1164 Iterator<String> it = rtcConfFile_.iterator();
1166 s += it.next() +
"\n";
1171 if(robotRtcName_.equals(
""))
1172 rrnText_.setText(controllerName_+
"(robot)");
1174 rrnText_.setText(robotRtcName_);
1178 saveButton_.setEnabled(b);
1179 saveAsButton_.setEnabled(b);
1184 if(!projectControllerName_.equals(controllerName_))
1186 Iterator<Port> it = portTable_.iterator();
1187 while(it.hasNext()){
1188 Port port = it.next();
1189 if(port.
name_.equals(
""))
1195 String[] s = port.
id_.split(
",");
1201 Integer.valueOf(port.
id_);
1202 }
catch(NumberFormatException e){
1206 if(port.
type_.equals(
"IN")){
1217 if(time < controlTime_){
1220 }
catch(NumberFormatException e){
1229 if(moduleName_.equals(
""))
1231 if(controllerRtcName_.equals(
""))
1232 errorMessage_ +=
MessageBundle.
get(
"panel.Bridge.error.controlRTCName")+
"\n";
1233 if(useConfigFile_ && configFileName_.equals(
""))
1234 errorMessage_ +=
MessageBundle.
get(
"panel.Bridge.error.configFileName")+
"\n";
1237 @SuppressWarnings(
"unchecked")
1250 return name_.equals(((
IdData)
object).name_);
1252 return name_.equals(((
IdData)
object).name_) || id_ == ((
IdData)
object).id_ ;
1257 super(name, jointId);
1267 private Vector<Link> links_ =
new Vector<Link>();
1270 private Vector<Button> linkButtons_ =
new Vector<Button>();
1277 for(
int i=0;
i<joints.length;
i++)
1278 links_.add(
new Link(joints[
i], i));
1279 Iterator<GrxLinkItem> it = robot_.
links_.iterator();
1280 while(it.hasNext()){
1286 sensors_[
i] =
new Vector<IdData>();
1289 for(
int j=0; j<names.length; j++)
1290 sensors_[i].add(
new IdData(names[j], j));
1292 sensorButtons_[
i] =
new Vector<Button>();
1297 Composite composite = (Composite)super.createDialogArea(parent);
1298 composite.setLayout(
new GridLayout(2,
true));
1300 Composite panel0 =
new Composite(composite,SWT.NONE);
1301 panel0.setLayoutData(
new GridData(GridData.FILL_VERTICAL));
1302 panel0.setLayout(
new FillLayout(SWT.VERTICAL));
1303 Label label0 =
new Label(panel0, SWT.NONE);
1304 label0.setText(
"Link");
1306 allJointButton_ =
new Button(panel0, SWT.TOGGLE|SWT.CENTER);
1307 allJointButton_.setText(
"All joints");
1308 allJointButton_.addSelectionListener(
new SelectionListener(){
1309 public void widgetDefaultSelected(SelectionEvent e) {
1311 public void widgetSelected(SelectionEvent e) {
1312 if(allJointButton_.getSelection()){
1313 for(
int i=0;
i<links_.size();
i++){
1314 if(links_.get(
i).isJoint())
1315 linkButtons_.get(
i).setSelection(
true);
1318 for(
int i=0;
i<links_.size();
i++){
1319 if(links_.get(
i).isJoint())
1320 linkButtons_.get(
i).setSelection(
false);
1325 for(
int i=0;
i<links_.size();
i++){
1326 linkButtons_.add(
new Button(panel0, SWT.CHECK|SWT.LEFT));
1327 linkButtons_.get(
i).addSelectionListener(
new SelectionListener(){
1328 public void widgetDefaultSelected(SelectionEvent e) {
1330 public void widgetSelected(SelectionEvent e) {
1331 updateAllJointButton();
1335 updateButton(
true, 0);
1337 Composite panel1 =
new Composite(composite,SWT.NONE);
1338 panel1.setLayoutData(
new GridData(GridData.FILL_VERTICAL));
1339 panel1.setLayout(
new RowLayout(SWT.VERTICAL));
1341 Label label =
new Label(panel1, SWT.NONE);
1344 for(
int j=0; j<sensors_[
i].size(); j++){
1345 sensorButtons_[
i].add(
new Button(panel1, SWT.CHECK|SWT.LEFT));
1347 Label dumy =
new Label(panel1, SWT.NONE);
1349 updateButton(
false, -1);
1351 Transfer [] transfers =
new Transfer[]{ TextTransfer.getInstance() };
1352 DragSourceListener dragSourceListener =
new DragSourceListener() {
1353 public void dragFinished(DragSourceEvent event) {
1355 public void dragSetData(DragSourceEvent event) {
1356 Button sourceButton = (Button)((DragSource)
event.getSource()).getControl();
1357 int index = linkButtons_.indexOf(sourceButton);
1359 event.data =
"link "+String.valueOf(index);
1361 for(
int i=0;
i<sensorButtons_.length;
i++){
1362 index = sensorButtons_[
i].indexOf(sourceButton);
1364 event.data =
"sensor "+String.valueOf(
i)+
" "+String.valueOf(index);
1369 public void dragStart(DragSourceEvent event) {
1372 DropTargetListener dropTargetListener =
new DropTargetListener(){
1373 public void drop(DropTargetEvent event){
1375 Button targetButton = (Button)((DropTarget)
event.getSource()).getControl();
1376 String
string = (String)event.data;
1377 String[] source =
string.split(
" ");
1378 if(source[0].equals(
"link")){
1379 for(
int i=0;
i<links_.size();
i++)
1380 links_.get(
i).selection_ = linkButtons_.get(
i).getSelection();
1381 int sourceIndex = Integer.parseInt(source[1]);
1382 int targetIndex = linkButtons_.indexOf(targetButton);
1383 if(targetIndex >=0){
1384 Link sourceLink = links_.get(sourceIndex);
1385 Link targetLink = links_.get(targetIndex);
1386 links_.remove(sourceLink);
1387 links_.insertElementAt(sourceLink, links_.indexOf(targetLink));
1388 updateButton(
true, 0);
1391 int type = Integer.parseInt(source[1]);
1392 for(
int i=0;
i<sensors_[
type].size();
i++)
1393 sensors_[type].
get(
i).selection_ = sensorButtons_[
type].get(
i).getSelection();
1394 int sourceIndex = Integer.parseInt(source[2]);
1395 int targetIndex = sensorButtons_[
type].indexOf(targetButton);
1396 if(targetIndex >=0){
1397 IdData sourceData = sensors_[
type].get(sourceIndex);
1398 IdData targetData = sensors_[
type].get(targetIndex);
1399 sensors_[
type].remove(sourceData);
1400 sensors_[
type].insertElementAt(sourceData, sensors_[type].indexOf(targetData));
1401 updateButton(
false, type);
1406 private Color buttonColor_;
1407 public void dragEnter(DropTargetEvent event) {
1408 Button targetButton = (Button)((DropTarget)
event.getSource()).getControl();
1409 buttonColor_ = targetButton.getBackground();
1412 public void dragLeave(DropTargetEvent event) {
1413 Button targetButton = (Button)((DropTarget)
event.getSource()).getControl();
1414 targetButton.setBackground(buttonColor_);
1416 public void dragOperationChanged(DropTargetEvent event) {
1418 public void dragOver(DropTargetEvent event) {
1420 public void dropAccept(DropTargetEvent event) {
1423 for(
int i=0;
i<links_.size();
i++){
1424 DragSource source =
new DragSource(linkButtons_.get(
i), DND.DROP_MOVE );
1425 source.setTransfer(transfers);
1426 source.addDragListener(dragSourceListener);
1427 DropTarget target =
new DropTarget(linkButtons_.get(
i), DND.DROP_MOVE);
1428 target.setTransfer(transfers);
1429 target.addDropListener(dropTargetListener);
1432 for(
int i=0;
i<sensors_.length;
i++){
1433 for(
int j=0; j<sensors_[
i].size(); j++){
1434 DragSource source =
new DragSource(sensorButtons_[
i].
get(j), DND.DROP_MOVE );
1435 source.setTransfer(transfers);
1436 source.addDragListener(dragSourceListener);
1437 DropTarget target =
new DropTarget(sensorButtons_[
i].
get(j), DND.DROP_MOVE);
1438 target.setTransfer(transfers);
1439 target.addDropListener(dropTargetListener);
1447 if (buttonId == IDialogConstants.OK_ID) {
1449 for(
int i=0;
i<links_.size();
i++){
1450 if(links_.get(
i).isJoint()){
1452 if(!linkButtons_.get(
i).getSelection()){
1462 for(
int i=0;
i<linkButtons_.size();
i++)
1463 if(linkButtons_.get(
i).getSelection())
1464 id_ += links_.get(
i).name_ +
",";
1465 for(
int i=1;
i<sensorButtons_.length;
i++)
1466 for(
int j=0; j<sensorButtons_[
i].size(); j++)
1467 if(sensorButtons_[
i].
get(j).getSelection())
1468 id_ += sensors_[
i].
get(j).name_ +
",";
1470 id_ = id_.substring(0, id_.length()-1);
1472 for(
int i=0;
i<sensorButtons_[0].size();
i++)
1473 if(sensorButtons_[0].
get(
i).getSelection())
1474 id_ = String.valueOf(sensors_[0].get(
i).id_);
1478 super.buttonPressed(buttonId);
1487 if(id_.equals(
"All joints")){
1488 for(
int i=0;
i<links_.size();
i++){
1489 if(links_.get(
i).isJoint())
1490 links_.get(
i).selection_ =
true;
1493 String[] names = id_.split(
",");
1494 for(
int i=names.length;
i>0; ){
1495 String
name = names[--
i].trim();
1496 int index = links_.indexOf(
new Link(name, -1));
1498 Link link = links_.get(index);
1500 links_.remove(link);
1501 links_.insertElementAt(link, 0);
1505 index = sensors_[j].indexOf(
new IdData(name, -1));
1507 IdData idData = sensors_[j].get(index);
1509 sensors_[j].remove(idData);
1510 sensors_[j].insertElementAt(idData, 0);
1515 int id = Integer.valueOf(name);
1516 index = sensors_[0].indexOf(
new IdData(
"",
id));
1518 IdData idData = sensors_[0].get(index);
1520 sensors_[0].remove(idData);
1521 sensors_[0].insertElementAt(idData, 0);
1523 }
catch(NumberFormatException e){
1532 for(
int i=0;
i<links_.size();
i++){
1533 String
string = links_.get(
i).name_;
1534 if(links_.get(
i).isJoint())
1535 string +=
" (id= "+links_.get(
i).id_+
")";
1536 linkButtons_.get(
i).setText(
string);
1537 linkButtons_.get(
i).setSelection(links_.get(
i).selection_);
1539 updateAllJointButton();
1543 for(
int j=0; j<sensors_[
i].size(); j++){
1544 sensorButtons_[
i].get(j).setText(sensors_[
i].
get(j).name_+
" (id= "+sensors_[
i].
get(j).id_+
")");
1545 sensorButtons_[
i].get(j).setSelection(sensors_[
i].
get(j).selection_);
1549 for(
int j=0; j<sensors_[
type].size(); j++){
1550 sensorButtons_[
type].get(j).setText(sensors_[type].
get(j).name_+
" (id= "+sensors_[type].
get(j).id_+
")");
1551 sensorButtons_[
type].get(j).setSelection(sensors_[type].
get(j).selection_);
1559 for(
int i=0;
i<links_.size();
i++)
1560 if(links_.get(
i).isJoint())
1561 b = b && linkButtons_.get(
i).getSelection();
1563 allJointButton_.setSelection(
true);
1565 allJointButton_.setSelection(
false);
Link(String name, int jointId)
String getColumnText(Object element, int columnIndex)
static final String get(String key)
String [] getJointNames()
void addListener(ILabelProviderListener listener)
png_infop png_charp png_int_32 png_int_32 int * type
static NUMID_CODE numId(String type)
boolean loadRtcConf(String fileName)
void setRobot(GrxModelItem robot)
void updateButton(boolean isLink, int type)
#define null
our own NULL pointer
Vector< String > rtcConfFile_
Image getColumnImage(Object element, int columnIndex)
png_infop png_charpp name
void modify(Object element, String property, Object value)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
item corresponds to a robot model
boolean isLabelProperty(Object element, String property)
png_bytep png_bytep png_size_t length
static boolean isInport(String type)
IdCellDialog(Shell parentShell)
void updateControllerBridgeFile()
void configureShell(Shell newShell)
void saveButtonEnabled(boolean b)
void removeListener(ILabelProviderListener listener)
Control createDialogArea(Composite parent)
Object getValue(Object element, String property)
Vector< Outport > outport_
void buttonPressed(int buttonId)
static Shell getCurrentShell()
static Activator getDefault()
void buttonPressed(int buttonId)
Vector< String > controllerBridgeFile_
Control createDialogArea(Composite parent)
boolean canModify(Object element, String property)
void rtcConfInit(String host, String port)
Vector< GrxLinkItem > links_
String controllerRtcName_
String controllerPortName_
static String [] getNames()
void setControlTime(double time)
void createButtonsForButtonBar(Composite parent)
static void println(String s)
String [] getSensorNames(String type)
static boolean isOutport(String type)
boolean equals(Object object)
Font getFont(String fontName)
NameServer rtcNameServer_
IdData(String name, int id)
HashMap< String, String > connection_
void setControllerName(String _controllerName)
void updateAllJointButton()
boolean load(String fileName)
final String getName()
get name
Vector< Port > portTable_
static final String [] sensorType
boolean checkNameServer()
Label rtcConfFileNameLabel_
Label bridgeConfFileNameLabel_
StringBuffer bridgeConfFile_
void parse(String[] options)
void loadConfigFile(String fileName)
boolean setProjectControllerName(String _controllerName)
void updateBridgeConfFile()
String projectControllerName_