Commit 3fc67c4a authored by Jean Meurice's avatar Jean Meurice
Browse files

GUI Dev

parent 9317cf12
@REM
@REM
@REM ******************************************************************************
@REM MontiCAR Modeling Family, www.se-rwth.de
@REM Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
@REM All rights reserved.
@REM
@REM This project is free software; you can redistribute it and/or
@REM modify it under the terms of the GNU Lesser General Public
@REM License as published by the Free Software Foundation; either
@REM version 3.0 of the License, or (at your option) any later version.
@REM This library is distributed in the hope that it will be useful,
@REM but WITHOUT ANY WARRANTY; without even the implied warranty of
@REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@REM Lesser General Public License for more details.
@REM
@REM You should have received a copy of the GNU Lesser General Public
@REM License along with this project. If not, see <http://www.gnu.org/licenses/>.
@REM *******************************************************************************
@REM
pushd %~dp0
call mvn clean install -s "settings.xml" -DskipTests
cd target
ren "basic-simulator-*.jar" "basic-simulator.jar"
copy "basic-simulator.jar" "..\install"
popd
\ No newline at end of file
......@@ -5,21 +5,21 @@ Prev: [Scripts tutorial](docs/scripts.md)
# MontiSim overview
## Contents
- Project Structure
- Simulation project
- Vehicle
- Maps
- Simulator
- Autopilots
- RMIModelServer
- Basic Simulator
- Distributed System
- RPC
- Restful
*Comming Soon*
> - Project Structure
> - Simulation project
> - Vehicle
> - Maps
> - Simulator
> - Autopilots
> - RMIModelServer
> - Basic Simulator
> - Distributed System
> - RPC
> - Restful
---
......
......@@ -10,8 +10,8 @@
{
"name": "car1",
"physics_model": "modelica",
"start_coords": [5.88133850,50.8354390,0],
"target_coords": [5.8813333,50.8355156,0],
"start_coords": [50.8354390, 5.88133850,0],
"target_coords": [50.8355156, 5.8813333,0],
"autopilot": {
"autopilot": "AutopilotAdapter",
"os": "windows",
......
......@@ -144,12 +144,13 @@ public class BasicController implements SimulationLoopNotifiable, Runnable {
double[] position = vehicle.getPosition().toArray();
double longitude = position[0];
double latitude = position[1];
System.out.println("\tPosition of car: [" +latitude + ", " + longitude + "]");
VehicleBuilder.VehicleTrajectory traj = vehicleTrajectories.get(vehicle.getId());
double dist = traj.target.getDistance(vehicle.getPosition());
System.out.println("\tPosition of car: [" +latitude + ", " + longitude + "] (Dist to target: " + dist + ")");
//Temporary hack to stop simulation when vehicle attained its target
VehicleBuilder.VehicleTrajectory traj = vehicleTrajectories.get(vehicle.getId());
if (!traj.notified){
if (traj.target.getDistance(vehicle.getPosition()) < 1){
if (dist < 1){
System.out.println("\tCar at target");
simulator.setSimulationDuration(1000+simulator.getSimulationTime());
traj.notified = true;
......
......@@ -197,12 +197,8 @@ public class VehicleBuilder {
return result;
}
/*
TODO:
- Check if latitude/longitude are read in correct order
*/
private static RealVector jsonCoordToRealVector(JsonArray coords) throws Exception {
//Json coords as [Latitude, Longitude]
double[] res = new double[3];
int c = 0;
for (JsonValue val : coords){
......@@ -213,8 +209,8 @@ public class VehicleBuilder {
}
ApproximateConverter cvt = WorldModel.getInstance().getParser().getConverter().getApproximateConverter();
return new ArrayRealVector(new double[]{
cvt.convertLongToMeters(res[0], res[1]),
cvt.convertLatToMeters(res[1]),
cvt.convertLongToMeters(res[1], res[0]),
cvt.convertLatToMeters(res[0]),
0
}, false);
}
......
......@@ -12,6 +12,7 @@ public class FileSystem {
public interface DirectoryWatcher {
void add_item(String path, String name);
void remove_item(String path);
}
public static class DirInfo {
......@@ -66,6 +67,13 @@ public class FileSystem {
}
}
public void remove_file(DirectoryWatcher watcher, File file, String extension) {
if(file == null) return;
if (!file.isDirectory()){
watcher.remove_item(file.getPath());
}
}
public void check_updates(){
for (;;){
WatchKey key;
......@@ -89,6 +97,10 @@ public class FileSystem {
if (kind == ENTRY_CREATE) {
add_file(target.watcher, child.toFile(), target.extension);
} else if (kind == ENTRY_DELETE){
remove_file(target.watcher, child.toFile(), target.extension);
} else if (kind == ENTRY_MODIFY){
}
}
......
......@@ -9,13 +9,23 @@ import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.*;
import java.awt.*;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
public class Browser extends JFrame implements TreeSelectionListener {
protected static class BrowserTree extends JTree {
public BrowserTree(TreeModel model){
super(model);
}
public void expand(TreePath path) {
setExpandedState(path, true);
}
}
JPanel cards;
CardLayout cl;
JTree tree;
BrowserTree tree;
DefaultMutableTreeNode tree_root;
DefaultTreeModel tree_model;
Category default_category;
......@@ -50,7 +60,7 @@ public class Browser extends JFrame implements TreeSelectionListener {
tree_root = new DefaultMutableTreeNode("Categories");
tree_model = new DefaultTreeModel(tree_root);
tree = new JTree(tree_model);
tree = new BrowserTree(tree_model);
tree.setRootVisible(false);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(this);
......@@ -68,13 +78,23 @@ public class Browser extends JFrame implements TreeSelectionListener {
tree_model.reload();
expand_all();
browser.setMinimumSize(new Dimension(300, 200));
browser.setViewportView(tree);
getContentPane().add(BorderLayout.LINE_START, browser);
setVisible(true); //making the frame visible
}
public void expand_all(){
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
}
private Category new_category(Category.CategoryType type, SimVis vis) throws IOException {
return new Category(type, vis, this, file_system);
}
......@@ -94,9 +114,28 @@ public class Browser extends JFrame implements TreeSelectionListener {
//https://stackoverflow.com/questions/23804675/list-files-and-directories-with-jtree-and-file-in-java
public void add_item(Category category, Category.Elem elem){
DefaultMutableTreeNode node = new DefaultMutableTreeNode(elem);
tree_model.insertNodeInto(node, categories.get(category.getType().id), 0);
tree.expandPath(new TreePath(node.getPath()));
DefaultMutableTreeNode par = categories.get(category.getType().id);
tree_model.insertNodeInto(node, par, 0);
tree_model.reload();
expand_all();
}
public void remove_item(Category category, String id){
DefaultMutableTreeNode cat_node = categories.get(category.getType().id);
Enumeration<TreeNode> children = cat_node.children();
DefaultMutableTreeNode node = null;
while (children.hasMoreElements()){
DefaultMutableTreeNode t = (DefaultMutableTreeNode)children.nextElement();
Category.Elem e = (Category.Elem) t.getUserObject();
if (e.id.equals(id)){
node = t;
break;
}
}
if (node == null) return;
tree_model.removeNodeFromParent(node);
tree_model.reload();
expand_all();
}
......@@ -117,32 +156,30 @@ public class Browser extends JFrame implements TreeSelectionListener {
categories.put(type.id, node);
}
public void showVis(SimVis new_vis, Category.Elem new_elem){
public void show_vis(SimVis new_vis, Category.Elem new_elem){
new_vis.select(new_elem);
if (new_vis != current_vis){
current_vis = new_vis;
cl.show(cards, new_vis.getId());
new_vis.select(new_elem);
}
}
public void valueChanged(TreeSelectionEvent e) {
//Returns the last path element of the selection.
//This method is useful only when the selection model allows a single selection.
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
SimVis new_vis = default_category.getVis();
Category.Elem new_elem = null;
if (node != null){
//Is it a valid selection?
if (node.getParent() != tree_root && node.isLeaf()) {
//Get category
TreeNode par;
TreeNode grt_par;
do {
par = node.getParent();
grt_par = par.getParent();
} while(grt_par != tree_root);
TreeNode par = node.getParent();
TreeNode grt_par = par.getParent();
while(grt_par != tree_root) {
TreeNode temp = grt_par;
grt_par = grt_par.getParent();
par = temp;
}
DefaultMutableTreeNode category_node = (DefaultMutableTreeNode) par;
Category category = node_category.get(category_node);
if (category != null){
......@@ -154,7 +191,6 @@ public class Browser extends JFrame implements TreeSelectionListener {
}
}
}
showVis(new_vis, new_elem);
show_vis(new_vis, new_elem);
}
}
......@@ -74,4 +74,10 @@ public class Category implements FileSystem.DirectoryWatcher {
elems.add(path);
browser.add_item(this, elem);
}
@Override
public void remove_item(String path){
elems.remove(path);
browser.remove_item(this, path);
}
}
......@@ -4,9 +4,16 @@ import javax.swing.*;
public class DefaultVis extends SimVis {
public DefaultVis(){
JButton b=new JButton("click");
b.setBounds(130,100,100, 40);
add(b);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
add_text("Select one of the scenarios to start a simulation.");
add_text("Visualize the available maps. (Coming)");
add_text("Watch completed simulations in the results. (Coming)");
}
private void add_text(String text){
JLabel t = new JLabel(text);
add(t);
}
@Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment