rcpilot-cvs Mailing List for R/C Pilot Project
Status: Beta
Brought to you by:
mjpawlowsky
You can subscribe to this list here.
2004 |
Jan
|
Feb
(55) |
Mar
(175) |
Apr
(6) |
May
|
Jun
(24) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: Michael P. <mjp...@us...> - 2004-06-28 11:22:17
|
Update of /cvsroot/rcpilot/src/res/maps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17213 Added Files: Test.inf Test.gif Log Message: test map --- NEW FILE: Test.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Test.inf --- 46 00.000, -74 00.000 45 00.000, -73 00.000 |
From: Chris S. <cm...@us...> - 2004-06-28 10:37:07
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9084/rcpilot/rcgs Modified Files: RcgsMap.java Log Message: minor bug in plane trail code fixed Index: RcgsMap.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/RcgsMap.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** RcgsMap.java 28 Jun 2004 10:33:45 -0000 1.12 --- RcgsMap.java 28 Jun 2004 10:36:58 -0000 1.13 *************** *** 387,395 **** int planeLonSecs = Rcgs.tdata.getGPSLongitude(); - if(gpsHistoryLat.size()==GPS_HISTORY_LENGTH) { - gpsHistoryLat.poll(); // remove head of queue - gpsHistoryLon.poll(); // remove head of queue - } - // calculate plane position on current display --- 387,390 ---- *************** *** 738,741 **** --- 733,741 ---- int planeLonSecs = Rcgs.tdata.getGPSLongitude(); + if(gpsHistoryLat.size()==GPS_HISTORY_LENGTH) { + gpsHistoryLat.poll(); // remove head of queue + gpsHistoryLon.poll(); // remove head of queue + } + gpsHistoryLat.offer(new Integer(planeLatSecs)); gpsHistoryLon.offer(new Integer(planeLonSecs)); |
From: Chris S. <cm...@us...> - 2004-06-28 10:33:53
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8651/rcpilot/rcgs Modified Files: RcgsMap.java Log Message: Added trail of last 500 GPS positions behind plane. Index: RcgsMap.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/RcgsMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RcgsMap.java 28 Jun 2004 08:35:57 -0000 1.11 --- RcgsMap.java 28 Jun 2004 10:33:45 -0000 1.12 *************** *** 43,46 **** --- 43,48 ---- import javax.swing.*; import java.io.*; + import java.util.Iterator; + import java.util.concurrent.*; // LinkedBlockingQueue public class RcgsMap extends JComponent *************** *** 65,68 **** --- 67,74 ---- private static final int EARTH_MILE_CIRCUMF = 24988; // miles private static final int EARTH_ASEC_CIRCUMF = 129600000; // asecs + private static final int GPS_HISTORY_LENGTH = 500; + + private LinkedBlockingQueue gpsHistoryLat = null; + private LinkedBlockingQueue gpsHistoryLon = null; private Image mapImg, displayImg; *************** *** 170,173 **** --- 176,182 ---- add(scrollDownButton); add(scrollLeftButton); + + gpsHistoryLat = new LinkedBlockingQueue(GPS_HISTORY_LENGTH); + gpsHistoryLon = new LinkedBlockingQueue(GPS_HISTORY_LENGTH); } *************** *** 374,380 **** --- 383,395 ---- int course = (int)Rcgs.tdata.getCourse(); + int planeLatSecs = Rcgs.tdata.getGPSLatitude(); int planeLonSecs = Rcgs.tdata.getGPSLongitude(); + if(gpsHistoryLat.size()==GPS_HISTORY_LENGTH) { + gpsHistoryLat.poll(); // remove head of queue + gpsHistoryLon.poll(); // remove head of queue + } + // calculate plane position on current display *************** *** 390,393 **** --- 405,434 ---- } + private void drawGPSHistory(Graphics2D g) { + + Iterator itLat = gpsHistoryLat.iterator(); + Iterator itLon = gpsHistoryLon.iterator(); + + int lat[] = new int[gpsHistoryLat.size()]; + int lon[] = new int[gpsHistoryLon.size()]; + + int i = 0; + + while(itLat.hasNext() && itLon.hasNext()) { + int oneLat = ((Integer)itLat.next()).intValue(); + int oneLon = ((Integer)itLon.next()).intValue(); + + int latPix = (int)((displayTopLatSecs-oneLat)/displayVscale); + int lonPix = (int)((oneLon-displayLeftLonSecs)/displayHscale); + + lat[i] = latPix; + lon[i] = lonPix; + i++; + } + + g.setColor(Color.blue); + g.drawPolyline(lon,lat,lat.length); + } + private void drawHome(Graphics2D g) { *************** *** 491,498 **** } - // Passing 'this' as last arg results in imageUpdate() method - // being called repeatedly until image is fully loaded. This - // way we can guarantee paint is called after image is loaded. - g2.setColor(UserPreferences.getVidColor()); g2.fillRect(0,0,getWidth(),getHeight()); --- 532,535 ---- *************** *** 500,503 **** --- 537,541 ---- g2.drawImage(displayImg, 0,0,null); + drawGPSHistory(g2); drawPlane(g2); drawHome(g2); *************** *** 696,699 **** --- 734,744 ---- public void telemetryDataChanged(TelemetryDataChangedEvent ev) { + + int planeLatSecs = Rcgs.tdata.getGPSLatitude(); + int planeLonSecs = Rcgs.tdata.getGPSLongitude(); + + gpsHistoryLat.offer(new Integer(planeLatSecs)); + gpsHistoryLon.offer(new Integer(planeLonSecs)); + repaint(); } |
From: Michael P. <mjp...@us...> - 2004-06-28 10:29:41
|
Update of /cvsroot/rcpilot/src/res/maps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7703 Added Files: Cap-Saint-Jacques.inf Cap-Saint-Jacques.gif Log Message: Adding new map --- NEW FILE: Cap-Saint-Jacques.inf --- 45 29.000, -73 57.000 45 26.000, -73 54.000 --- NEW FILE: Cap-Saint-Jacques.gif --- (This appears to be a binary file; contents omitted.) |
From: Chris S. <cm...@us...> - 2004-06-28 08:36:06
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21206/rcpilot/rcgs Modified Files: RcgsMap.java Log Message: 1. replaced MediaTracker usage with ImageIcon(filename) (this uses mediatracker internally so it is less work for us) 2. replaced some literals with named constants 3. broke out plane/home drawing into their own methods for cleanliness 4. eliminated flicker/flash when pressing scroll/zoom buttons. Index: RcgsMap.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/RcgsMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** RcgsMap.java 28 Jun 2004 04:53:13 -0000 1.10 --- RcgsMap.java 28 Jun 2004 08:35:57 -0000 1.11 *************** *** 61,64 **** --- 61,69 ---- private static final String SCROLL_LEFT_IMAGE_PATH = "res/icons/scroll_left.jpg"; + private static final int H_ASEC_PER_DEGREE = 360000; // to hundredth asec + private static final int H_ASEC_PER_MILE_LAT = 5186; // to hundredth asec + private static final int EARTH_MILE_CIRCUMF = 24988; // miles + private static final int EARTH_ASEC_CIRCUMF = 129600000; // asecs + private Image mapImg, displayImg; *************** *** 74,78 **** private double Hscale; private double Vscale; ! // GPS stats for image loaded from disk private long srcTopLatSecs; --- 79,86 ---- private double Hscale; private double Vscale; ! ! private double displayHscale; ! private double displayVscale; ! // GPS stats for image loaded from disk private long srcTopLatSecs; *************** *** 148,152 **** // add action commands - zoomPlusButton.addActionListener(this); zoomMinusButton.addActionListener(this); --- 156,159 ---- *************** *** 241,269 **** private boolean loadMapImage(String imagePath) { - MediaTracker tracker; - boolean rval = true; // assume load will succeed boolean imageExists = (new File(imagePath)).exists(); if(imageExists) { ! mapImg = Toolkit.getDefaultToolkit().getImage(imagePath); ! ! // use mediatracker to load image for us ! ! try { ! tracker = new MediaTracker(this); ! tracker.addImage(mapImg, 0); ! tracker.waitForAll(); ! ! if(tracker.isErrorAny()) { ! System.err.println("RcgsMap.java: Error code " + ! tracker.statusID(0,false) + ! " loading image " + imagePath); ! rval = false; // load failed ! } ! ! } catch ( Exception e ) { ! System.err.println("RcgsMap.java: Exception adding mapImg to tracker."); ! } } else { --- 248,258 ---- private boolean loadMapImage(String imagePath) { boolean rval = true; // assume load will succeed boolean imageExists = (new File(imagePath)).exists(); if(imageExists) { ! Image tempImg = Toolkit.getDefaultToolkit().getImage(imagePath); ! ImageIcon ii = new ImageIcon(tempImg); ! mapImg = ii.getImage(); } else { *************** *** 379,400 **** scrollLeftButton.setBounds(2,(getHeight()/2)-16,34,34); } protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; - Shape plane, home; - int course = (int)Rcgs.tdata.getCourse(); - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2.setColor(UserPreferences.getVidColor()); - g2.fillRect(0,0,getWidth(),getHeight()); - // in hundredths of a second/pixel ! double displayHscale = Hscale / zoomLevel; ! double displayVscale = Vscale / zoomLevel; if(imgUpdateRequired) { --- 368,465 ---- scrollLeftButton.setBounds(2,(getHeight()/2)-16,34,34); } + + private void drawPlane(Graphics2D g) { + + // grab relevant data from telemetry object + + int course = (int)Rcgs.tdata.getCourse(); + int planeLatSecs = Rcgs.tdata.getGPSLatitude(); + int planeLonSecs = Rcgs.tdata.getGPSLongitude(); + + // calculate plane position on current display + + int planeLatPix = (int)((displayTopLatSecs-planeLatSecs)/displayVscale); + int planeLonPix = (int)((planeLonSecs-displayLeftLonSecs)/displayHscale); + + Shape plane = Shapes.getShapeIcon(Shapes.PLANE_SHAPE, planeLonPix, planeLatPix, course); + + g.setColor(Color.red); + g.fill(plane); + g.setColor(Color.black); + g.draw(plane); + } + + private void drawHome(Graphics2D g) { + + // grab relevant data from user preferences + + int homeLatSecs = UserPreferences.getHomeLatitude(); + int homeLonSecs = UserPreferences.getHomeLongitude(); + + // calculate home position on current display + + int homeLatPix = (int)((displayTopLatSecs-homeLatSecs)/displayVscale); + int homeLonPix = (int)((homeLonSecs-displayLeftLonSecs)/displayHscale); + + Shape home = Shapes.getShapeIcon(Shapes.HOME_SHAPE, homeLonPix, homeLatPix, 0); + + g.setColor(Color.green); + g.fill(home); + g.setColor(Color.black); + g.draw(home); + + g.setFont(new Font("Arial", Font.BOLD, 12)); + g.drawString("H",homeLonPix-3,homeLatPix+7); + + // calculate arcseconds/mile for this latitude + // so we can draw accurate 1,2,...,N mile radius + // arcs around home base. + + double homeLatDegrees = (double)homeLatSecs/H_ASEC_PER_DEGREE; + + double hAsecPerMileLon = EARTH_ASEC_CIRCUMF/(EARTH_MILE_CIRCUMF * + Math.cos(Math.toRadians(homeLatDegrees))); + + // number of pixels on each axis + // corresponding to one mile. + + double oneMileArcRadiusLat = H_ASEC_PER_MILE_LAT * (1/(double)displayVscale); + double oneMileArcRadiusLon = hAsecPerMileLon * (1/(double)displayHscale); + + // draw arcs around home + + g.setStroke(new BasicStroke(2)); + g.setColor(Color.red); + + for(int i = 0; i < 36; i++) { + g.draw(new Arc2D.Float(homeLonPix-(int)oneMileArcRadiusLon, + homeLatPix-(int)oneMileArcRadiusLat, + (int)(oneMileArcRadiusLon*2), // one mile diameter + (int)(oneMileArcRadiusLat*2), // ditto + i*10,5,Arc2D.OPEN)); + g.draw(new Arc2D.Float(homeLonPix-(int)(oneMileArcRadiusLon*2), + homeLatPix-(int)(oneMileArcRadiusLat*2), + (int)(oneMileArcRadiusLon*4), // 2 mile diameter + (int)(oneMileArcRadiusLat*4), // ditto + i*10,5,Arc2D.OPEN)); + g.draw(new Arc2D.Float(homeLonPix-(int)(oneMileArcRadiusLon*4), + homeLatPix-(int)(oneMileArcRadiusLat*4), + (int)(oneMileArcRadiusLon*8), // 4 mile diameter + (int)(oneMileArcRadiusLat*8), // ditto + i*10,5,Arc2D.OPEN)); + } + } protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // in hundredths of a second/pixel ! displayHscale = Hscale / zoomLevel; ! displayVscale = Vscale / zoomLevel; if(imgUpdateRequired) { *************** *** 418,422 **** FilteredImageSource fis = new FilteredImageSource(mapImg.getSource(), cif); ! displayImg = createImage(fis).getScaledInstance(getWidth(),getHeight(),Image.SCALE_FAST); imgUpdateRequired = false; --- 483,490 ---- FilteredImageSource fis = new FilteredImageSource(mapImg.getSource(), cif); ! // use an ImageIcon object to handle the mediatracker details for us ! Image tempImg = createImage(fis).getScaledInstance(getWidth(),getHeight(),Image.SCALE_FAST); ! ImageIcon ii = new ImageIcon(tempImg); ! displayImg = ii.getImage(); imgUpdateRequired = false; *************** *** 425,507 **** // Passing 'this' as last arg results in imageUpdate() method // being called repeatedly until image is fully loaded. This ! // way we can poll the loading process and make sure the image ! // is displayed. ! ! g2.drawImage(displayImg, 0,0,this); ! ! // calculate pixel locations for drawing graphics ! // over map. ! ! // in hundredths of a second ! int homeLatSecs = UserPreferences.getHomeLatitude(); ! int homeLonSecs = UserPreferences.getHomeLongitude(); ! ! int planeLatSecs = Rcgs.tdata.getGPSLatitude(); ! int planeLonSecs = Rcgs.tdata.getGPSLongitude(); ! ! // in pixels ! int homeLatPix = (int)((displayTopLatSecs-homeLatSecs)/displayVscale); ! int homeLonPix = (int)((homeLonSecs-displayLeftLonSecs)/displayHscale); ! ! int planeLatPix = (int)((displayTopLatSecs-planeLatSecs)/displayVscale); ! int planeLonPix = (int)((planeLonSecs-displayLeftLonSecs)/displayHscale); ! ! // draw plane ! plane = Shapes.getShapeIcon(Shapes.PLANE_SHAPE, planeLonPix, planeLatPix, course); ! ! g2.setColor(Color.red); ! g2.fill(plane); ! g2.setColor(Color.black); ! g2.draw(plane); ! ! // draw home ! ! // calculate arcseconds/mile for this latitude ! // so we can draw accurate 1,2,...,N mile radius ! // arcs around home base. ! ! double homeLatDegrees = (double)homeLatSecs/360000; ! ! double asecVPerMile = 5186; ! double asecHPerMile = 129600000/(24988*Math.cos(Math.toRadians(homeLatDegrees))); ! ! // number of pixels on each axis ! // corresponding to one mile. ! ! double oneMileArcVRadius = asecVPerMile * (1/(double)displayVscale); ! double oneMileArcHRadius = asecHPerMile * (1/(double)displayHscale); ! ! home = Shapes.getShapeIcon(Shapes.HOME_SHAPE, homeLonPix, homeLatPix, 0); ! ! g2.setColor(Color.green); ! g2.fill(home); ! g2.setColor(Color.black); ! g2.draw(home); ! ! g2.setFont(new Font("Arial", Font.BOLD, 12)); ! g2.drawString("H",homeLonPix-3,homeLatPix+7); ! // draw arcs around home ! g2.setStroke(new BasicStroke(2)); ! g2.setColor(Color.red); ! for(int i = 0; i < 36; i++) { ! g2.draw(new Arc2D.Float(homeLonPix-(int)oneMileArcHRadius, ! homeLatPix-(int)oneMileArcVRadius, ! (int)(oneMileArcHRadius*2), // one mile diameter ! (int)(oneMileArcVRadius*2), // ditto ! i*10,5,Arc2D.OPEN)); ! g2.draw(new Arc2D.Float(homeLonPix-(int)(oneMileArcHRadius*2), ! homeLatPix-(int)(oneMileArcVRadius*2), ! (int)(oneMileArcHRadius*4), // 2 mile diameter ! (int)(oneMileArcVRadius*4), // ditto ! i*10,5,Arc2D.OPEN)); ! g2.draw(new Arc2D.Float(homeLonPix-(int)(oneMileArcHRadius*4), ! homeLatPix-(int)(oneMileArcVRadius*4), ! (int)(oneMileArcHRadius*8), // 4 mile diameter ! (int)(oneMileArcVRadius*8), // ditto ! i*10,5,Arc2D.OPEN)); ! } } --- 493,505 ---- // Passing 'this' as last arg results in imageUpdate() method // being called repeatedly until image is fully loaded. This ! // way we can guarantee paint is called after image is loaded. ! g2.setColor(UserPreferences.getVidColor()); ! g2.fillRect(0,0,getWidth(),getHeight()); ! g2.drawImage(displayImg, 0,0,null); ! drawPlane(g2); ! drawHome(g2); } *************** *** 510,517 **** } - private void updateZoomDependantVariables() { - - } - private boolean increaseZoom() { boolean zoomPerformed = false; --- 508,511 ---- *************** *** 705,719 **** } - - public boolean imageUpdate(Image img, int infoflags, - int x, int y, int w, int h) { - if (infoflags != ALLBITS) - return true; - else { - repaint(); - return false; - } - } - public void componentResized(ComponentEvent e) { imgUpdateRequired = true; --- 699,702 ---- |
From: Chris S. <cm...@us...> - 2004-06-28 04:53:29
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19321/rcpilot/rcgs Modified Files: RcgsMap.java Log Message: 1. Zoom/Scroll buttons implemented and working. 2. Hscale/Vscale converted to double instead of long (the precision lost in calculations was significant) 3. Renamed bot/top longitude variables to left/right. (was confusing) 4. Changed color of range rings from black to red. 5. Arrow shape removed (was just there for testing) Index: RcgsMap.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/RcgsMap.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RcgsMap.java 27 Jun 2004 20:14:05 -0000 1.9 --- RcgsMap.java 28 Jun 2004 04:53:13 -0000 1.10 *************** *** 42,50 **** import java.awt.event.*; import javax.swing.*; - //import javax.swing.plaf.basic.*; // for BasicArrowButton import java.io.*; public class RcgsMap extends JComponent ! implements ComponentListener, TelemetryDataChangedEventListener { private static final String defaultMapName = "world"; --- 42,51 ---- import java.awt.event.*; import javax.swing.*; import java.io.*; public class RcgsMap extends JComponent ! implements ComponentListener, ! TelemetryDataChangedEventListener, ! ActionListener { private static final String defaultMapName = "world"; *************** *** 70,89 **** private long mapVsecs; ! private long Hscale; ! private long Vscale; // GPS stats for image loaded from disk private long srcTopLatSecs; ! private long srcTopLonSecs; private long srcBotLatSecs; ! private long srcBotLonSecs; // GPS stats for currently displayed subimage private long displayTopLatSecs; ! private long displayTopLonSecs; private long displayBotLatSecs; ! private long displayBotLonSecs; ! private long scale; --- 71,107 ---- private long mapVsecs; ! // seconds/pixel ! private double Hscale; ! private double Vscale; // GPS stats for image loaded from disk private long srcTopLatSecs; ! private long srcLeftLonSecs; private long srcBotLatSecs; ! private long srcRightLonSecs; // GPS stats for currently displayed subimage private long displayTopLatSecs; ! private long displayLeftLonSecs; private long displayBotLatSecs; ! private long displayRightLonSecs; ! ! // Used to track currently displayed portion ! // of loaded map (needed for zoom/scrolling). ! // ! // - displayX is the x pixel coordinate (in map space) ! // of the current top left corner of the display. ! // - displayY is the y pixel coordinate (in map space) ! // of the current top left corner of the display. ! // ! ! private int displayX; ! private int displayY; ! private int displayWidth; ! private int displayHeight; ! ! private int zoomLevel; ! private long scale; *************** *** 113,122 **** setLayout(null); zoomPlusButton = new JButton(new ImageIcon(ZOOM_PLUS_IMAGE_PATH)); zoomMinusButton = new JButton(new ImageIcon(ZOOM_MINUS_IMAGE_PATH)); - - add(zoomPlusButton); - add(zoomMinusButton); - scrollUpButton = new JButton(new ImageIcon(SCROLL_UP_IMAGE_PATH)); scrollRightButton = new JButton(new ImageIcon(SCROLL_RIGHT_IMAGE_PATH)); --- 131,137 ---- setLayout(null); + // create buttons zoomPlusButton = new JButton(new ImageIcon(ZOOM_PLUS_IMAGE_PATH)); zoomMinusButton = new JButton(new ImageIcon(ZOOM_MINUS_IMAGE_PATH)); scrollUpButton = new JButton(new ImageIcon(SCROLL_UP_IMAGE_PATH)); scrollRightButton = new JButton(new ImageIcon(SCROLL_RIGHT_IMAGE_PATH)); *************** *** 124,127 **** --- 139,162 ---- scrollLeftButton = new JButton(new ImageIcon(SCROLL_LEFT_IMAGE_PATH)); + // set action commands + zoomPlusButton.setActionCommand("ZOOM_PLUS"); + zoomMinusButton.setActionCommand("ZOOM_MINUS"); + scrollUpButton.setActionCommand("SCROLL_UP"); + scrollRightButton.setActionCommand("SCROLL_RIGHT"); + scrollDownButton.setActionCommand("SCROLL_DOWN"); + scrollLeftButton.setActionCommand("SCROLL_LEFT"); + + // add action commands + + zoomPlusButton.addActionListener(this); + zoomMinusButton.addActionListener(this); + scrollUpButton.addActionListener(this); + scrollRightButton.addActionListener(this); + scrollDownButton.addActionListener(this); + scrollLeftButton.addActionListener(this); + + // add buttons + add(zoomPlusButton); + add(zoomMinusButton); add(scrollUpButton); add(scrollRightButton); *************** *** 179,183 **** // a .inf file ! mapHsecs = srcBotLonSecs - srcTopLonSecs; mapVsecs = srcTopLatSecs - srcBotLatSecs; --- 214,218 ---- // a .inf file ! mapHsecs = srcRightLonSecs - srcLeftLonSecs; mapVsecs = srcTopLatSecs - srcBotLatSecs; *************** *** 185,188 **** --- 220,230 ---- mapVpix = mapImg.getHeight(null); + // reset these whenever a new map loads + displayX = 0; + displayY = 0; + zoomLevel = 1; + + Hscale = ((double)mapHsecs / mapImg.getWidth(null) ); + Vscale = ((double)mapVsecs / mapImg.getHeight(null) ); } *************** *** 271,282 **** 6000 * Double.parseDouble(line1Tokens[1])); ! srcTopLonSecs = (int) (360000 * Double.parseDouble(line1Tokens[2]) + ! 6000 * Double.parseDouble(line1Tokens[3])); srcBotLatSecs = (int) (360000 * Double.parseDouble(line2Tokens[0]) + 6000 * Double.parseDouble(line2Tokens[1])); ! srcBotLonSecs = (int) (360000 * Double.parseDouble(line2Tokens[2]) + ! 6000 * Double.parseDouble(line2Tokens[3])); } catch(NumberFormatException nfe) { --- 313,324 ---- 6000 * Double.parseDouble(line1Tokens[1])); ! srcLeftLonSecs = (int) (360000 * Double.parseDouble(line1Tokens[2]) + ! 6000 * Double.parseDouble(line1Tokens[3])); srcBotLatSecs = (int) (360000 * Double.parseDouble(line2Tokens[0]) + 6000 * Double.parseDouble(line2Tokens[1])); ! srcRightLonSecs = (int) (360000 * Double.parseDouble(line2Tokens[2]) + ! 6000 * Double.parseDouble(line2Tokens[3])); } catch(NumberFormatException nfe) { *************** *** 294,297 **** --- 336,344 ---- } + ////////////////////////////////////////////////////////////// + // + // Called externally if user chooses a new map + // from the dropdown menu, etc. + public void changeMap(ActionEvent e) throws FileNotFoundException, IOException { *************** *** 299,311 **** // if it loads correctly, save map name to preferences ! if(loadMap(e.getActionCommand())) UserPreferences.setMap(e.getActionCommand()); ! ! if(isVisible()) { imgUpdateRequired = true; - repaint(); } } private void layoutButtons() { // fix: cleaner way to --- 346,370 ---- // if it loads correctly, save map name to preferences ! if(loadMap(e.getActionCommand())) { UserPreferences.setMap(e.getActionCommand()); ! displayWidth = getWidth()/zoomLevel; ! displayHeight = getHeight()/zoomLevel; imgUpdateRequired = true; } + + if(isVisible()) + repaint(); } + ////////////////////////////////////////////////////////////// + // + // Since we're not using a layout manager, this method + // is called to position the buttons. This is necessary + // if we want the buttons to overlay on the map. + // It must only be called *after* the component is sized/visible. + // Currently it is called from within the paintComponent() method. + // + // Don't call me from anywhere else. + private void layoutButtons() { // fix: cleaner way to *************** *** 324,328 **** Graphics2D g2 = (Graphics2D) g; ! Shape plane, home, arrow; int course = (int)Rcgs.tdata.getCourse(); --- 383,387 ---- Graphics2D g2 = (Graphics2D) g; ! Shape plane, home; int course = (int)Rcgs.tdata.getCourse(); *************** *** 330,361 **** g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - - g2.setColor(UserPreferences.getVidColor()); - g2.fillRect(0, 0, getWidth(), getHeight()); ! if(imgUpdateRequired) { ! int cropWidth = Math.min(mapImg.getWidth(null), ! getWidth()); ! int cropHeight = Math.min(mapImg.getHeight(null), ! getHeight()); ! layoutButtons(); ! // in hundredths of a second/pixel ! Hscale = mapHsecs / mapImg.getWidth(null); ! Vscale = mapVsecs / mapImg.getHeight(null); // figure out top/bot/left/right GPS coords // of cropped image. ! displayTopLatSecs = srcTopLatSecs; ! displayTopLonSecs = srcTopLonSecs; ! displayBotLatSecs = srcTopLatSecs - Vscale*cropHeight; ! displayBotLonSecs = srcTopLonSecs - Hscale*cropWidth; ! displayImg = createImage(new FilteredImageSource(mapImg.getSource(), ! new CropImageFilter(0, 0, cropWidth, cropHeight))); imgUpdateRequired = false; --- 389,422 ---- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); ! g2.setColor(UserPreferences.getVidColor()); ! g2.fillRect(0,0,getWidth(),getHeight()); ! // in hundredths of a second/pixel ! double displayHscale = Hscale / zoomLevel; ! double displayVscale = Vscale / zoomLevel; ! if(imgUpdateRequired) { ! layoutButtons(); // figure out top/bot/left/right GPS coords // of cropped image. ! displayTopLatSecs = (int)(srcTopLatSecs - Vscale*displayY); ! displayLeftLonSecs = (int)(srcLeftLonSecs + Hscale*displayX); ! displayBotLatSecs = (int)(displayTopLatSecs - displayVscale*displayHeight); ! displayRightLonSecs = (int)(displayLeftLonSecs + displayHscale*displayWidth); ! ! // perform image cropping ! ! CropImageFilter cif = new CropImageFilter(displayX, displayY, ! displayWidth, displayHeight); ! ! FilteredImageSource fis = new FilteredImageSource(mapImg.getSource(), cif); ! ! displayImg = createImage(fis).getScaledInstance(getWidth(),getHeight(),Image.SCALE_FAST); imgUpdateRequired = false; *************** *** 380,388 **** // in pixels ! int homeLatPix = (int)((displayTopLatSecs-homeLatSecs)/Vscale); ! int homeLonPix = (int)((homeLonSecs-displayTopLonSecs)/Hscale); ! int planeLatPix = (int)((displayTopLatSecs-planeLatSecs)/Vscale); ! int planeLonPix = (int)((planeLonSecs-displayTopLonSecs)/Hscale); // draw plane --- 441,449 ---- // in pixels ! int homeLatPix = (int)((displayTopLatSecs-homeLatSecs)/displayVscale); ! int homeLonPix = (int)((homeLonSecs-displayLeftLonSecs)/displayHscale); ! int planeLatPix = (int)((displayTopLatSecs-planeLatSecs)/displayVscale); ! int planeLonPix = (int)((planeLonSecs-displayLeftLonSecs)/displayHscale); // draw plane *************** *** 408,413 **** // corresponding to one mile. ! double oneMileArcVRadius = asecVPerMile * (1/(double)Vscale); ! double oneMileArcHRadius = asecHPerMile * (1/(double)Hscale); home = Shapes.getShapeIcon(Shapes.HOME_SHAPE, homeLonPix, homeLatPix, 0); --- 469,474 ---- // corresponding to one mile. ! double oneMileArcVRadius = asecVPerMile * (1/(double)displayVscale); ! double oneMileArcHRadius = asecHPerMile * (1/(double)displayHscale); home = Shapes.getShapeIcon(Shapes.HOME_SHAPE, homeLonPix, homeLatPix, 0); *************** *** 423,427 **** // draw arcs around home ! g2.setColor(Color.black); for(int i = 0; i < 36; i++) { --- 484,489 ---- // draw arcs around home ! g2.setStroke(new BasicStroke(2)); ! g2.setColor(Color.red); for(int i = 0; i < 36; i++) { *************** *** 442,456 **** i*10,5,Arc2D.OPEN)); } ! // draw arrow ! arrow = Shapes.getShapeIcon(Shapes.ARROW_SHAPE, 200, 200, 90); ! g2.setColor(Color.yellow); ! g2.fill(arrow); ! g2.setColor(Color.black); ! g2.draw(arrow); } public void displayDebugInfo() { --- 504,683 ---- i*10,5,Arc2D.OPEN)); } + } ! private void showEdgeOfMapDialog() { ! JOptionPane.showMessageDialog(Rcgs.frame, "Edge of map reached."); ! } ! private void updateZoomDependantVariables() { } + private boolean increaseZoom() { + boolean zoomPerformed = false; + + if(zoomLevel<6) { + zoomLevel++; + + // perform centered zoom in + displayX += displayWidth/(zoomLevel*2); + displayY += displayHeight/(zoomLevel*2); + + displayWidth = getWidth()/zoomLevel; + displayHeight = getHeight()/zoomLevel; + + zoomPerformed = true; + } + else + JOptionPane.showMessageDialog(Rcgs.frame, "Maximum zoom level reached."); + + return zoomPerformed; + } + + private boolean decreaseZoom() { + boolean zoomPerformed = false; + + if(zoomLevel>1) { + zoomLevel--; + + // perform centered zoom out + + displayWidth = getWidth()/zoomLevel; + displayHeight = getHeight()/zoomLevel; + + displayX -= displayWidth/((zoomLevel+1)*2); + displayY -= displayHeight/((zoomLevel+1)*2); + + // bounds checking + + if(displayX < 0) displayX = 0; + if(displayY < 0) displayY = 0; + + int rightSide = displayX + displayWidth; + int bottomSide = displayY + displayHeight; + + if(rightSide > mapImg.getWidth(null)) + displayX -= rightSide - mapImg.getWidth(null); + + if(bottomSide > mapImg.getHeight(null)) + displayY -= bottomSide - mapImg.getHeight(null); + + zoomPerformed = true; + } + else + JOptionPane.showMessageDialog(Rcgs.frame, "Minimum zoom level reached."); + + return zoomPerformed; + } + + private boolean scrollUp() { + + boolean scrollPerformed = false; + + // Figure out how far we should scroll up. + // This is the minimum of 2 values: + // field1: 1/4 the current displayHeight (preferred) + // field2: As far as we can go without running out of image + + int delta = Math.min(displayHeight/4, + displayY); + + if(delta > 0) { + displayY -= delta; + scrollPerformed = true; + } + else + showEdgeOfMapDialog(); + + return scrollPerformed; + } + + private boolean scrollRight() { + + boolean scrollPerformed = false; + + // Figure out how far we should scroll to the right. + // This is the minimum of 2 values: + // field1: 1/4 the current displayWidth (preferred) + // field2: As far as we can go without running out of image + + int delta = Math.min(displayWidth/4, + mapImg.getWidth(null)-displayWidth-displayX); + + if(delta > 0) { + displayX += delta; + scrollPerformed = true; + } + else + showEdgeOfMapDialog(); + + return scrollPerformed; + } + + private boolean scrollDown() { + + boolean scrollPerformed = false; + + // Figure out how far we should scroll down. + // This is the minimum of 2 values: + // field1: 1/4 the current displayHeight (preferred) + // field2: As far as we can go without running out of image + + int delta = Math.min(displayHeight/4, + mapImg.getHeight(null)-displayHeight-displayY); + + if(delta > 0) { + displayY += delta; + scrollPerformed = true; + } + else + showEdgeOfMapDialog(); + + return scrollPerformed; + } + + private boolean scrollLeft() { + + boolean scrollPerformed = false; + + // Figure out how far we should scroll to the left. + // This is the minimum of 2 values: + // field1: 1/4 the current displayWidth (preferred) + // field2: As far as we can go without running out of image + + int delta = Math.min(displayWidth/4, + displayX); + if(delta > 0) { + displayX -= delta; + scrollPerformed = true; + } + else + showEdgeOfMapDialog(); + + return scrollPerformed; + } + + public void actionPerformed(ActionEvent e) { + boolean shouldRepaint = false; + + if("ZOOM_PLUS".equals(e.getActionCommand())) + shouldRepaint = increaseZoom(); + else if("ZOOM_MINUS".equals(e.getActionCommand())) + shouldRepaint = decreaseZoom(); + else if("SCROLL_UP".equals(e.getActionCommand())) + shouldRepaint = scrollUp(); + else if("SCROLL_RIGHT".equals(e.getActionCommand())) + shouldRepaint = scrollRight(); + else if("SCROLL_DOWN".equals(e.getActionCommand())) + shouldRepaint = scrollDown(); + else if("SCROLL_LEFT".equals(e.getActionCommand())) + shouldRepaint = scrollLeft(); + + if(shouldRepaint) { + imgUpdateRequired = true; + repaint(); + } + } + public void displayDebugInfo() { *************** *** 464,469 **** System.out.println("bopLatSecs: " + srcBotLatSecs); ! System.out.println("topLonSecs: " + srcTopLonSecs); ! System.out.println("bopLonSecs: " + srcBotLonSecs); System.out.println("mapHSecs: " + mapHsecs); --- 691,696 ---- System.out.println("bopLatSecs: " + srcBotLatSecs); ! System.out.println("topLonSecs: " + srcLeftLonSecs); ! System.out.println("bopLonSecs: " + srcRightLonSecs); System.out.println("mapHSecs: " + mapHsecs); *************** *** 491,494 **** --- 718,725 ---- public void componentResized(ComponentEvent e) { imgUpdateRequired = true; + + displayWidth = getWidth()/zoomLevel; + displayHeight = getHeight()/zoomLevel; + repaint(); } |
From: Chris S. <cm...@us...> - 2004-06-27 20:14:16
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30523/rcpilot/rcgs Modified Files: RcgsMap.java Log Message: added scroll buttons, currently non-functional Index: RcgsMap.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/RcgsMap.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RcgsMap.java 27 Jun 2004 07:39:45 -0000 1.8 --- RcgsMap.java 27 Jun 2004 20:14:05 -0000 1.9 *************** *** 55,58 **** --- 55,63 ---- private static final String ZOOM_MINUS_IMAGE_PATH = "res/icons/zoom_minus.jpg"; + private static final String SCROLL_UP_IMAGE_PATH = "res/icons/scroll_up.jpg"; + private static final String SCROLL_RIGHT_IMAGE_PATH = "res/icons/scroll_right.jpg"; + private static final String SCROLL_DOWN_IMAGE_PATH = "res/icons/scroll_down.jpg"; + private static final String SCROLL_LEFT_IMAGE_PATH = "res/icons/scroll_left.jpg"; + private Image mapImg, displayImg; *************** *** 88,91 **** --- 93,101 ---- private JButton zoomMinusButton; + private JButton scrollUpButton; + private JButton scrollRightButton; + private JButton scrollDownButton; + private JButton scrollLeftButton; + /* * Create the Map Panel and get the last map. *************** *** 108,111 **** --- 118,131 ---- add(zoomPlusButton); add(zoomMinusButton); + + scrollUpButton = new JButton(new ImageIcon(SCROLL_UP_IMAGE_PATH)); + scrollRightButton = new JButton(new ImageIcon(SCROLL_RIGHT_IMAGE_PATH)); + scrollDownButton = new JButton(new ImageIcon(SCROLL_DOWN_IMAGE_PATH)); + scrollLeftButton = new JButton(new ImageIcon(SCROLL_LEFT_IMAGE_PATH)); + + add(scrollUpButton); + add(scrollRightButton); + add(scrollDownButton); + add(scrollLeftButton); } *************** *** 288,291 **** --- 308,324 ---- } + private void layoutButtons() { + // fix: cleaner way to + // store static values + + zoomPlusButton.setBounds(2,2,34,34); + zoomMinusButton.setBounds(38,2,34,34); + + scrollUpButton.setBounds( (getWidth()/2)-16,2,34,34); + scrollRightButton.setBounds( getWidth()-36,(getHeight()/2)-16,34,34); + scrollDownButton.setBounds( (getWidth()/2)-16,getHeight()-36,34,34); + scrollLeftButton.setBounds(2,(getHeight()/2)-16,34,34); + } + protected void paintComponent(Graphics g) { *************** *** 309,317 **** getHeight()); ! // replace literals here ! ! ! zoomPlusButton.setBounds(2,2,34,34); ! zoomMinusButton.setBounds(38,2,34,34); // in hundredths of a second/pixel --- 342,346 ---- getHeight()); ! layoutButtons(); // in hundredths of a second/pixel |
From: Chris S. <cm...@us...> - 2004-06-27 20:03:30
|
Update of /cvsroot/rcpilot/src/res/icons In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29022/res/icons Added Files: scroll_down.jpg scroll_left.jpg scroll_right.jpg scroll_up.jpg Log Message: images used for buttons/labels --- NEW FILE: scroll_left.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: scroll_up.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: scroll_down.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: scroll_right.jpg --- (This appears to be a binary file; contents omitted.) |
From: Chris S. <cm...@us...> - 2004-06-27 19:49:55
|
Update of /cvsroot/rcpilot/src/res/icons In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26656/res/icons Added Files: icon_base.psd zoom_minus.jpg zoom_plus.jpg Log Message: images used for buttons/labels --- NEW FILE: zoom_minus.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: zoom_plus.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: icon_base.psd --- (This appears to be a binary file; contents omitted.) |
From: Chris S. <cm...@us...> - 2004-06-27 07:39:53
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28174/rcpilot/rcgs Modified Files: RcgsMap.java Log Message: Added zoom buttons to map, but they are non-functional right now Index: RcgsMap.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/RcgsMap.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RcgsMap.java 27 Jun 2004 00:31:30 -0000 1.7 --- RcgsMap.java 27 Jun 2004 07:39:45 -0000 1.8 *************** *** 52,55 **** --- 52,58 ---- private static final String defaultInfoPath = "res/maps/"+defaultMapName+".inf"; + private static final String ZOOM_PLUS_IMAGE_PATH = "res/icons/zoom_plus.jpg"; + private static final String ZOOM_MINUS_IMAGE_PATH = "res/icons/zoom_minus.jpg"; + private Image mapImg, displayImg; *************** *** 82,85 **** --- 85,91 ---- private boolean imgUpdateRequired = true; + private JButton zoomPlusButton; + private JButton zoomMinusButton; + /* * Create the Map Panel and get the last map. *************** *** 94,97 **** --- 100,111 ---- setName("Map"); loadMap(UserPreferences.getMap()); + + setLayout(null); + + zoomPlusButton = new JButton(new ImageIcon(ZOOM_PLUS_IMAGE_PATH)); + zoomMinusButton = new JButton(new ImageIcon(ZOOM_MINUS_IMAGE_PATH)); + + add(zoomPlusButton); + add(zoomMinusButton); } *************** *** 275,279 **** protected void paintComponent(Graphics g) { ! Graphics2D g2 = (Graphics2D) g; Shape plane, home, arrow; --- 289,293 ---- protected void paintComponent(Graphics g) { ! Graphics2D g2 = (Graphics2D) g; Shape plane, home, arrow; *************** *** 291,297 **** --- 305,318 ---- int cropWidth = Math.min(mapImg.getWidth(null), getWidth()); + int cropHeight = Math.min(mapImg.getHeight(null), getHeight()); + // replace literals here + + + zoomPlusButton.setBounds(2,2,34,34); + zoomMinusButton.setBounds(38,2,34,34); + // in hundredths of a second/pixel Hscale = mapHsecs / mapImg.getWidth(null); *************** *** 352,357 **** double homeLatDegrees = (double)homeLatSecs/360000; - displayDebugInfo(); - double asecVPerMile = 5186; double asecHPerMile = 129600000/(24988*Math.cos(Math.toRadians(homeLatDegrees))); --- 373,376 ---- *************** *** 403,407 **** g2.draw(arrow); - g2.dispose(); //clean up } --- 422,425 ---- |
From: Chris S. <cm...@us...> - 2004-06-27 07:32:40
|
Update of /cvsroot/rcpilot/src/res/icons In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27069/icons Log Message: Directory /cvsroot/rcpilot/src/res/icons added to the repository |
From: Chris S. <cm...@us...> - 2004-06-27 00:31:38
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3284/rcpilot/rcgs Modified Files: RcgsMap.java Log Message: Added 1,2, and 4 mile range rings around home. These rings correctly take into account the changing arcSec/mile ratio as latitude increases. This can result in egg shaped range rings. I believe this is correct. Index: RcgsMap.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/RcgsMap.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RcgsMap.java 26 Jun 2004 10:20:49 -0000 1.6 --- RcgsMap.java 27 Jun 2004 00:31:30 -0000 1.7 *************** *** 38,45 **** import java.awt.*; import java.awt.image.*; import java.awt.event.*; import javax.swing.*; ! import java.io.*; --- 38,46 ---- import java.awt.*; + import java.awt.geom.*;//Arc2D.Float; import java.awt.image.*; import java.awt.event.*; import javax.swing.*; ! //import javax.swing.plaf.basic.*; // for BasicArrowButton import java.io.*; *************** *** 149,152 **** --- 150,154 ---- mapHpix = mapImg.getWidth(null); mapVpix = mapImg.getHeight(null); + } *************** *** 292,296 **** getHeight()); ! // in seconds/pixel Hscale = mapHsecs / mapImg.getWidth(null); Vscale = mapVsecs / mapImg.getHeight(null); --- 294,298 ---- getHeight()); ! // in hundredths of a second/pixel Hscale = mapHsecs / mapImg.getWidth(null); Vscale = mapVsecs / mapImg.getHeight(null); *************** *** 320,324 **** // over map. ! // in seconds int homeLatSecs = UserPreferences.getHomeLatitude(); int homeLonSecs = UserPreferences.getHomeLongitude(); --- 322,326 ---- // over map. ! // in hundredths of a second int homeLatSecs = UserPreferences.getHomeLatitude(); int homeLonSecs = UserPreferences.getHomeLongitude(); *************** *** 343,349 **** // draw home home = Shapes.getShapeIcon(Shapes.HOME_SHAPE, homeLonPix, homeLatPix, 0); ! g2.setColor(Color.green); g2.fill(home); g2.setColor(Color.black); --- 345,369 ---- // draw home + + // calculate arcseconds/mile for this latitude + // so we can draw accurate 1,2,...,N mile radius + // arcs around home base. + + double homeLatDegrees = (double)homeLatSecs/360000; + + displayDebugInfo(); + + double asecVPerMile = 5186; + double asecHPerMile = 129600000/(24988*Math.cos(Math.toRadians(homeLatDegrees))); + + // number of pixels on each axis + // corresponding to one mile. + + double oneMileArcVRadius = asecVPerMile * (1/(double)Vscale); + double oneMileArcHRadius = asecHPerMile * (1/(double)Hscale); + home = Shapes.getShapeIcon(Shapes.HOME_SHAPE, homeLonPix, homeLatPix, 0); ! g2.setColor(Color.green); g2.fill(home); g2.setColor(Color.black); *************** *** 353,356 **** --- 373,398 ---- g2.drawString("H",homeLonPix-3,homeLatPix+7); + // draw arcs around home + + g2.setColor(Color.black); + + for(int i = 0; i < 36; i++) { + g2.draw(new Arc2D.Float(homeLonPix-(int)oneMileArcHRadius, + homeLatPix-(int)oneMileArcVRadius, + (int)(oneMileArcHRadius*2), // one mile diameter + (int)(oneMileArcVRadius*2), // ditto + i*10,5,Arc2D.OPEN)); + g2.draw(new Arc2D.Float(homeLonPix-(int)(oneMileArcHRadius*2), + homeLatPix-(int)(oneMileArcVRadius*2), + (int)(oneMileArcHRadius*4), // 2 mile diameter + (int)(oneMileArcVRadius*4), // ditto + i*10,5,Arc2D.OPEN)); + g2.draw(new Arc2D.Float(homeLonPix-(int)(oneMileArcHRadius*4), + homeLatPix-(int)(oneMileArcVRadius*4), + (int)(oneMileArcHRadius*8), // 4 mile diameter + (int)(oneMileArcVRadius*8), // ditto + i*10,5,Arc2D.OPEN)); + } + // draw arrow arrow = Shapes.getShapeIcon(Shapes.ARROW_SHAPE, 200, 200, 90); *************** *** 378,381 **** --- 420,426 ---- System.out.println("bopLonSecs: " + srcBotLonSecs); + System.out.println("mapHSecs: " + mapHsecs); + System.out.println("mapVSecs: " + mapVsecs); + System.out.println("Hscale: " + Hscale); System.out.println("Vscale: " + Vscale); |
From: Chris S. <cm...@us...> - 2004-06-26 10:20:58
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21762/rcpilot/rcgs Modified Files: RcgsMap.java Log Message: Component resize now results in cropping of map image instead of scaling. Index: RcgsMap.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/RcgsMap.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RcgsMap.java 25 Jun 2004 12:29:12 -0000 1.5 --- RcgsMap.java 26 Jun 2004 10:20:49 -0000 1.6 *************** *** 38,41 **** --- 38,42 ---- import java.awt.*; + import java.awt.image.*; import java.awt.event.*; import javax.swing.*; *************** *** 50,56 **** private static final String defaultInfoPath = "res/maps/"+defaultMapName+".inf"; ! private Image mapImg, fastDisplayImg, goodDisplayImg; ! ! private MediaTracker scaledImgTracker = null; // Size of the map in pixels --- 51,55 ---- private static final String defaultInfoPath = "res/maps/"+defaultMapName+".inf"; ! private Image mapImg, displayImg; // Size of the map in pixels *************** *** 65,77 **** private long Vscale; ! private long topLatSecs; ! private long topLonSecs; ! private long botLatSecs; ! private long botLonSecs; private long scale; ! private boolean imgRescaleRequired = true; ! private boolean goodImgLoaded = false; /* --- 64,83 ---- private long Vscale; ! // GPS stats for image loaded from disk ! private long srcTopLatSecs; ! private long srcTopLonSecs; ! private long srcBotLatSecs; ! private long srcBotLonSecs; ! ! // GPS stats for currently displayed subimage ! ! private long displayTopLatSecs; ! private long displayTopLonSecs; ! private long displayBotLatSecs; ! private long displayBotLonSecs; private long scale; ! private boolean imgUpdateRequired = true; /* *************** *** 138,143 **** // a .inf file ! mapHsecs = botLonSecs - topLonSecs; ! mapVsecs = topLatSecs - botLatSecs; mapHpix = mapImg.getWidth(null); --- 144,149 ---- // a .inf file ! mapHsecs = srcBotLonSecs - srcTopLonSecs; ! mapVsecs = srcTopLatSecs - srcBotLatSecs; mapHpix = mapImg.getWidth(null); *************** *** 226,240 **** try { ! topLatSecs = (int) (360000 * Double.parseDouble(line1Tokens[0]) + ! 6000 * Double.parseDouble(line1Tokens[1])); ! topLonSecs = (int) (360000 * Double.parseDouble(line1Tokens[2]) + ! 6000 * Double.parseDouble(line1Tokens[3])); ! botLatSecs = (int) (360000 * Double.parseDouble(line2Tokens[0]) + ! 6000 * Double.parseDouble(line2Tokens[1])); ! botLonSecs = (int) (360000 * Double.parseDouble(line2Tokens[2]) + ! 6000 * Double.parseDouble(line2Tokens[3])); } catch(NumberFormatException nfe) { --- 232,246 ---- try { ! srcTopLatSecs = (int) (360000 * Double.parseDouble(line1Tokens[0]) + ! 6000 * Double.parseDouble(line1Tokens[1])); ! srcTopLonSecs = (int) (360000 * Double.parseDouble(line1Tokens[2]) + ! 6000 * Double.parseDouble(line1Tokens[3])); ! srcBotLatSecs = (int) (360000 * Double.parseDouble(line2Tokens[0]) + ! 6000 * Double.parseDouble(line2Tokens[1])); ! srcBotLonSecs = (int) (360000 * Double.parseDouble(line2Tokens[2]) + ! 6000 * Double.parseDouble(line2Tokens[3])); } catch(NumberFormatException nfe) { *************** *** 261,265 **** if(isVisible()) { ! imgRescaleRequired = true; repaint(); } --- 267,271 ---- if(isVisible()) { ! imgUpdateRequired = true; repaint(); } *************** *** 279,322 **** g2.fillRect(0, 0, getWidth(), getHeight()); ! int ch = getParent().getWidth() / 2; ! int cv = getParent().getHeight() / 2; ! if(imgRescaleRequired) { ! if(scaledImgTracker==null) ! scaledImgTracker = new MediaTracker(this); ! fastDisplayImg = mapImg.getScaledInstance(getWidth(), ! getHeight(), ! Image.SCALE_FAST); ! goodDisplayImg = mapImg.getScaledInstance(getWidth(), ! getHeight(), ! Image.SCALE_SMOOTH); ! try { ! // wait only for fast version of image to load ! // so we don't hang the app. ! // good version will load/display automatically ! // through imageUpdate() method. ! scaledImgTracker.addImage(fastDisplayImg, 0); ! scaledImgTracker.waitForID(0); ! goodImgLoaded = false; ! imgRescaleRequired = false; ! } ! catch(Exception e) { ! System.err.println("RcgsMap.java: Error loading fast image!"); ! } } ! if(!goodImgLoaded) ! g2.drawImage(fastDisplayImg, 0,0,null); ! g2.drawImage(goodDisplayImg, 0,0,this); ! // in seconds/pixel ! Hscale = mapHsecs / getWidth(); ! Vscale = mapVsecs / getHeight(); // in seconds --- 285,322 ---- g2.fillRect(0, 0, getWidth(), getHeight()); ! if(imgUpdateRequired) { ! int cropWidth = Math.min(mapImg.getWidth(null), ! getWidth()); ! int cropHeight = Math.min(mapImg.getHeight(null), ! getHeight()); ! // in seconds/pixel ! Hscale = mapHsecs / mapImg.getWidth(null); ! Vscale = mapVsecs / mapImg.getHeight(null); ! // figure out top/bot/left/right GPS coords ! // of cropped image. ! displayTopLatSecs = srcTopLatSecs; ! displayTopLonSecs = srcTopLonSecs; ! displayBotLatSecs = srcTopLatSecs - Vscale*cropHeight; ! displayBotLonSecs = srcTopLonSecs - Hscale*cropWidth; ! displayImg = createImage(new FilteredImageSource(mapImg.getSource(), ! new CropImageFilter(0, 0, cropWidth, cropHeight))); ! imgUpdateRequired = false; } ! // Passing 'this' as last arg results in imageUpdate() method ! // being called repeatedly until image is fully loaded. This ! // way we can poll the loading process and make sure the image ! // is displayed. ! g2.drawImage(displayImg, 0,0,this); ! // calculate pixel locations for drawing graphics ! // over map. // in seconds *************** *** 328,336 **** // in pixels ! int homeLatPix = (int)((topLatSecs-homeLatSecs)/Vscale); ! int homeLonPix = (int)((homeLonSecs-topLonSecs)/Hscale); ! int planeLatPix = (int)((topLatSecs-planeLatSecs)/Vscale); ! int planeLonPix = (int)((planeLonSecs-topLonSecs)/Hscale); // draw plane --- 328,336 ---- // in pixels ! int homeLatPix = (int)((displayTopLatSecs-homeLatSecs)/Vscale); ! int homeLonPix = (int)((homeLonSecs-displayTopLonSecs)/Hscale); ! int planeLatPix = (int)((displayTopLatSecs-planeLatSecs)/Vscale); ! int planeLonPix = (int)((planeLonSecs-displayTopLonSecs)/Hscale); // draw plane *************** *** 354,358 **** // draw arrow ! arrow = Shapes.getShapeIcon(Shapes.ARROW_SHAPE, ch-80, cv, 90); g2.setColor(Color.yellow); --- 354,358 ---- // draw arrow ! arrow = Shapes.getShapeIcon(Shapes.ARROW_SHAPE, 200, 200, 90); g2.setColor(Color.yellow); *************** *** 372,380 **** System.out.println("Current component height: " + getHeight()); ! System.out.println("topLatSecs: " + topLatSecs); ! System.out.println("bopLatSecs: " + botLatSecs); ! System.out.println("topLonSecs: " + topLonSecs); ! System.out.println("bopLonSecs: " + botLonSecs); System.out.println("Hscale: " + Hscale); --- 372,380 ---- System.out.println("Current component height: " + getHeight()); ! System.out.println("topLatSecs: " + srcTopLatSecs); ! System.out.println("bopLatSecs: " + srcBotLatSecs); ! System.out.println("topLonSecs: " + srcTopLonSecs); ! System.out.println("bopLonSecs: " + srcBotLonSecs); System.out.println("Hscale: " + Hscale); *************** *** 392,396 **** return true; else { - goodImgLoaded = true; repaint(); return false; --- 392,395 ---- *************** *** 399,403 **** public void componentResized(ComponentEvent e) { ! imgRescaleRequired = true; repaint(); } --- 398,402 ---- public void componentResized(ComponentEvent e) { ! imgUpdateRequired = true; repaint(); } |
From: Michael P. <mjp...@us...> - 2004-06-25 12:29:21
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6074 Modified Files: RcgsMap.java Shapes.java Tracker.java Log Message: -- Map resizes correctly with changes in component/window size. This required implementing ComponentListener interface to pickup resize events. -- Map displays 'fast' image first, then switches to antialiased version of image when it's ready (on my machine, the antialiased version took up to 2-3 seconds for large window sizes). This required overriding imageUpdate(Image,int,int,int,int,int); Try resizing the map several times and you'll see the image 'pop' from aliased to antialiased. -- bug with calculation of Hscale/Vscale fixed (needs to be based on actual window size, not .gif size). -- Plane displays at correct GPS coordinates received from TelemetryData class. -- added HOME graphic (small green house with H inside it). -- HOME graphic displays at correct GPS coordinates received from UserPreferences. Try setting your home coords somewhere inside the Montreal map, then swap back and forth between Montreal/World maps. -- added ARROW graphic. (right now just displays near center of map, but can be used for various things on map). -- added displayDebugInfo() method. Shapes.java ----------- -- Rewritten to support arbitrary number of shapes with very little code for each additional shape. -- Added HOME_SHAPE and ARROW_SHAPE -- Adding a new shape is described in the source file. Tracker.java ------------ -- One line altered to reflect new method of accessing Shapes.java. Index: RcgsMap.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/RcgsMap.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RcgsMap.java 24 Jun 2004 10:29:32 -0000 1.4 --- RcgsMap.java 25 Jun 2004 12:29:12 -0000 1.5 *************** *** 40,47 **** import java.awt.event.*; import javax.swing.*; import java.io.*; public class RcgsMap extends JComponent ! implements TelemetryDataChangedEventListener { private static final String defaultMapName = "world"; --- 40,48 ---- import java.awt.event.*; import javax.swing.*; + import java.io.*; public class RcgsMap extends JComponent ! implements ComponentListener, TelemetryDataChangedEventListener { private static final String defaultMapName = "world"; *************** *** 49,53 **** private static final String defaultInfoPath = "res/maps/"+defaultMapName+".inf"; ! private Image mapImg; // Size of the map in pixels --- 50,56 ---- private static final String defaultInfoPath = "res/maps/"+defaultMapName+".inf"; ! private Image mapImg, fastDisplayImg, goodDisplayImg; ! ! private MediaTracker scaledImgTracker = null; // Size of the map in pixels *************** *** 68,72 **** private long scale; ! /* * Create the Map Panel and get the last map. --- 71,78 ---- private long scale; ! ! private boolean imgRescaleRequired = true; ! private boolean goodImgLoaded = false; ! /* * Create the Map Panel and get the last map. *************** *** 76,79 **** --- 82,88 ---- // register for telemetry events tdata.addTelemetryDataChangedListener(this); + // register for resize events + addComponentListener(this); + setName("Map"); loadMap(UserPreferences.getMap()); *************** *** 121,128 **** // perform actual loading ! rval &= loadMapImage(imagePath); ! rval &= loadMapInfo(infoPath); ! ! return rval; } --- 130,149 ---- // perform actual loading ! boolean imageSuccess = loadMapImage(imagePath); ! boolean infoSuccess = loadMapInfo(infoPath); ! ! if(imageSuccess && infoSuccess) { ! // these values shound only be calculated ! // if we managed to load an image and ! // a .inf file ! ! mapHsecs = botLonSecs - topLonSecs; ! mapVsecs = topLatSecs - botLatSecs; ! ! mapHpix = mapImg.getWidth(null); ! mapVpix = mapImg.getHeight(null); ! } ! ! return rval & imageSuccess & infoSuccess; } *************** *** 151,160 **** tracker.waitForAll(); - mapHpix = mapImg.getWidth(null); - mapVpix = mapImg.getHeight(null); - - Hscale = mapHsecs / mapHpix; - Vscale = mapVsecs / mapVpix; - if(tracker.isErrorAny()) { System.err.println("RcgsMap.java: Error code " + --- 172,175 ---- *************** *** 222,228 **** botLonSecs = (int) (360000 * Double.parseDouble(line2Tokens[2]) + 6000 * Double.parseDouble(line2Tokens[3])); - - mapHsecs = botLonSecs - topLonSecs; - mapVsecs = topLatSecs - botLatSecs; } catch(NumberFormatException nfe) { --- 237,240 ---- *************** *** 248,253 **** UserPreferences.setMap(e.getActionCommand()); ! if(isVisible()) repaint(); } --- 260,267 ---- UserPreferences.setMap(e.getActionCommand()); ! if(isVisible()) { ! imgRescaleRequired = true; repaint(); + } } *************** *** 255,259 **** Graphics2D g2 = (Graphics2D) g; ! Shape plane; int course = (int)Rcgs.tdata.getCourse(); --- 269,273 ---- Graphics2D g2 = (Graphics2D) g; ! Shape plane, home, arrow; int course = (int)Rcgs.tdata.getCourse(); *************** *** 265,277 **** g2.fillRect(0, 0, getWidth(), getHeight()); - int mch = mapImg.getWidth(null) / 2; - int mcv = mapImg.getHeight(null) / 2; - int ch = getParent().getWidth() / 2; int cv = getParent().getHeight() / 2; ! ! g2.drawImage(mapImg, ch - mch, cv - mcv, null); ! ! plane = Shapes.planePath(ch, cv, course); g2.setColor(Color.red); --- 279,339 ---- g2.fillRect(0, 0, getWidth(), getHeight()); int ch = getParent().getWidth() / 2; int cv = getParent().getHeight() / 2; ! ! if(imgRescaleRequired) { ! if(scaledImgTracker==null) ! scaledImgTracker = new MediaTracker(this); ! ! fastDisplayImg = mapImg.getScaledInstance(getWidth(), ! getHeight(), ! Image.SCALE_FAST); ! ! goodDisplayImg = mapImg.getScaledInstance(getWidth(), ! getHeight(), ! Image.SCALE_SMOOTH); ! ! try { ! // wait only for fast version of image to load ! // so we don't hang the app. ! // good version will load/display automatically ! // through imageUpdate() method. ! ! scaledImgTracker.addImage(fastDisplayImg, 0); ! scaledImgTracker.waitForID(0); ! ! goodImgLoaded = false; ! imgRescaleRequired = false; ! } ! catch(Exception e) { ! System.err.println("RcgsMap.java: Error loading fast image!"); ! } ! } ! ! if(!goodImgLoaded) ! g2.drawImage(fastDisplayImg, 0,0,null); ! ! g2.drawImage(goodDisplayImg, 0,0,this); ! ! // in seconds/pixel ! Hscale = mapHsecs / getWidth(); ! Vscale = mapVsecs / getHeight(); ! ! // in seconds ! int homeLatSecs = UserPreferences.getHomeLatitude(); ! int homeLonSecs = UserPreferences.getHomeLongitude(); ! ! int planeLatSecs = Rcgs.tdata.getGPSLatitude(); ! int planeLonSecs = Rcgs.tdata.getGPSLongitude(); ! ! // in pixels ! int homeLatPix = (int)((topLatSecs-homeLatSecs)/Vscale); ! int homeLonPix = (int)((homeLonSecs-topLonSecs)/Hscale); ! ! int planeLatPix = (int)((topLatSecs-planeLatSecs)/Vscale); ! int planeLonPix = (int)((planeLonSecs-topLonSecs)/Hscale); ! ! // draw plane ! plane = Shapes.getShapeIcon(Shapes.PLANE_SHAPE, planeLonPix, planeLatPix, course); g2.setColor(Color.red); *************** *** 279,288 **** g2.setColor(Color.black); g2.draw(plane); ! g2.dispose(); //clean up } ! ! public void telemetryDataChanged(TelemetryDataChangedEvent ev) { ! repaint(); ! } } --- 341,420 ---- g2.setColor(Color.black); g2.draw(plane); ! ! // draw home ! home = Shapes.getShapeIcon(Shapes.HOME_SHAPE, homeLonPix, homeLatPix, 0); ! ! g2.setColor(Color.green); ! g2.fill(home); ! g2.setColor(Color.black); ! g2.draw(home); ! ! g2.setFont(new Font("Arial", Font.BOLD, 12)); ! g2.drawString("H",homeLonPix-3,homeLatPix+7); ! ! // draw arrow ! arrow = Shapes.getShapeIcon(Shapes.ARROW_SHAPE, ch-80, cv, 90); ! ! g2.setColor(Color.yellow); ! g2.fill(arrow); ! g2.setColor(Color.black); ! g2.draw(arrow); ! g2.dispose(); //clean up } ! ! public void displayDebugInfo() { ! ! System.out.println("Current img width: " + mapImg.getWidth(null)); ! System.out.println("Current img height: " + mapImg.getHeight(null)); ! ! System.out.println("Current component width: " + getWidth()); ! System.out.println("Current component height: " + getHeight()); ! ! System.out.println("topLatSecs: " + topLatSecs); ! System.out.println("bopLatSecs: " + botLatSecs); ! ! System.out.println("topLonSecs: " + topLonSecs); ! System.out.println("bopLonSecs: " + botLonSecs); ! ! System.out.println("Hscale: " + Hscale); ! System.out.println("Vscale: " + Vscale); ! } ! ! public void telemetryDataChanged(TelemetryDataChangedEvent ev) { ! repaint(); ! } ! ! ! public boolean imageUpdate(Image img, int infoflags, ! int x, int y, int w, int h) { ! if (infoflags != ALLBITS) ! return true; ! else { ! goodImgLoaded = true; ! repaint(); ! return false; ! } ! } ! ! public void componentResized(ComponentEvent e) { ! imgRescaleRequired = true; ! repaint(); ! } ! ! // dont need these 3 below, but ! // we couldn't use the adapter class b/c ! // java doesn't support multiple inheritance! ! ! public void componentHidden(ComponentEvent e) { ! ! } ! ! public void componentMoved(ComponentEvent e) { ! ! } ! ! public void componentShown(ComponentEvent e) { ! ! } } Index: Tracker.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/Tracker.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Tracker.java 5 Apr 2004 17:33:58 -0000 1.8 --- Tracker.java 25 Jun 2004 12:29:12 -0000 1.9 *************** *** 127,132 **** // Create plane shape and rotate it to course. // (course - bearing) because of previous transform) ! plane = Shapes.planePath(xc, yc-dist, (int)(course - b)); ! g2.setColor(Color.red); g2.fill(plane); --- 127,131 ---- // Create plane shape and rotate it to course. // (course - bearing) because of previous transform) ! plane = Shapes.getShapeIcon(Shapes.PLANE_SHAPE, xc, yc-dist, (int)(course - b)); g2.setColor(Color.red); g2.fill(plane); Index: Shapes.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/Shapes.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Shapes.java 3 Mar 2004 18:42:20 -0000 1.2 --- Shapes.java 25 Jun 2004 12:29:12 -0000 1.3 *************** *** 33,63 **** abstract public class Shapes { ! ! ! public static Shape planePath(int xc, int yc, int angle){ ! ! AffineTransform at = new AffineTransform(); ! Shape rplane; ! ! // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ! int txPoints[] = {xc-18, xc-3, xc-3, xc-2, xc+2, xc+3, xc+3, xc+18, xc+20, xc+20, xc+18, xc+14, xc+13, xc+3, xc+3, xc+7, xc+9, xc+7, xc+3, xc+3, xc+1, xc-1, xc-3, xc-3, xc-7, xc-9, xc-7, xc-3, xc-3, xc-13, xc-14, xc-18, xc-20, xc-20}; ! int tyPoints[] = {yc-3, yc-3, yc-10, yc-12, yc-12, yc-10, yc-3, yc-3, yc-2, yc+1, yc+2, yc+2, yc+3, yc+3, yc+15, yc+15, yc+17, yc+19, yc+19, yc+21, yc+22, yc+22, yc+21, yc+19, yc+19, yc+17, yc+15, yc+15, yc+3, yc+3, yc+2, yc+2, yc+1, yc-2 }; ! GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, txPoints.length); ! gp.moveTo(txPoints[0], tyPoints[0]); ! ! for (int index = 1; index < txPoints.length; index++) { ! gp.lineTo(txPoints[index], tyPoints[index]); ! }; ! ! gp.closePath(); ! ! at.rotate(Math.toRadians(angle), xc, yc); ! rplane = gp.createTransformedShape(at); ! return(rplane); } - - - ! } \ No newline at end of file --- 33,108 ---- abstract public class Shapes { ! ! public static final int PLANE_SHAPE = 0; ! public static final int HOME_SHAPE = 1; ! public static final int ARROW_SHAPE = 2; ! ! static GeneralPath[] paths = null; ! ! /////////////////////////////////////////////////////////////////// ! // shape descriptions ! // ! // to add a new shape, add an entry (above) of the form: ! // public static final int NEW_SHAPE_NAME = #; ! // and describe the shape's x/y coords in the Points arrays below. ! // ! // The shape can then be retrieved using getShapeIcon(NEW_SHAPE_NAME, ...); ! // ! ! static int xPoints[][] = { ! {-18,-3,-3,-2,2,3,3,18,20,20,18,14,13,3,3,7,9,7,3,3,1,-1,-3,-3,-7,-9,-7,-3,-3,-13,-14,-18,-20,-20}, // x coords for plane ! {-11,0,11,7,7,-7,-7}, // x coords for home ! {-6,0,6,3,3,-3,-3} // x coords for arrow ! }; + static int yPoints[][] = { + { -3,-3,-10,-12,-12,-10,-3,-3,-2,1,2,2,3,3,15,15,17,19,19,21,22,22,21,19,19,17,15,15,3,3,2,2,1,-2}, // y coords for plane + {2,-8,2,2,8,8,2}, // y coords for home + {4,-10,4,4,10,10,4} // y coords for arrow + }; + + public static Shape getShapeIcon(int shapeType, int xc, int yc, int angle){ + + // if this is the first time we've ever been called, + // setup the paths array + + if(paths==null) { + paths = new GeneralPath[xPoints.length]; + for(int i = 0; i < xPoints.length; i++) + paths[i] = null; + } + + // create shape if this is the + // first time this method was invoked for + // a particular shapeType + + if(paths[shapeType]==null) { + paths[shapeType] = buildPath(xPoints[shapeType], + yPoints[shapeType]); + } + + AffineTransform at = buildTransform(xc,yc,angle); + + return(paths[shapeType].createTransformedShape(at)); } ! private static AffineTransform buildTransform(int xc, int yc, int angle) { ! AffineTransform at = new AffineTransform(); ! at.translate(xc,yc); ! at.rotate(Math.toRadians(angle)); ! return(at); ! } ! ! private static GeneralPath buildPath(int xP[], int yP[]) { ! GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, ! xP.length); ! path.moveTo(xP[0], yP[0]); ! ! for (int i = 1; i < xP.length; i++) ! path.lineTo(xP[i], yP[i]); ! ! path.closePath(); ! ! return(path); ! } ! } |
From: Michael P. <mjp...@us...> - 2004-06-24 10:29:42
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14824 Modified Files: RcgsMap.java Log Message: Changes submitted by Chris Smith 1. added loadMap + loadMapImage method to combine common functionality of constructor + changeMap. 2. as a result, rewrote constructor and changeMap. 3. made getMapInfo private. 4. renamed getMapInfo to loadMapInfo. 5. fixed bug in constructor (fix moved to loadMap). 6. removed redundant 'this.' in a few places. 7. added default map filenames to class as private static final Strings. 8. removed Color class data members (black/white) that weren't in use anywhere in the code. 9. rewrote parsing of map .inf files to clean it up a bit and add some error checking on the input. Index: RcgsMap.java =================================================================== RCS file: /cvsroot/rcpilot/src/rcpilot/rcgs/RcgsMap.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RcgsMap.java 9 Mar 2004 00:11:00 -0000 1.3 --- RcgsMap.java 24 Jun 2004 10:29:32 -0000 1.4 *************** *** 1,10 **** /* - * - * - * TODO: Combine the constructor and changeMap.... - * - * - * - * * Class to create a map for tracking the vehicle * --- 1,3 ---- *************** *** 49,127 **** import java.io.*; - public class RcgsMap extends JComponent implements TelemetryDataChangedEventListener{ - - - final Color white = Color.white; - final Color black = Color.black; - private Image mapImg; // Size of the map in pixels ! private long mapHpix; ! private long mapVpix; ! // Size of the map in 1/100th of seconds ! private long mapHsecs; ! private long mapVsecs; ! private long Hscale; ! private long Vscale; ! private long topLatSecs; ! private long topLonSecs; ! private long botLatSecs; ! private long botLonSecs; ! private long scale; ! /* * Create the Map Panel and get the last map. */ public RcgsMap(TelemetryData tdata ) throws FileNotFoundException, IOException { ! ! MediaTracker tracker; ! ! // Register for TelemetryDataChangedEvents ! TelemetryDataChangedEventListener l = this; ! tdata.addTelemetryDataChangedListener(l); ! ! this.setName("Map"); ! ! String mapname = UserPreferences.getMap(); ! ! mapImg = Toolkit.getDefaultToolkit().getImage("res/maps/"+mapname+".gif"); ! ! ! /* ! * THIS DOESN'T WORK.... WHY? ! */ ! if (mapImg.getWidth(null) == 0) { ! System.out.println (" width was " + mapImg.getWidth(null)); ! mapImg = Toolkit.getDefaultToolkit().getImage("res/maps/World.gif"); ! } ! ! // Get the info files as well ! getMapInfo(mapname); ! ! try { ! tracker = new MediaTracker(this); ! tracker.addImage(mapImg, 0); ! tracker.waitForAll(); ! } catch ( Exception e ) {} ! ! mapHpix = mapImg.getWidth(null); ! mapVpix = mapImg.getHeight(null); ! Hscale = mapHsecs / mapHpix; ! Vscale = mapVsecs / mapVpix; ! ! System.out.println ("mapHsecs: " + mapHsecs); ! System.out.println ("mapVsecs: " + mapVsecs); ! System.out.println ("mapHpix: " + mapHpix); ! System.out.println ("mapVpix: " + mapVpix); ! System.out.println ("Hscale: " + Hscale); ! System.out.println ("Vscale: " + Vscale); } /* --- 42,178 ---- import java.io.*; + public class RcgsMap extends JComponent + implements TelemetryDataChangedEventListener { + private static final String defaultMapName = "world"; + private static final String defaultImagePath = "res/maps/"+defaultMapName+".gif"; + private static final String defaultInfoPath = "res/maps/"+defaultMapName+".inf"; private Image mapImg; + // Size of the map in pixels ! private long mapHpix; ! private long mapVpix; ! ! // Size of the map in 1/100th of seconds ! private long mapHsecs; ! private long mapVsecs; ! private long Hscale; ! private long Vscale; ! private long topLatSecs; ! private long topLonSecs; ! private long botLatSecs; ! private long botLonSecs; ! private long scale; /* * Create the Map Panel and get the last map. */ + public RcgsMap(TelemetryData tdata ) throws FileNotFoundException, IOException { ! // register for telemetry events ! tdata.addTelemetryDataChangedListener(this); ! setName("Map"); ! loadMap(UserPreferences.getMap()); } + ////////////////////////////////////////////////////////////// + // + // Load the given mapName. + // If it can't be found, load defaultMapName + // + // returns -- true if it loaded mapName successfully + // returns -- false if anything goes wrong. + // + // There are multiple cases that result in false: + // 1. Found mapName but something wrong with image or info file. + // 2. Couldn't find mapName, default loaded instead. + // 3. Couldn't find mapName, default failed to load. + // + + private boolean loadMap(String mapName) throws FileNotFoundException, IOException { + + boolean rval = true; // assume load will succeed + + String imagePath = "res/maps/"+mapName+".gif"; + String infoPath = "res/maps/"+mapName+".inf"; + + boolean imageExists = (new File(imagePath)).exists(); + boolean infoExists = (new File(infoPath)).exists(); + + // if requested map image or info file doesn't exist, + // prepare to load default image/info. + + if(!imageExists || !infoExists) { + System.err.println("RcgsMap.java: One of " + imagePath + + " or " + infoPath + + " doesn't exist, using defaults."); + + mapName = defaultMapName; + imagePath = defaultImagePath; + infoPath = defaultInfoPath; + + rval = false; // couldn't find part of requested map + } + + // perform actual loading + + rval &= loadMapImage(imagePath); + rval &= loadMapInfo(infoPath); + + return rval; + } + + ////////////////////////////////////////////////////////////// + // + // Load the image portion of the map. + // + // This should only be called from private + // routine loadMap, nowhere else. + // + + private boolean loadMapImage(String imagePath) { + MediaTracker tracker; + + boolean rval = true; // assume load will succeed + boolean imageExists = (new File(imagePath)).exists(); + + if(imageExists) { + mapImg = Toolkit.getDefaultToolkit().getImage(imagePath); + + // use mediatracker to load image for us + + try { + tracker = new MediaTracker(this); + tracker.addImage(mapImg, 0); + tracker.waitForAll(); + + mapHpix = mapImg.getWidth(null); + mapVpix = mapImg.getHeight(null); + + Hscale = mapHsecs / mapHpix; + Vscale = mapVsecs / mapVpix; + + if(tracker.isErrorAny()) { + System.err.println("RcgsMap.java: Error code " + + tracker.statusID(0,false) + + " loading image " + imagePath); + rval = false; // load failed + } + + } catch ( Exception e ) { + System.err.println("RcgsMap.java: Exception adding mapImg to tracker."); + } + } + else { + JOptionPane.showMessageDialog(Rcgs.frame, "Image file "+imagePath+" for map does not exist."); + rval = false; // load failed + } + + return rval; + } /* *************** *** 129,230 **** * The info should be in a file called mapname.inf * with a format like: 45 45.160, 74 04.550 ! * 45 20.080, 73 14.280 ! */ ! public void getMapInfo(String mapname) throws FileNotFoundException, IOException{ ! ! boolean exists = (new File("res/maps/"+mapname+".inf")).exists(); ! if (exists) { ! BufferedReader in = new BufferedReader(new FileReader("res/maps/"+mapname+".inf")); ! String str, lat, lon; ! String[] tmp; ! int i = 1; ! while ((str = in.readLine()) != null) { ! tmp = str.split(","); ! getCoord(tmp, i); ! i++; ! } ! mapHsecs = botLonSecs - topLonSecs; ! mapVsecs = topLatSecs - botLatSecs; ! } else { ! // Modal dialog with OK button ! JOptionPane.showMessageDialog(Rcgs.frame, "Information file for map does not exists."); ! } ! } ! ! ! public void getCoord(String[] tmp, int line){ ! ! String t; ! String[] s; ! double k, l; ! int lat=0, lon=0; ! ! if (line <= 2){ ! t = tmp[0].trim(); ! s = t.split(" "); ! Debug.dump(s); ! l = Double.parseDouble(s[0]); ! l = l * 60 * 60 * 100; ! k = Double.parseDouble(s[1]); ! k = k * 60 * 100; ! lat = (int)(k + l); ! ! t = tmp[1].trim(); ! s = t.split(" "); ! Debug.dump(s); ! l = Double.parseDouble(s[0]); ! l = l * 60 * 60 * 100; ! k = Double.parseDouble(s[1]); ! k = k * 60 * 100; ! lon = (int)(k + l); ! } ! ! switch (line){ ! case 1: ! topLatSecs = lat; ! topLonSecs = lon; ! case 2: ! botLatSecs = lat; ! botLonSecs = lon; ! break; ! default: ! break; ! } } ! ! public void changeMap(ActionEvent e) throws FileNotFoundException, IOException { - try - { - this.mapImg = Toolkit.getDefaultToolkit().getImage("res/maps/" + e.getActionCommand() + ".gif"); - } catch (Exception ex) { - System.err.println("Error loading map : " + ex); - } - - // Get the info files as well - getMapInfo(e.getActionCommand()); - - try { - MediaTracker tracker = new MediaTracker(this); - tracker.addImage(this.mapImg, 0); - tracker.waitForAll(); - } catch ( Exception me ) { - - } - - // Set the last map in preferences - UserPreferences.setMap(e.getActionCommand()); - - if (this.isVisible()) - { - this.repaint(); - } - } - - protected void paintComponent(Graphics g) { --- 180,254 ---- * The info should be in a file called mapname.inf * with a format like: 45 45.160, 74 04.550 ! * 45 20.080, 73 14.280 ! */ ! private boolean loadMapInfo(String infoPath) throws FileNotFoundException, IOException{ ! boolean rval = true; // assume load will succeed ! boolean infoExists = (new File(infoPath)).exists(); ! ! if (infoExists) { ! BufferedReader in = new BufferedReader(new FileReader(infoPath)); ! String str; ! String[] line1Tokens = null, line2Tokens = null; ! ! // read 2 lines from file into tokens ! ! if((str = in.readLine()) != null) ! line1Tokens = str.trim().replaceAll(",","").split(" "); ! else ! rval = false; // load failed ! ! if(rval && ((str = in.readLine()) != null)) ! line2Tokens = str.trim().replaceAll(",","").split(" "); ! else ! rval = false; // load failed ! ! // parse tokens from each line into lat/long in seconds ! // (as long as everything has gone smoothly so far). ! ! if(rval) { ! ! try { ! topLatSecs = (int) (360000 * Double.parseDouble(line1Tokens[0]) + ! 6000 * Double.parseDouble(line1Tokens[1])); ! ! topLonSecs = (int) (360000 * Double.parseDouble(line1Tokens[2]) + ! 6000 * Double.parseDouble(line1Tokens[3])); ! ! botLatSecs = (int) (360000 * Double.parseDouble(line2Tokens[0]) + ! 6000 * Double.parseDouble(line2Tokens[1])); ! ! botLonSecs = (int) (360000 * Double.parseDouble(line2Tokens[2]) + ! 6000 * Double.parseDouble(line2Tokens[3])); ! ! mapHsecs = botLonSecs - topLonSecs; ! mapVsecs = topLatSecs - botLatSecs; ! } ! catch(NumberFormatException nfe) { ! System.err.println("RcgsMap.java: Map file " + infoPath + ! " contains non-numeric tokens!"); ! rval = false; ! } ! } ! } else { ! JOptionPane.showMessageDialog(Rcgs.frame, "Information file "+infoPath+" for map does not exist."); ! rval = false; // load failed } + + return rval; } ! public void changeMap(ActionEvent e) throws FileNotFoundException, IOException { + // load map named in the action command. + // if it loads correctly, save map name to preferences + + if(loadMap(e.getActionCommand())) + UserPreferences.setMap(e.getActionCommand()); + + if(isVisible()) + repaint(); + } protected void paintComponent(Graphics g) { *************** *** 232,247 **** Graphics2D g2 = (Graphics2D) g; Shape plane; int course = (int)Rcgs.tdata.getCourse(); ! ! ((Graphics2D)g2).setRenderingHint ! (RenderingHints.KEY_ANTIALIASING, ! RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(UserPreferences.getVidColor()); g2.fillRect(0, 0, getWidth(), getHeight()); ! int mch = mapImg.getWidth(this) / 2; ! int mcv = mapImg.getHeight(this) / 2; int ch = getParent().getWidth() / 2; int cv = getParent().getHeight() / 2; --- 256,271 ---- Graphics2D g2 = (Graphics2D) g; Shape plane; + int course = (int)Rcgs.tdata.getCourse(); ! g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, ! RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(UserPreferences.getVidColor()); g2.fillRect(0, 0, getWidth(), getHeight()); ! int mch = mapImg.getWidth(null) / 2; ! int mcv = mapImg.getHeight(null) / 2; ! int ch = getParent().getWidth() / 2; int cv = getParent().getHeight() / 2; *************** *** 250,253 **** --- 274,278 ---- plane = Shapes.planePath(ch, cv, course); + g2.setColor(Color.red); g2.fill(plane); *************** *** 256,265 **** g2.dispose(); //clean up - } ! public void telemetryDataChanged(TelemetryDataChangedEvent ev){ ! this.repaint(); ! } ! } --- 281,288 ---- g2.dispose(); //clean up } ! public void telemetryDataChanged(TelemetryDataChangedEvent ev) { ! repaint(); ! } } |
From: Michael P. <mjp...@us...> - 2004-06-23 17:12:29
|
Update of /cvsroot/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17029 Removed Files: COPYING.TXT Log Message: Removing rcgs all java source has been moved below src/rcpilot --- COPYING.TXT DELETED --- |
Update of /cvsroot/rcpilot/rcgs/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13235 Removed Files: AGWController.java AGWFunctions.java AGWPacket.java AGWPacketTransport.java Agwpe.java AGWTest.java AGWUser.java Altimeter.java Attitude.java Compass.java CRC.java Debug.java Global.java GPS.java HUD.java IAS.java ImagePanel.java InstrumentLayout.java Map.java Monitor.java Prefs.java Rcgs.java Shapes.java Tachometer.java TelemetryData.java TelemetryDataChangedEvent.java TelemetryDataChangedEventListener.java TelemetryTable.java TestServer.java Tracker.java Variometer.java Video.java Log Message: Removing rcgs all java source has been moved below src/rcpilot --- InstrumentLayout.java DELETED --- --- CRC.java DELETED --- --- ImagePanel.java DELETED --- --- Tracker.java DELETED --- --- Rcgs.java DELETED --- --- AGWController.java DELETED --- --- Altimeter.java DELETED --- --- TelemetryTable.java DELETED --- --- TestServer.java DELETED --- --- Tachometer.java DELETED --- --- Map.java DELETED --- --- Debug.java DELETED --- --- Prefs.java DELETED --- --- Video.java DELETED --- --- Shapes.java DELETED --- --- IAS.java DELETED --- --- Variometer.java DELETED --- --- HUD.java DELETED --- --- TelemetryDataChangedEventListener.java DELETED --- --- AGWPacketTransport.java DELETED --- --- Compass.java DELETED --- --- TelemetryData.java DELETED --- --- TelemetryDataChangedEvent.java DELETED --- --- Global.java DELETED --- --- AGWUser.java DELETED --- --- Attitude.java DELETED --- --- Monitor.java DELETED --- --- AGWFunctions.java DELETED --- --- AGWPacket.java DELETED --- --- GPS.java DELETED --- --- AGWTest.java DELETED --- --- Agwpe.java DELETED --- |
From: Michael P. <mjp...@us...> - 2004-06-23 16:51:22
|
Update of /cvsroot/rcpilot/rcgs/src/notused In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13126 Removed Files: printHex.java Log Message: Removing rcgs all java source has been moved below src/rcpilot --- printHex.java DELETED --- |
From: Michael P. <mjp...@us...> - 2004-06-23 16:50:55
|
Update of /cvsroot/rcpilot/rcgs/res/maps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12945 Removed Files: Montreal.gif Montreal.inf world.gif world.inf Log Message: Removing rcgs all java source has been moved below src/rcpilot --- world.gif DELETED --- --- Montreal.gif DELETED --- --- world.inf DELETED --- --- Montreal.inf DELETED --- |
From: Michael P. <mjp...@us...> - 2004-06-23 16:50:05
|
Update of /cvsroot/rcpilot/rcgs/res/instruments In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12650 Removed Files: compass-face.gif panel.jpg Log Message: Removing rcgs all java source has been moved below src/rcpilot --- compass-face.gif DELETED --- --- panel.jpg DELETED --- |
From: Michael P. <mjp...@us...> - 2004-06-23 16:49:32
|
Update of /cvsroot/rcpilot/rcgs/res In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12589 Removed Files: Rcgs.properties Log Message: Removing rcgs all java source has been moved below src/rcpilot --- Rcgs.properties DELETED --- |
From: Michael P. <mjp...@us...> - 2004-06-23 16:49:07
|
Update of /cvsroot/rcpilot/rcgs/META-INF In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12495 Removed Files: AGWTEST.MF MANIFEST.MF TELDATA.MF TESTSERVER.MF Log Message: Removing rcgs all java source has been moved below src/rcpilot --- TELDATA.MF DELETED --- --- TESTSERVER.MF DELETED --- --- AGWTEST.MF DELETED --- --- MANIFEST.MF DELETED --- |
From: Michael P. <mjp...@us...> - 2004-06-23 16:48:30
|
Update of /cvsroot/rcpilot/rcgs/art In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12387 Removed Files: altimeter-photo.jpg altimeter.ai panel.ai panel2.ai variometer.ai Log Message: Removing rcgs all java source has been moved below src/rcpilot --- altimeter.ai DELETED --- --- panel.ai DELETED --- --- variometer.ai DELETED --- --- panel2.ai DELETED --- --- altimeter-photo.jpg DELETED --- |
From: Michael P. <mjp...@us...> - 2004-06-23 11:25:59
|
Update of /cvsroot/rcpilot/rcap/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7674 Modified Files: main.bas Log Message: Added 2004 to copyright Index: main.bas =================================================================== RCS file: /cvsroot/rcpilot/rcap/src/main.bas,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** main.bas 24 Feb 2004 12:35:55 -0000 1.2 --- main.bas 23 Jun 2004 11:25:50 -0000 1.3 *************** *** 1,3 **** ! ' Copyright 2003 Michael J. Pawlowsky ' ' This file is part of RCAP. --- 1,4 ---- ! ' ! ' Copyright 2003-2004 Michael J. Pawlowsky ' ' This file is part of RCAP. |
From: Michael P. <mjp...@us...> - 2004-04-10 11:14:55
|
Update of /cvsroot/rcpilot/rcpl/circuit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12656 Modified Files: rcpl.PCB Log Message: Moved hole on transistor and v. reg to make it easier for soldering. Index: rcpl.PCB =================================================================== RCS file: /cvsroot/rcpilot/rcpl/circuit/rcpl.PCB,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** rcpl.PCB 23 Feb 2004 17:16:36 -0000 1.2 --- rcpl.PCB 10 Apr 2004 11:01:23 -0000 1.3 *************** *** 1,176 **** PCB FILE 4 COMP ! R3 ! AXIAL0.3 ! ! 2899 2446 60 0 10 7 ! 3040 2372 39 0 10 7 ! 2930 2390 1 2 2 CP ! 3230 2390 62 62 1 28 1 13 [...1197 lines suppressed...] } NETDEF ! NET0 0 ( ! R1-2 ! Q2-3 ! D1-2 ! U2-1 ! C2-1 ! C3-2 ) { ! 1 6 0 ! 3 6 0 ! 2 3 0 ! 5 2 0 ! 4 5 0 } ENDPCB |