From 3c0b926ec76f673bc237c3269b5b5704befaec2b Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Sat, 21 Mar 2020 14:23:44 -0700 Subject: [PATCH] Replace coreContext.geometry function with a more explicit coreGraph.geometry function --- modules/behavior/draw_way.js | 2 +- modules/core/context.js | 1 - modules/core/graph.js | 5 +++++ modules/modes/move.js | 2 +- modules/modes/rotate.js | 2 +- modules/modes/select.js | 4 ++-- modules/operations/delete.js | 4 ++-- modules/operations/disconnect.js | 9 +++++---- modules/operations/extract.js | 2 +- modules/operations/move.js | 2 +- modules/operations/orthogonalize.js | 2 +- modules/operations/rotate.js | 2 +- modules/operations/split.js | 6 +++--- modules/ui/feature_list.js | 2 +- modules/ui/fields/combo.js | 2 +- modules/ui/preset_list.js | 2 +- modules/ui/sections/feature_type.js | 2 +- modules/ui/sections/raw_member_editor.js | 2 +- modules/ui/sections/raw_membership_editor.js | 2 +- modules/ui/sections/raw_tag_editor.js | 2 +- modules/ui/sections/selection_list.js | 2 +- test/spec/operations/extract.js | 1 - 22 files changed, 32 insertions(+), 28 deletions(-) diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 421eb0ef8..2d52d9311 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -25,7 +25,7 @@ export function behaviorDrawWay(context, wayID, index, mode, startGraph) { var _annotation = t((_origWay.isDegenerate() ? 'operations.start.annotation.' : - 'operations.continue.annotation.') + context.geometry(wayID) + 'operations.continue.annotation.') + _origWay.geometry(context.graph()) ); var behavior = behaviorDraw(context); diff --git a/modules/core/context.js b/modules/core/context.js index b32cb4df7..ba0161278 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -247,7 +247,6 @@ export function coreContext() { /* Graph */ context.hasEntity = (id) => _history.graph().hasEntity(id); context.entity = (id) => _history.graph().entity(id); - context.geometry = (id) => context.entity(id).geometry(_history.graph()); /* Modes */ diff --git a/modules/core/graph.js b/modules/core/graph.js index e746d962f..2d426b323 100644 --- a/modules/core/graph.js +++ b/modules/core/graph.js @@ -46,6 +46,11 @@ coreGraph.prototype = { }, + geometry: function(id) { + return this.entity(id).geometry(this); + }, + + transient: function(entity, key, fn) { var id = entity.id; var transients = this.transients[id] || (this.transients[id] = {}); diff --git a/modules/modes/move.js b/modules/modes/move.js index 1405f0d47..d91a85d4f 100644 --- a/modules/modes/move.js +++ b/modules/modes/move.js @@ -38,7 +38,7 @@ export function modeMove(context, entityIDs, baseGraph) { operationRotate(entityIDs, context).behavior ]; var annotation = entityIDs.length === 1 ? - t('operations.move.annotation.' + context.geometry(entityIDs[0])) : + t('operations.move.annotation.' + context.graph().geometry(entityIDs[0])) : t('operations.move.annotation.multiple'); var _prevGraph; diff --git a/modules/modes/rotate.js b/modules/modes/rotate.js index 4b1e26927..53080a27b 100644 --- a/modules/modes/rotate.js +++ b/modules/modes/rotate.js @@ -42,7 +42,7 @@ export function modeRotate(context, entityIDs) { operationReflectShort(entityIDs, context).behavior ]; var annotation = entityIDs.length === 1 ? - t('operations.rotate.annotation.' + context.geometry(entityIDs[0])) : + t('operations.rotate.annotation.' + context.graph().geometry(entityIDs[0])) : t('operations.rotate.annotation.multiple'); var _prevGraph; diff --git a/modules/modes/select.js b/modules/modes/select.js index bddae3a63..accb768c7 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -156,7 +156,7 @@ export function modeSelect(context, selectedIDs) { if (!editMenu) return; var entity = singular(); - if (entity && context.geometry(entity.id) === 'relation') { + if (entity && entity.geometry(context.graph()) === 'relation') { _suppressMenu = true; } else { var point = context.mouse(); @@ -377,7 +377,7 @@ export function modeSelect(context, selectedIDs) { var surface = context.surface(); var entity = singular(); - if (entity && context.geometry(entity.id) === 'relation') { + if (entity && entity.geometry(context.graph()) === 'relation') { _suppressMenu = true; } diff --git a/modules/operations/delete.js b/modules/operations/delete.js index d66e4420c..1e698a085 100644 --- a/modules/operations/delete.js +++ b/modules/operations/delete.js @@ -25,7 +25,7 @@ export function operationDelete(selectedIDs, context) { if (selectedIDs.length === 1) { var id = selectedIDs[0]; var entity = context.entity(id); - var geometry = context.geometry(id); + var geometry = entity.geometry(context.graph()); var parents = context.graph().parentWays(entity); var parent = parents[0]; @@ -140,7 +140,7 @@ export function operationDelete(selectedIDs, context) { operation.annotation = function() { return selectedIDs.length === 1 ? - t('operations.delete.annotation.' + context.geometry(selectedIDs[0])) : + t('operations.delete.annotation.' + context.graph().geometry(selectedIDs[0])) : t('operations.delete.annotation.multiple', { n: selectedIDs.length }); }; diff --git a/modules/operations/disconnect.js b/modules/operations/disconnect.js index ff81f1f83..eabd849e7 100644 --- a/modules/operations/disconnect.js +++ b/modules/operations/disconnect.js @@ -11,16 +11,17 @@ export function operationDisconnect(selectedIDs, context) { var actions = []; selectedIDs.forEach(function(id) { - if (context.geometry(id) === 'vertex') { + var entity = context.entity(id); + if (entity.geometry(context.graph()) === 'vertex') { vertexIDs.push(id); - } else if (context.entity(id).type === 'way'){ + } else if (entity.type === 'way'){ wayIDs.push(id); } else { otherIDs.push(id); } }); - var disconnectingWayID = (vertexIDs.length === 0 && wayIDs.length === 1 && wayIDs[0]); + var disconnectingWayID = vertexIDs.length === 0 && wayIDs.length === 1 && wayIDs[0]; var extent, nodes, coords; if (disconnectingWayID) { // disconnecting a way @@ -115,7 +116,7 @@ export function operationDisconnect(selectedIDs, context) { return t('operations.disconnect.' + disable); } if (disconnectingWayID) { - return t('operations.disconnect.' + context.geometry(disconnectingWayID) + '.description'); + return t('operations.disconnect.' + context.graph().geometry(disconnectingWayID) + '.description'); } return t('operations.disconnect.description'); }; diff --git a/modules/operations/extract.js b/modules/operations/extract.js index 2e494e0b6..c2c76874d 100644 --- a/modules/operations/extract.js +++ b/modules/operations/extract.js @@ -9,7 +9,7 @@ export function operationExtract(selectedIDs, context) { var entityID = selectedIDs.length && selectedIDs[0]; var action = actionExtract(entityID, context.projection); - var geometry = entityID && context.geometry(entityID); + var geometry = entityID && context.graph().geometry(entityID); var extent = geometry === 'area' && context.entity(entityID).extent(context.graph()); diff --git a/modules/operations/move.js b/modules/operations/move.js index f91f71138..1f9de7748 100644 --- a/modules/operations/move.js +++ b/modules/operations/move.js @@ -69,7 +69,7 @@ export function operationMove(selectedIDs, context) { operation.annotation = function() { return selectedIDs.length === 1 ? - t('operations.move.annotation.' + context.geometry(selectedIDs[0])) : + t('operations.move.annotation.' + context.graph().geometry(selectedIDs[0])) : t('operations.move.annotation.multiple'); }; diff --git a/modules/operations/orthogonalize.js b/modules/operations/orthogonalize.js index edf8957b5..ed3eaf834 100644 --- a/modules/operations/orthogonalize.js +++ b/modules/operations/orthogonalize.js @@ -16,7 +16,7 @@ export function operationOrthogonalize(selectedIDs, context) { function chooseAction(entityID) { var entity = context.entity(entityID); - var geometry = context.geometry(entityID); + var geometry = entity.geometry(context.graph()); if (!_extent) { _extent = entity.extent(context.graph()); diff --git a/modules/operations/rotate.js b/modules/operations/rotate.js index 35c9020dd..7fd8a7b83 100644 --- a/modules/operations/rotate.js +++ b/modules/operations/rotate.js @@ -69,7 +69,7 @@ export function operationRotate(selectedIDs, context) { operation.annotation = function() { return selectedIDs.length === 1 ? - t('operations.rotate.annotation.' + context.geometry(selectedIDs[0])) : + t('operations.rotate.annotation.' + context.graph().geometry(selectedIDs[0])) : t('operations.rotate.annotation.multiple'); }; diff --git a/modules/operations/split.js b/modules/operations/split.js index 94eb7ea67..deb4dae29 100644 --- a/modules/operations/split.js +++ b/modules/operations/split.js @@ -6,7 +6,7 @@ import { modeSelect } from '../modes/select'; export function operationSplit(selectedIDs, context) { var vertices = selectedIDs - .filter(function(id) { return context.geometry(id) === 'vertex'; }); + .filter(function(id) { return context.graph().geometry(id) === 'vertex'; }); var entityID = vertices[0]; var action = actionSplit(entityID); var ways = []; @@ -48,7 +48,7 @@ export function operationSplit(selectedIDs, context) { if (disable) { return t('operations.split.' + disable); } else if (ways.length === 1) { - return t('operations.split.description.' + context.geometry(ways[0].id)); + return t('operations.split.description.' + context.graph().geometry(ways[0].id)); } else { return t('operations.split.description.multiple'); } @@ -57,7 +57,7 @@ export function operationSplit(selectedIDs, context) { operation.annotation = function() { return ways.length === 1 ? - t('operations.split.annotation.' + context.geometry(ways[0].id)) : + t('operations.split.annotation.' + context.graph().geometry(ways[0].id)) : t('operations.split.annotation.multiple', { n: ways.length }); }; diff --git a/modules/ui/feature_list.js b/modules/ui/feature_list.js index 791bfb650..8bc6e6dd2 100644 --- a/modules/ui/feature_list.js +++ b/modules/ui/feature_list.js @@ -162,7 +162,7 @@ export function uiFeatureList(context) { localResults.push({ id: entity.id, entity: entity, - geometry: context.geometry(entity.id), + geometry: entity.geometry(graph), type: type, name: name, distance: distance diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index 33af5159e..e6d6ad04f 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -188,7 +188,7 @@ export function uiFieldCombo(field, context) { }; if (_entityIDs.length) { - params.geometry = context.geometry(_entityIDs[0]); + params.geometry = context.graph().geometry(_entityIDs[0]); } taginfo[fn](params, function(err, data) { diff --git a/modules/ui/preset_list.js b/modules/ui/preset_list.js index 7eb92a436..27c65e43a 100644 --- a/modules/ui/preset_list.js +++ b/modules/ui/preset_list.js @@ -495,7 +495,7 @@ export function uiPresetList(context) { for (var i in _entityIDs) { var entityID = _entityIDs[i]; var entity = context.entity(entityID); - var geometry = context.geometry(entityID); + var geometry = entity.geometry(context.graph()); // Treat entities on addr:interpolation lines as points, not vertices (#3241) if (geometry === 'vertex' && entity.isOnAddressLine(context.graph())) { diff --git a/modules/ui/sections/feature_type.js b/modules/ui/sections/feature_type.js index c2934e838..12cb9cfe5 100644 --- a/modules/ui/sections/feature_type.js +++ b/modules/ui/sections/feature_type.js @@ -143,7 +143,7 @@ export function uiSectionFeatureType(context) { var counts = {}; for (var i in _entityIDs) { - var geometry = context.geometry(_entityIDs[i]); + var geometry = context.graph().geometry(_entityIDs[i]); if (!counts[geometry]) counts[geometry] = 0; counts[geometry] += 1; } diff --git a/modules/ui/sections/raw_member_editor.js b/modules/ui/sections/raw_member_editor.js index b381a0500..934bdaf42 100644 --- a/modules/ui/sections/raw_member_editor.js +++ b/modules/ui/sections/raw_member_editor.js @@ -346,7 +346,7 @@ export function uiSectionRawMemberEditor(context) { // not yet downloaded, it's ok to guess based on type. var geometry; if (d.member) { - geometry = context.geometry(d.member.id); + geometry = context.graph().geometry(d.member.id); } else if (d.type === 'relation') { geometry = 'relation'; } else if (d.type === 'way') { diff --git a/modules/ui/sections/raw_membership_editor.js b/modules/ui/sections/raw_membership_editor.js index 4db0a2f6f..54ccecfc7 100644 --- a/modules/ui/sections/raw_membership_editor.js +++ b/modules/ui/sections/raw_membership_editor.js @@ -414,7 +414,7 @@ export function uiSectionRawMembershipEditor(context) { taginfo.roles({ debounce: true, rtype: rtype || '', - geometry: context.geometry(entityID), + geometry: context.graph().geometry(entityID), query: role }, function(err, data) { if (!err) callback(sort(role, data)); diff --git a/modules/ui/sections/raw_tag_editor.js b/modules/ui/sections/raw_tag_editor.js index c01f659c3..8cfb72c4e 100644 --- a/modules/ui/sections/raw_tag_editor.js +++ b/modules/ui/sections/raw_tag_editor.js @@ -403,7 +403,7 @@ export function uiSectionRawTagEditor(id, context) { return; } - var geometry = context.geometry(_entityIDs[0]); + var geometry = context.graph().geometry(_entityIDs[0]); key.call(uiCombobox(context, 'tag-key') .fetcher(function(value, callback) { diff --git a/modules/ui/sections/selection_list.js b/modules/ui/sections/selection_list.js index 329277613..e15a0730d 100644 --- a/modules/ui/sections/selection_list.js +++ b/modules/ui/sections/selection_list.js @@ -114,7 +114,7 @@ export function uiSectionSelectionList(context) { items.selectAll('.entity-geom-icon use') .attr('href', function() { var entity = this.parentNode.parentNode.__data__; - return '#iD-icon-' + context.geometry(entity.id); + return '#iD-icon-' + entity.geometry(context.graph()); }); items.selectAll('.entity-type') diff --git a/test/spec/operations/extract.js b/test/spec/operations/extract.js index 4dfefa54e..3985e51d4 100644 --- a/test/spec/operations/extract.js +++ b/test/spec/operations/extract.js @@ -6,7 +6,6 @@ describe('iD.operationExtract', function () { fakeContext = {}; fakeContext.graph = function () { return graph; }; fakeContext.hasHiddenConnections = function () { return false; }; - fakeContext.geometry = function () { return 'vertex'; }; var fakeTags = { 'name': 'fake' };