Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
964b254
Add action to extract new relation from a subset of members of an exi…
floscher Aug 24, 2020
7d0ad20
Added code to
PolyglotOpenstreetmap Aug 24, 2020
3da4860
Added code to
PolyglotOpenstreetmap Aug 24, 2020
12411a3
Now it works the way I wanted it to work. I'll keep testing it more t…
PolyglotOpenstreetmap Aug 24, 2020
ce6106d
I succeeded in making it work the way I want and I incorporated Flori…
PolyglotOpenstreetmap Aug 26, 2020
e3ff059
The relation wasn't added if member 1-... were selected, so if the fi…
PolyglotOpenstreetmap Aug 26, 2020
7616d42
refactored to extract the methods that do the work. I may want to use…
PolyglotOpenstreetmap Aug 26, 2020
4d1af91
renamed bus.png to bus. It's not a bus.svg, which is detected automat…
PolyglotOpenstreetmap Aug 26, 2020
eca82d5
refactored, it works OK most of the time, but when extracting from a …
PolyglotOpenstreetmap Aug 27, 2020
92e1bab
Sometimes there is an exception. What I find odd is that this happens…
PolyglotOpenstreetmap Sep 8, 2020
0d4b9d9
If the route relation that is divide into 2 route relations is alread…
PolyglotOpenstreetmap Sep 9, 2020
10955a9
It worked almost the way I wanted it at some point. Trying to iron ou…
PolyglotOpenstreetmap Sep 15, 2020
f96c6de
Add custom icon for the extract relation action
floscher Sep 15, 2020
da27d28
I got it back to a point that I'm almost happy with the result. Some …
PolyglotOpenstreetmap Sep 17, 2020
01d9ea2
it's somewhat stable now, although there are still many things that d…
PolyglotOpenstreetmap Sep 18, 2020
ec66b9d
I didn't like the nondescript A and B from Pair, so I created a new C…
PolyglotOpenstreetmap Sep 20, 2020
d36c864
Changed colours and lineIdentifiers to TreeSet. lineIdentifiers need …
PolyglotOpenstreetmap Sep 20, 2020
1feb68c
No need to user .contains anymore, now that it's using TreeSet
PolyglotOpenstreetmap Sep 20, 2020
1443a9a
I fixed the problem where identical sub route relations where created…
PolyglotOpenstreetmap Sep 20, 2020
74b0e75
some reshuffling and minor changes
PolyglotOpenstreetmap Sep 20, 2020
acec22f
removed some code duplication
PolyglotOpenstreetmap Sep 21, 2020
2b6b7f4
removed code duplication in those 3 constructors. Now there are 4 of …
PolyglotOpenstreetmap Sep 21, 2020
69f8bdd
added some Javadoc
PolyglotOpenstreetmap Sep 21, 2020
68654bf
Create unit test for extracting PT segment
PolyglotOpenstreetmap Sep 21, 2020
0c178a8
Rename PTSegmentToExtract to RouteSegmentToExtract
floscher Oct 27, 2020
ccf71f5
created unit test for bus line 601. It's a circular line, which reuse…
PolyglotOpenstreetmap Sep 27, 2020
e4a522d
I removed the code from the Action file, it's now in the RouteSegment…
PolyglotOpenstreetmap Sep 27, 2020
a1ef4f9
Wrote test cases for 1 complete itinerary and started on cases for an…
PolyglotOpenstreetmap Oct 1, 2020
5372fa0
renamed WayTriplet to WaySequence as it can contain 4 consecutive way…
PolyglotOpenstreetmap Oct 1, 2020
742265a
All the unit tests are working up to this point. Rewrote isItineraryI…
PolyglotOpenstreetmap Oct 5, 2020
deb7c6d
Added some more unit tests and needed to check that if one of the par…
PolyglotOpenstreetmap Oct 6, 2020
28f11b6
Added a lookup for itineraryWays per relation, so it only needs to be…
PolyglotOpenstreetmap Oct 7, 2020
4bd2b71
In some cases the membershipcount is needed of all the (parent) route…
PolyglotOpenstreetmap Oct 8, 2020
4bcfa3f
Added another line, which has variants with an extra spoon, which nee…
PolyglotOpenstreetmap Oct 10, 2020
af2ab8c
Added connectivity checks to WaySequence and wrote JavaDoc for its me…
PolyglotOpenstreetmap Oct 11, 2020
04acfb0
I have no idea how to resolve this exception. It always complains abo…
PolyglotOpenstreetmap Oct 16, 2020
d33a855
as route relations get converted to superroute relations, sub route r…
PolyglotOpenstreetmap Oct 16, 2020
5448f8f
Added tests for cycle route.
PolyglotOpenstreetmap Oct 16, 2020
41a9649
Rewrote the entire test suite. It works with an array of known values…
PolyglotOpenstreetmap Oct 20, 2020
11a99a3
During live testing I get an Index out of bounds exception, when proc…
PolyglotOpenstreetmap Oct 21, 2020
6b01f01
Moved isItineraryInSameDirection to WaySequence class.
PolyglotOpenstreetmap Oct 23, 2020
977d54d
Some refactoring
PolyglotOpenstreetmap Oct 23, 2020
dbdd778
resolved some warnings from IntelliJ
PolyglotOpenstreetmap Oct 23, 2020
4c3ce56
Simplify dataset loading in RouteSegmentToExtractTest
floscher Oct 27, 2020
f66483b
Tried to sanitize the RouteSegmentToExtractTest class. I didn't test …
PolyglotOpenstreetmap Oct 23, 2020
2b52d4d
Some changes made while doing pair programming with Florian.
PolyglotOpenstreetmap Oct 23, 2020
12158e8
Running the loop down to 0 seems to work better when splitting in seg…
PolyglotOpenstreetmap Oct 23, 2020
5e6e728
Changed the order of creation of clonedRelation. The way it was, it w…
PolyglotOpenstreetmap Oct 25, 2020
d8e83b5
Merge master branch into extract_relation
floscher Oct 28, 2020
4305ff8
reduced file size of test file to 5.5 MB by purging ways. The relatio…
PolyglotOpenstreetmap Oct 29, 2020
616e955
Reworked the tests. For removing members from a relation, it makes mo…
PolyglotOpenstreetmap Nov 2, 2020
ac95d6d
In ExtractRelationMembersToNewRelationAction I made an attempt to get…
PolyglotOpenstreetmap Nov 4, 2020
0355688
It seems like I succeeded in suppressing the IndexOutOfBounds excepti…
PolyglotOpenstreetmap Nov 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,7 @@
import org.openstreetmap.josm.plugins.Plugin;
import org.openstreetmap.josm.plugins.PluginInformation;
import org.openstreetmap.josm.plugins.customizepublictransportstop.CustomizeStopAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.AddStopPositionAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformNodeAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformNodeThroughReplaceAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformShortcutAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.DoubleSplitAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.EdgeSelectionAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.ExtractPlatformNodeAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.PTWizardAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.RoutingAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.SortPTRouteMembersAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.SortPTRouteMembersMenuBar;
import org.openstreetmap.josm.plugins.pt_assistant.actions.SplitRoundaboutAction;
import org.openstreetmap.josm.plugins.pt_assistant.actions.*;
import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment;
import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayerManager;
import org.openstreetmap.josm.plugins.pt_assistant.validation.BicycleFootRouteValidatorTest;
Expand Down Expand Up @@ -191,7 +180,8 @@ public int order() {

@Override
public List<AbstractRelationEditorAction> getActions(IRelationEditorActionAccess editorAccess) {
return Arrays.asList(new SortPTRouteMembersAction(editorAccess));
return Arrays.asList(new SortPTRouteMembersAction(editorAccess),
new ExtractRelationMembersToNewRelationAction(editorAccess));
}
};
RelationEditorHooks.addActionsToMembers(group1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.openstreetmap.josm.plugins.pt_assistant.actions;

import java.awt.event.ActionEvent;
import java.util.*;

import javax.swing.JOptionPane;

import org.openstreetmap.josm.command.AddCommand;
import org.openstreetmap.josm.command.ChangeCommand;
import org.openstreetmap.josm.data.UndoRedoHandler;
import org.openstreetmap.josm.data.osm.Relation;
import org.openstreetmap.josm.data.osm.RelationMember;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
import org.openstreetmap.josm.gui.dialogs.relation.actions.AbstractRelationEditorAction;
import org.openstreetmap.josm.gui.dialogs.relation.actions.IRelationEditorActionAccess;
import org.openstreetmap.josm.gui.dialogs.relation.actions.IRelationEditorUpdateOn;
import org.openstreetmap.josm.tools.I18n;
import org.openstreetmap.josm.tools.ImageProvider;

import static org.openstreetmap.josm.gui.MainApplication.*;

public class ExtractRelationMembersToNewRelationAction extends AbstractRelationEditorAction {
public ExtractRelationMembersToNewRelationAction(IRelationEditorActionAccess editorAccess) {
super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE, IRelationEditorUpdateOn.TAG_CHANGE);
new ImageProvider("bus").getResource().attachImageIcon(this);
}

@Override
public void actionPerformed(ActionEvent actionEvent) {
final Collection<RelationMember> selectedMembers = editorAccess.getMemberTableModel().getSelectedMembers();
final Map<String, String> tags = editorAccess.getTagModel().getTags();
final Relation originalRelation = editorAccess.getEditor().getRelation();


if (
JOptionPane.showConfirmDialog(
getMemberTable(),
I18n.tr(
"Do you really want to create a new relation from the {0} selected members of relation {1}, copying the {2} tags to the new relation?",
selectedMembers.size(),
getEditor().getRelation().getId(),
tags.size()
),
I18n.tr("Extract part from relation?"),
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE
) == JOptionPane.OK_OPTION
) {
final Relation extractedRelation = new Relation();
extractedRelation.setKeys(tags);
UndoRedoHandler.getInstance().add(new AddCommand(getLayerManager().getActiveDataSet(), extractedRelation));
final Relation newExtractedRelation = new Relation(extractedRelation);
Comment thread
PolyglotOpenstreetmap marked this conversation as resolved.
Outdated
boolean flag = true;
Comment thread
PolyglotOpenstreetmap marked this conversation as resolved.
Outdated

Relation newRelation = new Relation(originalRelation);
List<RelationMember> members = newRelation.getMembers();
for (int i = members.size()-1; i >= 0; i--) {
RelationMember member = members.get(i);
if (selectedMembers.contains(member)) {
newExtractedRelation.addMember(0, member);
newRelation.removeMember(i);
if (flag) {
newRelation.addMember(i, new RelationMember("", extractedRelation));
flag = false;
}
}
}
newExtractedRelation.put("type", "route");

UndoRedoHandler.getInstance().add(new ChangeCommand(originalRelation, newRelation));
UndoRedoHandler.getInstance().add(new ChangeCommand(extractedRelation, newExtractedRelation));
editorAccess.getEditor().reloadDataFromRelation();
RelationEditor.getEditor(getEditor().getLayer(), extractedRelation, Collections.emptyList()).setVisible(true);
}
}

@Override
public boolean isExpertOnly() {
return true;
}

@Override
protected void updateEnabledState() {
final boolean newEnabledState = !editorAccess.getSelectionTableModel().getSelection().isEmpty()
&& Optional.ofNullable(editorAccess.getTagModel().get("type")).filter(it -> "route".equals(it.getValue())).isPresent();

putValue(SHORT_DESCRIPTION, (
newEnabledState
? I18n.tr("Extract part of the route into new relation")
: I18n.tr("Extract into new relation (needs type=route tag and at least one selected relation member)")
));
setEnabled(newEnabledState);
}
}