Changeset 27842 in osm for applications
- Timestamp:
- 2012-02-17T19:56:48+01:00 (13 years ago)
- Location:
- applications/editors/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/public_transport/src/public_transport/RoutePatternAction.java
r26582 r27842 286 286 } 287 287 288 public void addRow(Node node, String role ) {289 insertRow(-1, node, role );290 } 291 292 public void insertRow(int insPos, Node node, String role ) {293 String[] buf = { "", "", "" };288 public void addRow(Node node, String role, double distance) { 289 insertRow(-1, node, role, distance); 290 } 291 292 public void insertRow(int insPos, Node node, String role, double distance) { 293 String[] buf = { "", "", "", "" }; 294 294 String curName = node.get("name"); 295 295 if (curName != null) … … 307 307 } 308 308 buf[STOPLIST_ROLE_COLUMN] = role; 309 buf[3] = Double.toString(((double)(int)(distance*40000/360.0*100))/100); 310 309 311 if (insPos == -1) 310 312 { … … 340 342 public double length; 341 343 public double d1, d2, o1, o2; 342 343 public SegmentMetric(double fromLat, double fromLon, double toLat, double toLon) { 344 public double distance; 345 346 public SegmentMetric(double fromLat, double fromLon, double toLat, double toLon, 347 double distance) { 348 this.distance = distance; 349 344 350 aLat = fromLat; 345 351 aLon = fromLon; … … 415 421 private static JTextField tfSuggestStopsLimit = null; 416 422 private static Relation currentRoute = null; 423 private static Vector< SegmentMetric > segmentMetrics = null; 417 424 private static Vector< RelationMember > markedWays = new Vector< RelationMember >(); 418 425 private static Vector< RelationMember > markedNodes = new Vector< RelationMember >(); … … 863 870 stoplistData.addColumn(tr("Ref")); 864 871 stoplistData.addColumn(tr("Role")); 872 stoplistData.addColumn(tr("km")); 865 873 stoplistTable.setModel(stoplistData); 866 874 /*JScrollPane*/ tableSP = new JScrollPane(stoplistTable); … … 1286 1294 1287 1295 itineraryData.cleanupGaps(); 1296 segmentMetrics = fillSegmentMetrics(); 1288 1297 rebuildWays(); 1289 1298 } … … 1300 1309 1301 1310 itineraryData.cleanupGaps(); 1311 segmentMetrics = fillSegmentMetrics(); 1302 1312 rebuildWays(); 1303 1313 } … … 1377 1387 1378 1388 itineraryData.cleanupGaps(); 1389 segmentMetrics = fillSegmentMetrics(); 1379 1390 rebuildWays(); 1380 1391 } … … 1444 1455 1445 1456 itineraryData.cleanupGaps(); 1457 segmentMetrics = fillSegmentMetrics(); 1446 1458 rebuildWays(); 1447 1459 } … … 1529 1541 if ((curMember.isNode()) && (mainDataSet.isSelected(curMember.getNode()))) 1530 1542 { 1531 stoplistData.insertRow(insPos, curMember.getNode(), curMember.getRole()); 1543 StopReference sr = detectMinDistance 1544 (curMember.getNode(), segmentMetrics, cbRight.isSelected(), cbLeft.isSelected()); 1545 double offset = segmentMetrics.elementAt((sr.index+1) / 2).distance; 1546 if (sr.index % 2 == 0) 1547 offset += sr.pos; 1548 stoplistData.insertRow(insPos, curMember.getNode(), curMember.getRole(), offset); 1532 1549 if (insPos >= 0) 1533 1550 ++insPos; … … 1545 1562 if (!(addedNodes.contains(curMember))) 1546 1563 { 1547 stoplistData.insertRow(insPos, curMember, ""); 1564 StopReference sr = detectMinDistance 1565 (curMember, segmentMetrics, cbRight.isSelected(), cbLeft.isSelected()); 1566 double offset = segmentMetrics.elementAt((sr.index+1) / 2).distance; 1567 if (sr.index % 2 == 0) 1568 offset += sr.pos; 1569 stoplistData.insertRow(insPos, curMember, "", offset); 1548 1570 if (insPos >= 0) 1549 1571 ++insPos; … … 1580 1602 // Prepare Segments: The segments of all usable ways are arranged in a linear 1581 1603 // list such that a coor can directly be checked concerning position and offset 1582 Vector<SegmentMetric> segmentMetrics = new Vector<SegmentMetric>();1583 for (int i = 0; i < itineraryData.getRowCount(); ++i)1584 {1585 if (itineraryData.ways.elementAt(i) != null)1586 {1587 Way way = itineraryData.ways.elementAt(i);1588 if (!(way.isIncomplete()))1589 {1590 if ("backward".equals((String)(itineraryData.getValueAt(i, 1))))1591 {1592 for (int j = way.getNodesCount()-2; j >= 0; --j)1593 {1594 SegmentMetric sm = new SegmentMetric1595 (way.getNode(j+1).getCoor().lat(), way.getNode(j+1).getCoor().lon(),1596 way.getNode(j).getCoor().lat(), way.getNode(j).getCoor().lon());1597 segmentMetrics.add(sm);1598 }1599 }1600 else1601 {1602 for (int j = 0; j < way.getNodesCount()-1; ++j)1603 {1604 SegmentMetric sm = new SegmentMetric1605 (way.getNode(j).getCoor().lat(), way.getNode(j).getCoor().lon(),1606 way.getNode(j+1).getCoor().lat(), way.getNode(j+1).getCoor().lon());1607 segmentMetrics.add(sm);1608 }1609 }1610 }1611 }1612 else1613 {1614 segmentMetrics.add(null);1615 }1616 }1617 1618 1604 Vector< StopReference > srm = new Vector< StopReference >(); 1619 1605 int insPos = stoplistTable.getSelectedRow(); … … 1686 1672 for (int i = 0; i < srm.size(); ++i) 1687 1673 { 1688 stoplistData.insertRow(insPos, srm.elementAt(i).node, srm.elementAt(i).role); 1674 StopReference sr = detectMinDistance 1675 (srm.elementAt(i).node, segmentMetrics, cbRight.isSelected(), cbLeft.isSelected()); 1676 double offset = segmentMetrics.elementAt((sr.index+1) / 2).distance; 1677 if (sr.index % 2 == 0) 1678 offset += sr.pos; 1679 stoplistData.insertRow(insPos, srm.elementAt(i).node, srm.elementAt(i).role, offset); 1689 1680 if (insPos >= 0) 1690 1681 ++insPos; … … 1695 1686 else if ("routePattern.stoplistReflect".equals(event.getActionCommand())) 1696 1687 { 1697 Vector<RelationMember> itemsToReflect = new Vector<RelationMember>(); 1688 Vector< RelationMember > itemsToReflect = new Vector< RelationMember >(); 1689 Vector< Double > distancesToReflect = new Vector< Double >(); 1698 1690 int insPos = stoplistTable.getSelectedRow(); 1699 1691 … … 1706 1698 String role = (String)(stoplistData.getValueAt(i, STOPLIST_ROLE_COLUMN)); 1707 1699 RelationMember markedNode = new RelationMember 1708 (role, stoplistData.nodes.elementAt(i));1700 (role, stoplistData.nodes.elementAt(i)); 1709 1701 itemsToReflect.addElement(markedNode); 1710 1702 … … 1734 1726 if (curMember.isNode()) 1735 1727 { 1736 stoplistData.insertRow(insPos, curMember.getNode(), curMember.getRole()); 1728 StopReference sr = detectMinDistance 1729 (curMember.getNode(), segmentMetrics, cbRight.isSelected(), cbLeft.isSelected()); 1730 double offset = segmentMetrics.elementAt((sr.index+1) / 2).distance; 1731 if (sr.index % 2 == 0) 1732 offset += sr.pos; 1733 stoplistData.insertRow(insPos, curMember.getNode(), curMember.getRole(), offset); 1737 1734 if (insPos >= 0) 1738 1735 ++insPos; … … 1748 1745 // Prepare Segments: The segments of all usable ways are arranged in a linear 1749 1746 // list such that a coor can directly be checked concerning position and offset 1750 Vector<SegmentMetric> segmentMetrics = new Vector<SegmentMetric>();1751 for (int i = 0; i < itineraryData.getRowCount(); ++i)1752 {1753 if (itineraryData.ways.elementAt(i) != null)1754 {1755 Way way = itineraryData.ways.elementAt(i);1756 if (!(way.isIncomplete()))1757 {1758 if ("backward".equals((String)(itineraryData.getValueAt(i, 1))))1759 {1760 for (int j = way.getNodesCount()-2; j >= 0; --j)1761 {1762 SegmentMetric sm = new SegmentMetric1763 (way.getNode(j+1).getCoor().lat(), way.getNode(j+1).getCoor().lon(),1764 way.getNode(j).getCoor().lat(), way.getNode(j).getCoor().lon());1765 segmentMetrics.add(sm);1766 }1767 }1768 else1769 {1770 for (int j = 0; j < way.getNodesCount()-1; ++j)1771 {1772 SegmentMetric sm = new SegmentMetric1773 (way.getNode(j).getCoor().lat(), way.getNode(j).getCoor().lon(),1774 way.getNode(j+1).getCoor().lat(), way.getNode(j+1).getCoor().lon());1775 segmentMetrics.add(sm);1776 }1777 }1778 }1779 }1780 else1781 {1782 segmentMetrics.add(null);1783 }1784 }1785 1786 1747 Vector< StopReference > srm = new Vector< StopReference >(); 1787 1748 // Determine for each member its position on the itinerary: position means here the … … 1848 1809 } 1849 1810 1850 /*for (int i = 0; i < stoplistData.getRowCount(); ++i)1851 {1852 }*/1853 1854 1811 Collections.sort(srm); 1855 1812 … … 1857 1814 for (int i = 0; i < srm.size(); ++i) 1858 1815 { 1859 stoplistData.addRow(srm.elementAt(i).node, srm.elementAt(i).role); 1816 StopReference sr = detectMinDistance 1817 (srm.elementAt(i).node, segmentMetrics, cbRight.isSelected(), cbLeft.isSelected()); 1818 double offset = segmentMetrics.elementAt((sr.index+1) / 2).distance; 1819 if (sr.index % 2 == 0) 1820 offset += sr.pos; 1821 stoplistData.addRow(srm.elementAt(i).node, srm.elementAt(i).role, offset); 1860 1822 } 1861 1823 … … 2142 2104 } 2143 2105 itineraryData.cleanupGaps(); 2106 segmentMetrics = fillSegmentMetrics(); 2144 2107 } 2145 2108 … … 2151 2114 if (curMember.isNode()) 2152 2115 { 2153 stoplistData.insertRow(insPos, curMember.getNode(), curMember.getRole()); 2154 if (insPos >= 0) 2155 ++insPos; 2156 } 2157 } 2116 StopReference sr = detectMinDistance 2117 (curMember.getNode(), segmentMetrics, cbRight.isSelected(), cbLeft.isSelected()); 2118 double offset = segmentMetrics.elementAt((sr.index+1) / 2).distance; 2119 System.out.print(sr.index); 2120 System.out.print(" "); 2121 System.out.print(offset); 2122 System.out.print(" "); 2123 System.out.println(sr.pos); 2124 if (sr.index % 2 == 0) 2125 offset += sr.pos; 2126 stoplistData.insertRow(insPos, curMember.getNode(), curMember.getRole(), offset); 2127 if (insPos >= 0) 2128 ++insPos; 2129 } 2130 } 2131 } 2132 2133 private Vector< SegmentMetric > fillSegmentMetrics() 2134 { 2135 Vector< SegmentMetric > segmentMetrics = new Vector< SegmentMetric >(); 2136 double distance = 0; 2137 for (int i = 0; i < itineraryData.getRowCount(); ++i) 2138 { 2139 if (itineraryData.ways.elementAt(i) != null) 2140 { 2141 Way way = itineraryData.ways.elementAt(i); 2142 if (!(way.isIncomplete())) 2143 { 2144 if ("backward".equals((String)(itineraryData.getValueAt(i, 1)))) 2145 { 2146 for (int j = way.getNodesCount()-2; j >= 0; --j) 2147 { 2148 SegmentMetric sm = new SegmentMetric 2149 (way.getNode(j+1).getCoor().lat(), way.getNode(j+1).getCoor().lon(), 2150 way.getNode(j).getCoor().lat(), way.getNode(j).getCoor().lon(), distance); 2151 segmentMetrics.add(sm); 2152 distance += sm.length; 2153 } 2154 } 2155 else 2156 { 2157 for (int j = 0; j < way.getNodesCount()-1; ++j) 2158 { 2159 SegmentMetric sm = new SegmentMetric 2160 (way.getNode(j).getCoor().lat(), way.getNode(j).getCoor().lon(), 2161 way.getNode(j+1).getCoor().lat(), way.getNode(j+1).getCoor().lon(), distance); 2162 segmentMetrics.add(sm); 2163 distance += sm.length; 2164 } 2165 } 2166 } 2167 } 2168 else 2169 segmentMetrics.add(null); 2170 } 2171 return segmentMetrics; 2158 2172 } 2159 2173 … … 2161 2175 (Node node, Vector< SegmentMetric > segmentMetrics, 2162 2176 boolean rhsPossible, boolean lhsPossible) { 2177 if (node == null) 2178 return null; 2179 2163 2180 int minIndex = -1; 2164 2181 double position = -1.0;
Note:
See TracChangeset
for help on using the changeset viewer.