package gui.dialogs;
import gui.EasyBotApp;
import gui.EasyBotAppException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Vector;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import resources.SWTResourceManager;
import resources.digesters.ClassManager;
import resources.digesters.Plugin;
import utils.ErrorMessage;
import utils.defines.Defines;
import utils.logging.Logger;
import components.gps.GPSGUI;
import components.gps.imagebased.ImageBasedGPS;
import components.robot.Robot;
import core.simulation.Simulation;
/**
* <code>NewSimulationDialog</code> implementa el di�logo para la creaci�n de una
* nueva simulaci�n.
*/
public class NewSimulationDialog extends Dialog
{
// TODO: renombrar los atributos, usando nombres representativos
private Shell dialogShell;
private Composite composite1;
private Label label2;
private ToolItem agregarRobot;
private ToolItem eliminarRobot;
private ToolItem calibrarRobot;
private ToolItem configRobot;
private ToolItem copyRobot;
private Composite listadoRobots;
private ToolBar toolBarRobot;
private Composite barraRobots;
private Composite colDer2;
private Composite notas;
private TableColumn fileNameColumn;
private Composite webcamConfig;
private Label label7;
private CLabel tituloGPS;
private CCombo gpsComboType;
private Label tipoGps;
private Composite composite2;
private Button exploreFiles;
private Label label5;
private CCombo simulationTypeCombo;
private Button ok;
private Button aplicar;
private Composite footer;
private Label label4;
private Text comentario;
private Label label3;
private Composite colDer1;
private Text path;
private Text editNombre;
private Label destino;
private Label nombre;
private Composite colDer;
private Composite colIzq;
private CTabItem gps;
private TableColumn estado;
private TableColumn id;
private CTabItem cTabItem1;
private CTabFolder cTabFolder1;
private Composite lenguetas;
private Table listaRobots;
private Label label1;
private CLabel cTitle;
private DirectoryDialog directoryDialog;
private FileDialog fileDialog;
private EasyBotApp parentComposite;
private HashMap gpsHash;
private boolean allOk;
public NewSimulationDialog(Shell parent, int style, EasyBotApp parentComposite)
{
super(parent, style);
allOk = false;
this.parentComposite = parentComposite;
this.directoryDialog = new DirectoryDialog(parent, SWT.APPLICATION_MODAL);
this.fileDialog = new FileDialog(parent, SWT.OPEN);
gpsHash = new HashMap();
fileDialog.setFilterNames(new String[] {"*.jpg","*.gif","*.png"});
//Simulation.getCurrent().setPlaybackSimualtion(false);
}
public void open()
{
try
{
Shell parent = getParent();
dialogShell = new Shell(parent, SWT.DIALOG_TRIM |
SWT.APPLICATION_MODAL );
{
//Register as a resource user - SWTResourceManager will
//handle the obtaining and disposing of resources
SWTResourceManager.registerResourceUser( dialogShell );
}
GridLayout dialogShellLayout = new GridLayout();
dialogShell.setLayout(dialogShellLayout);
dialogShellLayout.horizontalSpacing = 0;
dialogShellLayout.marginHeight = 0;
dialogShellLayout.marginWidth = 0;
dialogShellLayout.verticalSpacing = 0;
dialogShell.setText("Nueva Simulaci�n");
dialogShell.setImage(SWTResourceManager.getImage("resources/icons/icon24x24/enable/film.png"));
dialogShell.layout();
dialogShell.pack();
dialogShell.setSize(708, 620);
dialogShell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent evt) {
rootWidgetDisposed(evt);
}
});
{
composite1 = new Composite(dialogShell, SWT.NONE);
GridLayout composite1Layout = new GridLayout();
composite1Layout.horizontalSpacing = 0;
composite1Layout.marginHeight = 0;
composite1Layout.marginWidth = 0;
composite1Layout.numColumns = 2;
composite1Layout.verticalSpacing = 0;
GridData composite1LData = new GridData();
composite1LData.grabExcessHorizontalSpace = true;
composite1LData.horizontalAlignment = GridData.FILL;
composite1LData.verticalAlignment = GridData.FILL;
composite1.setLayoutData(composite1LData);
composite1.setLayout(composite1Layout);
{
cTitle = new CLabel(composite1, SWT.NONE);
cTitle.setText("Nueva Simulaci�n");
GridData cTitleLData = new GridData();
cTitleLData.horizontalSpan = 3;
cTitleLData.grabExcessHorizontalSpace = true;
cTitleLData.horizontalAlignment = GridData.FILL;
cTitle.setLayoutData(cTitleLData);
cTitle.setImage(SWTResourceManager.getImage("resources/icons/icon32x32/enable/Toolbar-_-Movies32x32.png"));
cTitle.setFont(SWTResourceManager.getFont("Tahoma", 9, 1, false, false));
cTitle.setForeground(SWTResourceManager.getColor(91, 91, 91));
}
{
label1 = new Label(composite1, SWT.SEPARATOR
| SWT.HORIZONTAL);
GridData label1LData = new GridData();
label1LData.grabExcessHorizontalSpace = true;
label1LData.horizontalAlignment = GridData.FILL;
label1LData.horizontalSpan = 3;
label1.setLayoutData(label1LData);
label1.setText("label1");
}
{
colIzq = new Composite(composite1, SWT.NONE);
GridLayout colIzqLayout = new GridLayout();
colIzqLayout.makeColumnsEqualWidth = true;
colIzqLayout.marginTop = 5;
GridData colIzqLData = new GridData();
colIzqLData.horizontalAlignment = GridData.FILL;
colIzqLData.verticalAlignment = GridData.FILL;
colIzqLData.grabExcessVerticalSpace = true;
colIzq.setLayoutData(colIzqLData);
colIzq.setLayout(colIzqLayout);
{
nombre = new Label(colIzq, SWT.NONE);
GridData NombreLData = new GridData();
NombreLData.horizontalAlignment = GridData.END;
NombreLData.grabExcessHorizontalSpace = true;
NombreLData.heightHint = 17;
nombre.setLayoutData(NombreLData);
nombre.setText("Nombre:");
nombre.setFont(SWTResourceManager.getFont("Tahoma", 8, 1, false, false));
}
{
destino = new Label(colIzq, SWT.NONE);
GridData DestinoLData = new GridData();
DestinoLData.grabExcessHorizontalSpace = true;
DestinoLData.horizontalAlignment = GridData.END;
DestinoLData.heightHint = 17;
destino.setLayoutData(DestinoLData);
destino.setText("Destino:");
destino.setFont(SWTResourceManager.getFont("Tahoma", 8, 1, false, false));
}
{
label5 = new Label(colIzq, SWT.NONE);
GridData label5LData = new GridData();
label5LData.horizontalAlignment = GridData.END;
label5LData.heightHint = 17;
label5.setLayoutData(label5LData);
label5.setText("Tipo de Simulaci�n:");
label5.setFont(SWTResourceManager.getFont("Tahoma", 8, 1, false, false));
}
}
{
colDer = new Composite(composite1, SWT.NONE);
GridLayout colDerLayout = new GridLayout();
colDerLayout.numColumns = 2;
colDerLayout.makeColumnsEqualWidth = true;
GridData colDerLData = new GridData();
colDerLData.grabExcessHorizontalSpace = true;
colDerLData.horizontalAlignment = GridData.FILL;
colDerLData.heightHint = 117;
colDerLData.grabExcessVerticalSpace = true;
colDer.setLayoutData(colDerLData);
colDer.setLayout(colDerLayout);
{
colDer1 = new Composite(colDer, SWT.NONE);
GridLayout colDer1Layout = new GridLayout();
colDer1Layout.makeColumnsEqualWidth = true;
GridData colDer1LData = new GridData();
colDer1LData.horizontalAlignment = GridData.FILL;
colDer1LData.grabExcessVerticalSpace = true;
colDer1LData.verticalAlignment = GridData.FILL;
colDer1.setLayoutData(colDer1LData);
colDer1.setLayout(colDer1Layout);
{
editNombre = new Text(colDer1, SWT.NONE);
editNombre.setText("Introduzca Nombre...");
GridData editNombreLData = new GridData();
editNombreLData.widthHint = 150;
editNombreLData.heightHint = 17;
editNombre.setLayoutData(editNombreLData);
}
{
path = new Text(colDer1, SWT.NONE);
GridData pathLData = new GridData();
pathLData.heightHint = 17;
pathLData.grabExcessHorizontalSpace = true;
pathLData.horizontalAlignment = GridData.FILL;
path.setLayoutData(pathLData);
}
{
simulationTypeCombo = new CCombo(colDer1, SWT.NONE);
GridData cCombo1LData = new GridData();
cCombo1LData.widthHint = 69;
cCombo1LData.heightHint = 17;
simulationTypeCombo.setLayoutData(cCombo1LData);
simulationTypeCombo.setItems(new String[] {Defines.VIRTUAL_SIMULATION_TEXT, Defines.REAL_SIMULATION_TEXT});
simulationTypeCombo.setLayoutDeferred(true);
simulationTypeCombo.setVisibleItemCount(3);
simulationTypeCombo.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
simulationTypeCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
try
{
simulationTypeComboWidgetSelected(evt);
}
catch (EasyBotAppException e)
{
ErrorMessage.customMessage(e.getMessage(), ErrorMessage.ERROR_MESSAGE, getParent() );
}
}
});
}
}
{
colDer2 = new Composite(colDer, SWT.NONE);
FormLayout colDer2Layout = new FormLayout();
GridData colDer2LData = new GridData();
colDer2LData.verticalAlignment = GridData.FILL;
colDer2LData.grabExcessHorizontalSpace = true;
colDer2.setLayoutData(colDer2LData);
colDer2.setLayout(colDer2Layout);
{
exploreFiles = new Button(colDer2, SWT.PUSH | SWT.CENTER);
exploreFiles.setText("Explorar");
FormData button1LData = new FormData();
button1LData.width = 80;
button1LData.height = 21;
button1LData.right = new FormAttachment(312, 1000, 0);
button1LData.left = new FormAttachment(13, 1000, 0);
button1LData.bottom = new FormAttachment(1000, 1000, -65);
button1LData.top = new FormAttachment(236, 1000, 0);
exploreFiles.setLayoutData(button1LData);
exploreFiles
.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
exploreFilesWidgetSelected(evt);
}
});
}
/*{
browseButton = new Button(colDer2, SWT.PUSH
| SWT.CENTER);
FormData browseButtonLData = new FormData();
browseButtonLData.width = 80;
browseButtonLData.height = 21;
browseButtonLData.right = new FormAttachment(311, 1000, 0);
browseButtonLData.left = new FormAttachment(13, 1000, 0);
browseButtonLData.bottom = new FormAttachment(1004, 1000, 0);
browseButtonLData.top = new FormAttachment(816, 1000, 0);
browseButton.setLayoutData(browseButtonLData);
browseButton.setText("Explorar");
browseButton.setVisible(false);
browseButton
.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(
SelectionEvent evt) {
browseButtonWidgetSelected(evt);
}
});
}*/
}
}
{
label2 = new Label(composite1, SWT.SEPARATOR
| SWT.HORIZONTAL);
GridData label2LData = new GridData();
label2LData.grabExcessHorizontalSpace = true;
label2LData.horizontalAlignment = GridData.FILL;
label2LData.horizontalSpan = 2;
label2LData.grabExcessVerticalSpace = true;
label2.setLayoutData(label2LData);
label2.setText("label2");
}
{
notas = new Composite(composite1, SWT.NONE);
GridLayout notasLayout = new GridLayout();
notasLayout.makeColumnsEqualWidth = true;
GridData notasLData = new GridData();
notasLData.grabExcessHorizontalSpace = true;
notasLData.horizontalAlignment = GridData.FILL;
notasLData.horizontalSpan = 2;
notas.setLayoutData(notasLData);
notas.setLayout(notasLayout);
{
label4 = new Label(notas, SWT.NONE);
label4.setText("Comentario:");
}
{
comentario = new Text(notas, SWT.MULTI | SWT.WRAP);
GridData ComentarioLData = new GridData();
ComentarioLData.grabExcessHorizontalSpace = true;
ComentarioLData.horizontalAlignment = GridData.CENTER;
ComentarioLData.widthHint = 541;
ComentarioLData.heightHint = 71;
comentario.setLayoutData(ComentarioLData);
comentario.setText("...");
comentario.setToolTipText("Comentario de la Simulaci�n");
}
}
{
label3 = new Label(composite1, SWT.SEPARATOR
| SWT.HORIZONTAL);
GridData label3LData = new GridData();
label3LData.grabExcessHorizontalSpace = true;
label3LData.horizontalAlignment = GridData.FILL;
label3LData.horizontalSpan = 2;
label3.setLayoutData(label3LData);
label3.setText("label3");
}
{
lenguetas = new Composite(composite1, SWT.EMBEDDED);
GridLayout lenguetasLayout = new GridLayout();
lenguetasLayout.verticalSpacing = 0;
lenguetasLayout.horizontalSpacing = 0;
lenguetasLayout.marginHeight = 0;
lenguetasLayout.marginWidth = 0;
GridData lenguetasLData = new GridData();
lenguetasLData.horizontalSpan = 2;
lenguetasLData.horizontalAlignment = GridData.FILL;
lenguetasLData.verticalAlignment = GridData.BEGINNING;
lenguetasLData.grabExcessHorizontalSpace = true;
lenguetasLData.heightHint = 249;
lenguetas.setLayoutData(lenguetasLData);
lenguetas.setLayout(lenguetasLayout);
lenguetas.setEnabled(false);
{
cTabFolder1 = new CTabFolder(lenguetas, SWT.NONE);
cTabFolder1.addSelectionListener(new SelectionListener(){
public void widgetSelected(SelectionEvent arg0) {
fillTable();
}
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
});
{
cTabItem1 = new CTabItem(cTabFolder1, SWT.NONE);
cTabItem1.setText("Robots");
{
listadoRobots = new Composite(
cTabFolder1,
SWT.NONE);
GridLayout listadoRobotsLayout = new GridLayout();
listadoRobotsLayout.makeColumnsEqualWidth = true;
listadoRobotsLayout.marginWidth = 0;
listadoRobotsLayout.marginHeight = 0;
listadoRobotsLayout.horizontalSpacing = 0;
listadoRobotsLayout.verticalSpacing = 0;
listadoRobots.setLayout(listadoRobotsLayout);
cTabItem1.setControl(listadoRobots);
{
barraRobots = new Composite(
listadoRobots,
SWT.NONE);
RowLayout barraRobotsLayout = new RowLayout(
org.eclipse.swt.SWT.HORIZONTAL);
GridData barraRobotsLData = new GridData();
barraRobotsLData.grabExcessHorizontalSpace = true;
barraRobotsLData.horizontalAlignment = GridData.FILL;
barraRobots.setLayoutData(barraRobotsLData);
barraRobots.setLayout(barraRobotsLayout);
{
RowData toolBarRobotLData = new RowData();
toolBarRobot = new ToolBar(
barraRobots,
SWT.FLAT);
toolBarRobot
.setLayoutData(toolBarRobotLData);
{
agregarRobot = new ToolItem(
toolBarRobot,
SWT.NONE);
agregarRobot
.setImage(SWTResourceManager
.getImage("resources/icons/icon24x24/enable/AIBO210-add.png"));
agregarRobot
.setToolTipText("Agregar robot");
agregarRobot.setEnabled(false);
agregarRobot
.setDisabledImage(SWTResourceManager
.getImage("resources/icons/icon24x24/disable/AIBO210-add-des.png"));
agregarRobot
.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(
SelectionEvent evt) {
addRobotWidgetSelected(evt);
}
});
}
{
eliminarRobot = new ToolItem(
toolBarRobot,
SWT.NONE);
eliminarRobot
.setToolTipText("Eliminar robot");
eliminarRobot
.setImage(SWTResourceManager
.getImage("resources/icons/icon24x24/enable/AIBO210-rem.png"));
eliminarRobot.setEnabled(false);
eliminarRobot
.setDisabledImage(SWTResourceManager
.getImage("resources/icons/icon24x24/disable/AIBO210-rem-des.png"));
eliminarRobot
.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(
SelectionEvent evt) {
remRobotWidgetSelected(evt);
}
});
}
{
copyRobot = new ToolItem(
toolBarRobot,
SWT.NONE);
copyRobot
.setToolTipText("Copiar robot");
copyRobot
.setImage(SWTResourceManager
.getImage("resources/icons/icon24x24/enable/AIBO210-copy.png"));
copyRobot.setEnabled(false);
copyRobot
.setDisabledImage(SWTResourceManager
.getImage("resources/icons/icon24x24/disable/AIBO210-copy-des.png"));
}
{
configRobot = new ToolItem(
toolBarRobot,
SWT.NONE);
configRobot
.setToolTipText("Propiedades del robot");
configRobot
.setImage(SWTResourceManager
.getImage("resources/icons/icon24x24/enable/Toolbar-_Applications.png"));
configRobot.setEnabled(false);
configRobot
.setDisabledImage(SWTResourceManager
.getImage("resources/icons/icon24x24/disable/Toolbar-_Applications-des.png"));
}
{
calibrarRobot = new ToolItem(
toolBarRobot,
SWT.NONE);
calibrarRobot
.setToolTipText("Calibrar robot");
calibrarRobot
.setImage(SWTResourceManager
.getImage("resources/icons/icon24x24/enable/System-ColorSync.png"));
calibrarRobot.setEnabled(false);
calibrarRobot
.setDisabledImage(SWTResourceManager
.getImage("resources/icons/icon24x24/disable/System-ColorSync-des.png"));
}
}
}
{
listaRobots = new Table(
listadoRobots,
SWT.SINGLE | SWT.FULL_SELECTION);
listaRobots.setHeaderVisible(true);
listaRobots.setLayoutDeferred(true);
GridData listaRobotsLData = new GridData();
listaRobotsLData.grabExcessHorizontalSpace = true;
listaRobotsLData.verticalAlignment = GridData.BEGINNING;
listaRobotsLData.heightHint = 143;
listaRobotsLData.horizontalAlignment = GridData.FILL;
listaRobots.setLayoutData(listaRobotsLData);
listaRobots.setLinesVisible(true);
listaRobots
.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(
MouseEvent evt) {
listaRobotsMouseDoubleClick(evt);
}
});
listaRobots
.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(
SelectionEvent evt) {
listaRobotsWidgetSelected(evt);
}
});
{
id = new TableColumn(
listaRobots,
SWT.NONE);
id.setText("Nombre");
id.setWidth(232);
}
{
estado = new TableColumn(
listaRobots,
SWT.CENTER);
estado.setText("Estado");
estado.setWidth(161);
}
{
fileNameColumn = new TableColumn(
listaRobots,
SWT.CENTER);
fileNameColumn
.setText("Archivo de Configuraci�n");
fileNameColumn.setWidth(280);
}
}
}
}
{
gps = new CTabItem(cTabFolder1, SWT.NONE);
gps.setText("Posicionamiento");
{
composite2 = new Composite(
cTabFolder1,
SWT.NONE);
GridLayout composite2Layout = new GridLayout();
composite2Layout.marginHeight = 0;
composite2Layout.numColumns = 2;
composite2Layout.marginTop = 7;
composite2Layout.marginWidth = 7;
composite2.setLayout(composite2Layout);
gps.setControl(composite2);
{
tituloGPS = new CLabel(composite2, SWT.NONE);
GridData tituloGPSLData = new GridData();
tituloGPSLData.horizontalSpan = 3;
tituloGPSLData.horizontalAlignment = GridData.FILL;
tituloGPS.setLayoutData(tituloGPSLData);
tituloGPS
.setText("Configuraci�n Sistema de Posicionamiento Global");
tituloGPS
.setImage(SWTResourceManager
.getImage("resources/icons/icon32x32/enable/Webcam Configuration.png"));
}
{
label7 = new Label(
composite2,
SWT.SEPARATOR | SWT.HORIZONTAL);
label7.setText("label7");
GridData label7LData = new GridData();
label7LData.grabExcessHorizontalSpace = true;
label7LData.horizontalSpan = 3;
label7LData.horizontalAlignment = GridData.FILL;
label7.setLayoutData(label7LData);
}
{
tipoGps = new Label(composite2, SWT.NONE);
tipoGps
.setText("Sistema de Posisionamiento");
}
{
gpsComboType = new CCombo(
composite2,
SWT.NONE);
GridData tipoGpsComboLData = new GridData();
tipoGpsComboLData.widthHint = 159;
tipoGpsComboLData.heightHint = 17;
gpsComboType
.setLayoutData(tipoGpsComboLData);
gpsComboType.setVisibleItemCount(3);
gpsComboType
.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(
SelectionEvent evt) {
tipoGpsComboWidgetSelected(evt);
}
});
}
{
webcamConfig = new Composite(
composite2,
SWT.NONE);
}
}
}
GridData cTabFolder1LData = new GridData();
cTabFolder1LData.grabExcessHorizontalSpace = true;
cTabFolder1LData.horizontalAlignment = GridData.FILL;
cTabFolder1LData.verticalAlignment = GridData.FILL;
cTabFolder1LData.verticalIndent = 3;
cTabFolder1LData.grabExcessVerticalSpace = true;
cTabFolder1.setLayoutData(cTabFolder1LData);
cTabFolder1.setSelection(0);
}
}
}
{
footer = new Composite(dialogShell, SWT.NONE);
GridLayout footerLayout = new GridLayout();
footerLayout.makeColumnsEqualWidth = true;
footerLayout.numColumns = 2;
GridData footerLData = new GridData();
footerLData.horizontalSpan = 2;
footerLData.widthHint = 149;
footerLData.heightHint = 52;
footerLData.grabExcessHorizontalSpace = true;
footerLData.horizontalAlignment = GridData.END;
footer.setLayoutData(footerLData);
footer.setLayout(footerLayout);
{
aplicar = new Button(footer, SWT.PUSH | SWT.CENTER);
GridData AplicarLData = new GridData();
AplicarLData.widthHint = 60;
AplicarLData.heightHint = 23;
aplicar.setLayoutData(AplicarLData);
aplicar.setText("Aplicar");
aplicar.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
AplicarWidgetSelected(evt);
}
});
}
{
ok = new Button(footer, SWT.PUSH | SWT.CENTER);
GridData okLData = new GridData();
okLData.widthHint = 60;
okLData.heightHint = 23;
ok.setLayoutData(okLData);
ok.setText("OK");
ok.setEnabled(false);
ok.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
okWidgetSelected(evt);
}
});
}
}
// Se crea una simulaci�n vac�a que se ir� llenando.
Simulation newSim = new Simulation();
if ( newSim != null )
newSim.setPlaybackSimualtion( false );
else
Logger.error( "No pude instanciarse la nueva simulaci�n" );
composite1.layout(true);
dialogShell.open();
Display display = dialogShell.getDisplay();
while (!dialogShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
catch (Exception e)
{
Logger.error(e.getMessage());
// TODO: qu� hacer ???
}
}
private void simulationTypeComboWidgetSelected(SelectionEvent evt) throws EasyBotAppException
{
if ( (listaRobots.getItems().length > 0 || gpsComboType.getText().length()>0) && ErrorMessage.warningYesNoMessage(Defines.WARNING_CHANGE_SIMULATION_TYPE,((CCombo)evt.getSource()).getParent()) == SWT.NO )
return;
if ( ((CCombo)evt.getSource()).getText().equalsIgnoreCase("Virtual") )
Simulation.getCurrent().setType( Defines.VIRTUAL_SIMULATION );
else
Simulation.getCurrent().setType( Defines.REAL_SIMULATION );
lenguetas.setEnabled(true);
enableAddRobotButton();
Simulation.getCurrent().setGps(null);
Simulation.getCurrent().removeAllRobots();
fillTable();
fillGPSCombo();
}
private void enableAddRobotButton()
{
if ((path.getText().length() > 0) && (simulationTypeCombo.getText().length() > 0) && (Simulation.getCurrent().getType() != Defines.VIRTUAL_SIMULATION))
{
agregarRobot.setEnabled(true);
}
else if ((path.getText().length() > 0)
&& (simulationTypeCombo.getText().length() > 0)
&& (Simulation.getCurrent().getType() == Defines.VIRTUAL_SIMULATION)
//&& (sceneFile.getText().length()>0)
)
{
agregarRobot.setEnabled(true);
}
else
{
agregarRobot.setEnabled(false);
}
}
private void fillGPSCombo() throws EasyBotAppException
{
Vector gps = ClassManager.getInstance().searchClass(Defines.COMPONENT_GPS , Simulation.getCurrent().getType());
gpsComboType.removeAll();
if (!webcamConfig.isDisposed())
webcamConfig.dispose();
composite2.layout(true);
if (gps != null)
for (int i=0 ; i<gps.size(); i++)
{
gpsComboType.add(((Plugin) gps.get(i)).getPluginDescription());
gpsHash.put(((Plugin) gps.get(i)).getPluginDescription(),((Plugin) gps.get(i)).getName());
}
}
private void exploreFilesWidgetSelected(SelectionEvent evt)
{
String pathName = directoryDialog.open();
path.setText(pathName!=null?pathName:"");
if (path.getText().length() > 0)
Simulation.getCurrent().setBaseSimulationDirectory(path.getText());
enableAddRobotButton();
}
private void okWidgetSelected(SelectionEvent evt)
{
try
{
File baseDir = new File( Simulation.getCurrent().getBaseSimulationDirectory() );
File simFile = new File( Simulation.getCurrent().getBaseSimulationDirectory() + "/simulation.xml" );
if ( ( !baseDir.isDirectory() && ErrorMessage.errorMessage(Defines.ERROR_BASEDIRECTORY_DONOT_EXISTS, getParent()) != SWT.OK )
|| !simFile.isFile()
|| (simFile.isFile() && ErrorMessage.warningYesNoMessage(Defines.WARNING_DIRECTORY_USED_BY_SIMULATION, getParent()) == SWT.YES )
)
{
// Primero se borra el contenido del directorio base
// (por si conten�a una simulaci�n previa).
//FileUtils.cleanDirectory( baseDir );
File dir = new File( Simulation.getCurrent().getBaseSimulationDirectory() + "/components/" );
dir.mkdir();
dir = new File( Simulation.getCurrent().getBaseSimulationDirectory() + "/traces/" );
dir.mkdir();
//Simulation.getCurrent().saveSimulationConfig();
for (int i=0; i<Simulation.getCurrent().getRobotArray().size();i++)
{
String file =((Robot)Simulation.getCurrent().getRobotArray().get(i)).getXMLConfigFile();
PrintWriter xmlFile = new PrintWriter(new FileOutputStream(Simulation.getCurrent().getBaseSimulationDirectory()+ "/components/" + file));
xmlFile.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
xmlFile.println(((Robot)Simulation.getCurrent().getRobotArray().get(i)).getXMLConfig(""));
xmlFile.close();
}
PrintWriter gpsXmlFile = new PrintWriter(new FileOutputStream(Simulation.getCurrent().getBaseSimulationDirectory()+ "/components/" + "gps.xml"));
gpsXmlFile.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
gpsXmlFile.println(Simulation.getCurrent().getGps().getXMLConfig(""));
gpsXmlFile.close();
}
else
{
path.selectAll();
path.setFocus();
ok.setEnabled(false);
aplicar.setEnabled(true);
return;
}
}
catch(Exception e)
{
ErrorMessage.customMessage( e.getMessage(), ErrorMessage.ERROR_MESSAGE, getParent());
}
parentComposite.drawMazeImage();
Simulation.getCurrent().setAllOk(true);
dialogShell.close();
}
private void addRobotWidgetSelected(SelectionEvent evt)
{
// Se crea un nuevo robot, y se lo agrega a la simulaci�n.
if ( !(Simulation.getCurrent().getRobotArray().size() < Defines.MAX_VIRTUAL_ROBOTS) )
{
ErrorMessage.infoMessage(Defines.INFO_MAX_VIRTUAL_ROBOTS, dialogShell.getShell());
return;
}
AddRobot addRobotDialog = new AddRobot(dialogShell.getShell(),SWT.NONE);
addRobotDialog.open();
fillTable();
}
private void fillTable()
{
listaRobots.removeAll();
Vector robots = Simulation.getCurrent().getRobotArray();
for (int i=0;i<robots.size();i++)
{
TableItem item = new TableItem(listaRobots,SWT.NONE);
Robot lastRobot = (Robot)robots.get(i);
item.setText(0,lastRobot.getName());
item.setText(1,lastRobot.getStatusText());
if (lastRobot.getStatus() == Defines.STATE_ROBOT_CALIBRATED)
item.setImage(1,SWTResourceManager
.getImage("resources/icons/icon16x16/enable/Symbol check 2.png"));
else
item.setImage(1,SWTResourceManager
.getImage("resources/icons/icon16x16/enable/Symbol error.png"));
item.setText(2,Simulation.getCurrent().getBaseSimulationDirectory() + "/robots/" +lastRobot.getXMLConfigFile());
}
}
private void tipoGpsComboWidgetSelected(SelectionEvent evt)
{
try
{
Plugin selectedGPS = ClassManager.getInstance().getPluginByName((String)gpsHash.get(((CCombo)evt.getSource()).getText()));
if (selectedGPS != null)
{
if (!webcamConfig.isDisposed())
webcamConfig.dispose();
ImageBasedGPS gps = (ImageBasedGPS) selectedGPS.makeIntance();
Simulation.getCurrent().setGps(gps);
GPSGUI gpsGUI = (GPSGUI) selectedGPS.makeGUInstance(gps);
webcamConfig = gpsGUI.getConfigPannel(composite2, composite2.getStyle());
GridData webcamConfigLData = new GridData();
webcamConfigLData.horizontalAlignment = GridData.FILL;
webcamConfigLData.verticalAlignment = GridData.BEGINNING;
webcamConfigLData.grabExcessVerticalSpace=true;
webcamConfigLData.horizontalSpan = 2;
webcamConfig.setLayoutData(webcamConfigLData);
composite2.layout(true);
}
}
catch (Exception e)
{
ErrorMessage.customMessage( e.getMessage(), ErrorMessage.ERROR_MESSAGE, getParent());
}
}
private void AplicarWidgetSelected(SelectionEvent evt)
{
//TODO: Verificar todos las configuaraciones sean correctas y que no
// falte nada
String errorString= new String();
Simulation.getCurrent().setName(editNombre.getText());
Simulation.getCurrent().setComment(comentario.getText());
//Se controla que los robots esten calibrados
Vector robots = Simulation.getCurrent().getRobotArray();
for (int i=0;i<robots.size();i++)
{
if (((Robot)robots.get(i)).getStatus() != Defines.STATE_ROBOT_CALIBRATED)
errorString = errorString.concat("El robot " + ((Robot)robots.get(i)).getName() + " debe ser calibrado.\n");
}
if (Simulation.getCurrent().getGps() == null)
errorString = errorString.concat("Debe elegir un Sistema de Posicionamiento Global.");
if (Simulation.getCurrent().getGps() != null && Simulation.getCurrent().getGps().isCalibrated()== false)
errorString = errorString.concat("El Sistema de Posicionamiento Global no ha sido calibrado correctamente.\n");
if ( simulationTypeCombo.getText().compareTo(Defines.REAL_SIMULATION_TEXT)==0)
{
Simulation.getCurrent().setType(Defines.REAL_SIMULATION);
Simulation.getCurrent().setStepTime( Defines.REAL_SIMULATION_STEP_TIME );
}
else if (simulationTypeCombo.getText().compareTo(Defines.VIRTUAL_SIMULATION_TEXT)==0)
{
Simulation.getCurrent().setType(Defines.VIRTUAL_SIMULATION);
}
else if (simulationTypeCombo.getText().compareTo(Defines.MIXED_SIMULATION_TEXT)==0)
{
Simulation.getCurrent().setType(Defines.MIXED_SIMULATION);
}
Simulation.getCurrent().setBaseSimulationDirectory( path.getText() != null ? path.getText() : "");
if ( path.getText().length() <= 0)
errorString = errorString.concat("Debe especificar una ruta para la simulaci�n.\n");
if (errorString.length() == 0)
{
allOk = true;
aplicar.setEnabled(false);
ok.setEnabled(true);
}
else
ErrorMessage.customMessage(errorString,ErrorMessage.ERROR_MESSAGE,getParent());
}
private void listaRobotsWidgetSelected(SelectionEvent evt)
{
eliminarRobot.setEnabled(true);
//copyRobot.setEnabled(true);
}
private void remRobotWidgetSelected(SelectionEvent evt)
{
//Robot robot = Simulation.getCurrent().searchRobotByName(listaRobots.getSelection()[0].getText());
Robot robot = Simulation.getCurrent().getRobotByName( listaRobots.getSelection()[0].getText() );
if (robot != null)
{
Simulation.getCurrent().removeRobot(robot);
listaRobots.remove(listaRobots.getSelectionIndex());
}
}
private void listaRobotsMouseDoubleClick(MouseEvent evt)
{
Robot robot = Simulation.getCurrent().getRobotByName( listaRobots.getSelection()[0].getText() );
if (robot != null)
{
RobotConfigDialog robotDlg = new RobotConfigDialog(dialogShell.getShell(),SWT.NONE,robot);
robotDlg.open();
fillTable();
}
}
private void rootWidgetDisposed(DisposeEvent evt)
{
if (allOk == false)
Simulation.getCurrent().unLoad();
}
}