From 9335b9cff8939b28168f9854720d165d75e65c94 Mon Sep 17 00:00:00 2001 From: "John M. Penn" Date: Tue, 12 Sep 2017 12:52:59 -0500 Subject: [PATCH] Fix variable server config in java clients. Ref #474 --- .../models/graphics/src/CannonDisplay.java | 11 ++-- .../models/graphics/src/trick/SatDisplay.java | 50 +++++++++++++------ .../graphics/src/sundisplay/SunDisplay.java | 15 ++---- .../models/Graphics/src/trick/EVDisplay.java | 15 +++--- 4 files changed, 53 insertions(+), 38 deletions(-) diff --git a/trick_sims/Cannon/models/graphics/src/CannonDisplay.java b/trick_sims/Cannon/models/graphics/src/CannonDisplay.java index 1652919d..b73e5677 100644 --- a/trick_sims/Cannon/models/graphics/src/CannonDisplay.java +++ b/trick_sims/Cannon/models/graphics/src/CannonDisplay.java @@ -737,18 +737,19 @@ public class CannonDisplay extends JFrame { // Configure the Variable Server to cyclically send us the following varibales. // Tell the variable server: // 1) We want the values of the following variables: - evd.out.writeBytes( "trick.var_add(\"dyn.cannon.impact\")\n" + + evd.out.writeBytes( "trick.var_pause() \n" + + "trick.var_add(\"dyn.cannon.impact\")\n" + "trick.var_add(\"dyn.cannon.pos[0]\")\n" + "trick.var_add(\"dyn.cannon.pos[1]\")\n" + "trick.var_add(\"dyn.cannon.vel[0]\")\n" + "trick.var_add(\"dyn.cannon.vel[1]\")\n" + - "trick.var_add(\"trick_sys.sched.mode\")\n"); + "trick.var_add(\"trick_sys.sched.mode\")\n" + // 2) We want the responses in ASCII: - evd.out.writeBytes("trick.var_ascii() \n"); + "trick.var_ascii() \n" + // 3) We want values to be updated at the specified rate: - evd.out.writeBytes( String.format("trick.var_cycle(%.3f)\n", dt)); + String.format("trick.var_cycle(%.3f)\n", dt) + // 4) Start sending values as specified. - evd.out.writeBytes("trick.var_send() \n" ); + "trick.var_unpause() \n" ); evd.out.flush(); while (go) { diff --git a/trick_sims/SIM_sat2d/models/graphics/src/trick/SatDisplay.java b/trick_sims/SIM_sat2d/models/graphics/src/trick/SatDisplay.java index 6b91166e..20c48eb6 100644 --- a/trick_sims/SIM_sat2d/models/graphics/src/trick/SatDisplay.java +++ b/trick_sims/SIM_sat2d/models/graphics/src/trick/SatDisplay.java @@ -46,7 +46,7 @@ class SkyView extends JPanel { scale = mapScale; setScale(mapScale); skyColor = Color.BLACK; - planetColor = new Color(100,200,200); + planetColor = new Color(128,128,255); satelliteColor = new Color(255,0,0); planetRadius = 6378000; satellitePos = new double[] {0.0, planetRadius + 200000}; @@ -65,7 +65,13 @@ class SkyView extends JPanel { } } - public void drawCenteredCircle(Graphics2D g, int x, int y, int r) { + public void drawCenteredOval(Graphics2D g, int x, int y, int rh, int rv) { + x = x-(rh/2); + y = y-(rv/2); + g.drawOval(x,y,rh,rv); + } + + public void fillCenteredCircle(Graphics2D g, int x, int y, int r) { x = x-(r/2); y = y-(r/2); g.fillOval(x,y,r,r); @@ -83,15 +89,34 @@ class SkyView extends JPanel { g2d.setPaint(Color.BLACK); g2d.fillRect(0, 0, width, height); + int pr0 = (int)(scale * planetRadius); + int pr30 = (int)(scale * planetRadius * Math.cos(Math.toRadians(30))); + int pr60 = (int)(scale * planetRadius * Math.cos(Math.toRadians(60))); + // Draw Planet g2d.setPaint(planetColor); - drawCenteredCircle(g2d, worldOriginX, worldOriginY, (int)(scale * 2 * planetRadius)); + fillCenteredCircle(g2d, worldOriginX, worldOriginY, 2 * pr0); + + g2d.setPaint(Color.BLACK); + + // Circles of Latitude + g2d.drawLine(worldOriginX - pr60, worldOriginY - pr30 , worldOriginX + pr60, worldOriginY - pr30); + g2d.drawLine(worldOriginX - pr30, worldOriginY - pr60 , worldOriginX + pr30, worldOriginY - pr60); + g2d.drawLine(worldOriginX - pr0, worldOriginY, worldOriginX + pr0, worldOriginY ); // Equator + g2d.drawLine(worldOriginX - pr30, worldOriginY + pr60 , worldOriginX + pr30, worldOriginY + pr60); + g2d.drawLine(worldOriginX - pr60, worldOriginY + pr30 , worldOriginX + pr60, worldOriginY + pr30); + + // Meridians + g2d.drawLine(worldOriginX, worldOriginY - pr0, worldOriginX, worldOriginY + pr0 ); + drawCenteredOval(g2d, worldOriginX, worldOriginY, 2 * pr60, 2 * pr0); + drawCenteredOval(g2d, worldOriginX, worldOriginY, 2 * pr30, 2 * pr0); + drawCenteredOval(g2d, worldOriginX, worldOriginY, 2 * pr0, 2 * pr0); // Draw Satellite g2d.setPaint(satelliteColor); int sx = (int)(worldOriginX + scale * satellitePos[0]); int sy = (int)(worldOriginY - scale * satellitePos[1]); - drawCenteredCircle(g2d, sx, sy, (int)(10)); + fillCenteredCircle(g2d, sx, sy, (int)(10)); } @Override @@ -171,16 +196,13 @@ public class SatDisplay extends JFrame { System.out.println("Connecting to: " + host + ":" + port); sd.connectToServer(host, port); - sd.out.writeBytes("trick.var_set_client_tag(\"SatDisplay\") \n"); - sd.out.flush(); - - sd.out.writeBytes("trick.var_add(\"dyn.satellite.pos[0]\") \n" + - "trick.var_add(\"dyn.satellite.pos[1]\") \n" ); - sd.out.flush(); - - sd.out.writeBytes("trick.var_ascii() \n" + - "trick.var_cycle(0.1) \n" + - "trick.var_send() \n" ); + sd.out.writeBytes("trick.var_set_client_tag(\"SatDisplay\") \n" + + "trick.var_pause() \n" + + "trick.var_add(\"dyn.satellite.pos[0]\") \n" + + "trick.var_add(\"dyn.satellite.pos[1]\") \n" + + "trick.var_ascii() \n" + + "trick.var_cycle(0.1) \n" + + "trick.var_unpause()\n" ); sd.out.flush(); Boolean go = true; diff --git a/trick_sims/SIM_sun/models/graphics/src/sundisplay/SunDisplay.java b/trick_sims/SIM_sun/models/graphics/src/sundisplay/SunDisplay.java index a7f5d009..e02ea326 100644 --- a/trick_sims/SIM_sun/models/graphics/src/sundisplay/SunDisplay.java +++ b/trick_sims/SIM_sun/models/graphics/src/sundisplay/SunDisplay.java @@ -404,10 +404,9 @@ public class SunDisplay extends JFrame implements ActionListener { System.out.println("Connecting to: " + host + ":" + port); evd.connectToServer(host, port); - evd.out.writeBytes("trick.var_set_client_tag(\"SunDisplay\") \n"); - evd.out.flush(); - - evd.out.writeBytes("trick.var_add(\"sun_predictor.sun.JD\") \n" + + evd.out.writeBytes("trick.var_set_client_tag(\"SunDisplay\") \n" + + "trick.var_pause() \n" + + "trick.var_add(\"sun_predictor.sun.JD\") \n" + "trick.var_add(\"sun_predictor.sun.observer_latitude\") \n" + "trick.var_add(\"sun_predictor.sun.observer_longitude\") \n" + "trick.var_add(\"sun_predictor.sun.observer_offset_from_UTC\") \n" + @@ -430,13 +429,9 @@ public class SunDisplay extends JFrame implements ActionListener { "trick.var_add(\"sun_predictor.sun.utc.hour\") \n" + "trick.var_add(\"sun_predictor.sun.utc.min\") \n" + "trick.var_add(\"sun_predictor.sun.utc.sec\") \n" + - "" - ); - - evd.out.flush(); - evd.out.writeBytes("trick.var_ascii() \n" + + "trick.var_ascii() \n" + "trick.var_cycle(0.1) \n" + - "trick.var_send() \n" ); + "trick.var_unpause() \n" ); evd.out.flush(); Boolean go = true; diff --git a/trick_sims/SIM_wheelbot/models/Graphics/src/trick/EVDisplay.java b/trick_sims/SIM_wheelbot/models/Graphics/src/trick/EVDisplay.java index c5f94436..f53d84b4 100644 --- a/trick_sims/SIM_wheelbot/models/Graphics/src/trick/EVDisplay.java +++ b/trick_sims/SIM_wheelbot/models/Graphics/src/trick/EVDisplay.java @@ -229,17 +229,14 @@ public class EVDisplay extends JFrame { System.out.println("Connecting to: " + host + ":" + port); evd.connectToServer(host, port); - evd.out.writeBytes("trick.var_set_client_tag(\"EVDisplay\") \n"); - evd.out.flush(); - - evd.out.writeBytes("trick.var_add(\"veh.vehicle.position[0]\") \n" + + evd.out.writeBytes("trick.var_set_client_tag(\"EVDisplay\") \n" + + "trick.var_pause() \n" + + "trick.var_add(\"veh.vehicle.position[0]\") \n" + "trick.var_add(\"veh.vehicle.position[1]\") \n" + - "trick.var_add(\"veh.vehicle.heading\") \n"); - evd.out.flush(); - - evd.out.writeBytes("trick.var_ascii() \n" + + "trick.var_add(\"veh.vehicle.heading\") \n" + + "trick.var_ascii() \n" + "trick.var_cycle(0.1) \n" + - "trick.var_send() \n" ); + "trick.var_unpause() \n" ); evd.out.flush(); Boolean go = true;