-
Notifications
You must be signed in to change notification settings - Fork 14
Extract relation #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
floscher
wants to merge
53
commits into
master
Choose a base branch
from
extract_relation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Extract relation #26
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 7d0ad20
Added code to
PolyglotOpenstreetmap 3da4860
Added code to
PolyglotOpenstreetmap 12411a3
Now it works the way I wanted it to work. I'll keep testing it more t…
PolyglotOpenstreetmap ce6106d
I succeeded in making it work the way I want and I incorporated Flori…
PolyglotOpenstreetmap e3ff059
The relation wasn't added if member 1-... were selected, so if the fi…
PolyglotOpenstreetmap 7616d42
refactored to extract the methods that do the work. I may want to use…
PolyglotOpenstreetmap 4d1af91
renamed bus.png to bus. It's not a bus.svg, which is detected automat…
PolyglotOpenstreetmap eca82d5
refactored, it works OK most of the time, but when extracting from a …
PolyglotOpenstreetmap 92e1bab
Sometimes there is an exception. What I find odd is that this happens…
PolyglotOpenstreetmap 0d4b9d9
If the route relation that is divide into 2 route relations is alread…
PolyglotOpenstreetmap 10955a9
It worked almost the way I wanted it at some point. Trying to iron ou…
PolyglotOpenstreetmap f96c6de
Add custom icon for the extract relation action
floscher da27d28
I got it back to a point that I'm almost happy with the result. Some …
PolyglotOpenstreetmap 01d9ea2
it's somewhat stable now, although there are still many things that d…
PolyglotOpenstreetmap ec66b9d
I didn't like the nondescript A and B from Pair, so I created a new C…
PolyglotOpenstreetmap d36c864
Changed colours and lineIdentifiers to TreeSet. lineIdentifiers need …
PolyglotOpenstreetmap 1feb68c
No need to user .contains anymore, now that it's using TreeSet
PolyglotOpenstreetmap 1443a9a
I fixed the problem where identical sub route relations where created…
PolyglotOpenstreetmap 74b0e75
some reshuffling and minor changes
PolyglotOpenstreetmap acec22f
removed some code duplication
PolyglotOpenstreetmap 2b6b7f4
removed code duplication in those 3 constructors. Now there are 4 of …
PolyglotOpenstreetmap 69f8bdd
added some Javadoc
PolyglotOpenstreetmap 68654bf
Create unit test for extracting PT segment
PolyglotOpenstreetmap 0c178a8
Rename PTSegmentToExtract to RouteSegmentToExtract
floscher ccf71f5
created unit test for bus line 601. It's a circular line, which reuse…
PolyglotOpenstreetmap e4a522d
I removed the code from the Action file, it's now in the RouteSegment…
PolyglotOpenstreetmap a1ef4f9
Wrote test cases for 1 complete itinerary and started on cases for an…
PolyglotOpenstreetmap 5372fa0
renamed WayTriplet to WaySequence as it can contain 4 consecutive way…
PolyglotOpenstreetmap 742265a
All the unit tests are working up to this point. Rewrote isItineraryI…
PolyglotOpenstreetmap deb7c6d
Added some more unit tests and needed to check that if one of the par…
PolyglotOpenstreetmap 28f11b6
Added a lookup for itineraryWays per relation, so it only needs to be…
PolyglotOpenstreetmap 4bd2b71
In some cases the membershipcount is needed of all the (parent) route…
PolyglotOpenstreetmap 4bcfa3f
Added another line, which has variants with an extra spoon, which nee…
PolyglotOpenstreetmap af2ab8c
Added connectivity checks to WaySequence and wrote JavaDoc for its me…
PolyglotOpenstreetmap 04acfb0
I have no idea how to resolve this exception. It always complains abo…
PolyglotOpenstreetmap d33a855
as route relations get converted to superroute relations, sub route r…
PolyglotOpenstreetmap 5448f8f
Added tests for cycle route.
PolyglotOpenstreetmap 41a9649
Rewrote the entire test suite. It works with an array of known values…
PolyglotOpenstreetmap 11a99a3
During live testing I get an Index out of bounds exception, when proc…
PolyglotOpenstreetmap 6b01f01
Moved isItineraryInSameDirection to WaySequence class.
PolyglotOpenstreetmap 977d54d
Some refactoring
PolyglotOpenstreetmap dbdd778
resolved some warnings from IntelliJ
PolyglotOpenstreetmap 4c3ce56
Simplify dataset loading in RouteSegmentToExtractTest
floscher f66483b
Tried to sanitize the RouteSegmentToExtractTest class. I didn't test …
PolyglotOpenstreetmap 2b52d4d
Some changes made while doing pair programming with Florian.
PolyglotOpenstreetmap 12158e8
Running the loop down to 0 seems to work better when splitting in seg…
PolyglotOpenstreetmap 5e6e728
Changed the order of creation of clonedRelation. The way it was, it w…
PolyglotOpenstreetmap d8e83b5
Merge master branch into extract_relation
floscher 4305ff8
reduced file size of test file to 5.5 MB by purging ways. The relatio…
PolyglotOpenstreetmap 616e955
Reworked the tests. For removing members from a relation, it makes mo…
PolyglotOpenstreetmap ac95d6d
In ExtractRelationMembersToNewRelationAction I made an attempt to get…
PolyglotOpenstreetmap 0355688
It seems like I succeeded in suppressing the IndexOutOfBounds excepti…
PolyglotOpenstreetmap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...treetmap/josm/plugins/pt_assistant/actions/ExtractRelationMembersToNewRelationAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| boolean flag = true; | ||
|
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); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.