Package org.openstreetmap.josm.actions
Class CreateMultipolygonAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.CreateMultipolygonAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
,Destroyable
public class CreateMultipolygonAction extends JosmAction
Create multipolygon from selected ways automatically. New relation with type=multipolygon is created. If one or more of ways is already in relation with type=multipolygon or the way is not closed, then error is reported and no relation is created. The "inner" and "outer" roles are guessed automatically. First, bbox is calculated for each way. then the largest area is assumed to be outside and the rest inside. In cases with one "outside" area and several cut-ins, the guess should be always good ... In more complex (multiple outer areas) or buggy (inner and outer ways intersect) scenarios the result is likely to be wrong.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
CreateMultipolygonAction.CreateUpdateMultipolygonTask
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<java.lang.String>
DEFAULT_LINEAR_TAGS
private static int
MAX_MEMBERS_TO_DOWNLOAD
private boolean
update
-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Constructor Description CreateMultipolygonAction(boolean update)
Constructs a newCreateMultipolygonAction
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
static Pair<SequenceCommand,Relation>
createMultipolygonCommand(java.util.Collection<Way> selectedWays, Relation selectedMultipolygonRelation)
static Pair<Relation,Relation>
createMultipolygonRelation(java.util.Collection<Way> selectedWays, boolean showNotif)
private static java.lang.String
getName(boolean update)
private static Relation
getSelectedMultipolygonRelation(java.util.Collection<Way> selectedWays, java.util.Collection<Relation> selectedRelations)
private static Pair<Relation,Relation>
mergeRelationsMembers(Relation old, Relation calculated)
Merge members of multipolygon relation.static java.util.List<Command>
removeTagsFromWaysIfNeeded(Relation relation)
This method removes tags/value pairs from inner and outer ways and put them on relation if necessary.private static void
showErrors(java.util.List<TestError> errors)
protected void
updateEnabledState()
Enable this action only if something is selectedprotected void
updateEnabledState(java.util.Collection<? extends OsmPrimitive> selection)
Enable this action only if something is selectedstatic Pair<Relation,Relation>
updateMultipolygonRelation(java.util.Collection<Way> selectedWays, Relation selectedMultipolygonRelation)
-
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
buildActiveLayerChangeAdapter, buildLayerChangeAdapter, checkAndConfirmOutlyingOperation, destroy, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setToolbarId, setTooltip, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFuture
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
-
-
-
Field Detail
-
update
private final boolean update
-
MAX_MEMBERS_TO_DOWNLOAD
private static final int MAX_MEMBERS_TO_DOWNLOAD
- See Also:
- Constant Field Values
-
DEFAULT_LINEAR_TAGS
private static final java.util.List<java.lang.String> DEFAULT_LINEAR_TAGS
-
-
Constructor Detail
-
CreateMultipolygonAction
public CreateMultipolygonAction(boolean update)
Constructs a newCreateMultipolygonAction
.- Parameters:
update
-true
if the multipolygon must be updated,false
if it must be created
-
-
Method Detail
-
getName
private static java.lang.String getName(boolean update)
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
-
getSelectedMultipolygonRelation
private static Relation getSelectedMultipolygonRelation(java.util.Collection<Way> selectedWays, java.util.Collection<Relation> selectedRelations)
-
updateMultipolygonRelation
public static Pair<Relation,Relation> updateMultipolygonRelation(java.util.Collection<Way> selectedWays, Relation selectedMultipolygonRelation)
Returns aPair
of the old multipolygonRelation
(or null) and the newly created/modified multipolygonRelation
.- Parameters:
selectedWays
- selected waysselectedMultipolygonRelation
- selected multipolygon relation- Returns:
- null if ways don't build a valid multipolygon, pair of old and new multipolygon relation if a difference was found, else the pair contains the old relation twice
-
mergeRelationsMembers
private static Pair<Relation,Relation> mergeRelationsMembers(Relation old, Relation calculated)
Merge members of multipolygon relation. Maintains the order of the old relation. May change roles, removes duplicate and non-way members and adds new members found incalculated
.- Parameters:
old
- old multipolygon relationcalculated
- calculated multipolygon relation- Returns:
- pair of old and new multipolygon relation if a difference was found, else the pair contains the old relation twice
-
createMultipolygonRelation
public static Pair<Relation,Relation> createMultipolygonRelation(java.util.Collection<Way> selectedWays, boolean showNotif)
- Parameters:
selectedWays
- selected waysshowNotif
- iftrue
, shows a notification if an error occurs- Returns:
- pair of null and new multipolygon relation
-
showErrors
private static void showErrors(java.util.List<TestError> errors)
-
createMultipolygonCommand
public static Pair<SequenceCommand,Relation> createMultipolygonCommand(java.util.Collection<Way> selectedWays, Relation selectedMultipolygonRelation)
- Parameters:
selectedWays
- selected waysselectedMultipolygonRelation
- selected multipolygon relation- Returns:
- pair of command and multipolygon relation
-
updateEnabledState
protected void updateEnabledState()
Enable this action only if something is selected- Overrides:
updateEnabledState
in classJosmAction
- See Also:
JosmAction.updateEnabledState(Collection)
,JosmAction.initEnabledState()
,JosmAction.listenToLayerChange()
-
updateEnabledState
protected void updateEnabledState(java.util.Collection<? extends OsmPrimitive> selection)
Enable this action only if something is selected- Overrides:
updateEnabledState
in classJosmAction
- Parameters:
selection
- the current selection, gets tested for emptiness- See Also:
JosmAction.updateEnabledState()
,JosmAction.initEnabledState()
,JosmAction.listenToSelectionChange()
-
removeTagsFromWaysIfNeeded
public static java.util.List<Command> removeTagsFromWaysIfNeeded(Relation relation)
This method removes tags/value pairs from inner and outer ways and put them on relation if necessary. Function was extended in reltoolbox plugin by Zverikk and copied back to the core- Parameters:
relation
- the multipolygon style relation to process. If it not linked to a dataset, the tags might be modified, else the list of commands will contain a command to modify its tags- Returns:
- a list of commands to execute
-
-