diff --git a/data/core.yaml b/data/core.yaml index 407cf7317..0700d2479 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -134,6 +134,8 @@ en: description: Reflect this area on the vertical axis. key: T annotation: Reflected an area. + too_large: This can't be reflected because not enough of it is currently visible. + connected_to_hidden: This can't be reflected because it is connected to a hidden feature. rotate: title: Rotate description: Rotate this object around its center point. diff --git a/dist/locales/en.json b/dist/locales/en.json index bdd861383..b01ffdc6e 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -163,6 +163,14 @@ "too_large": "This can't be moved because not enough of it is currently visible.", "connected_to_hidden": "This can't be moved because it is connected to a hidden feature." }, + "reflect": { + "title": "reflect", + "description": "Reflect this area on the vertical axis.", + "key": "T", + "annotation": "Reflected an area.", + "too_large": "This can't be reflected because not enough of it is currently visible.", + "connected_to_hidden": "This can't be reflected because it is connected to a hidden feature." + }, "rotate": { "title": "Rotate", "description": "Rotate this object around its center point.", diff --git a/modules/actions/index.js b/modules/actions/index.js index 0ad5fad9a..e45777bf8 100644 --- a/modules/actions/index.js +++ b/modules/actions/index.js @@ -31,4 +31,4 @@ export { actionRotateWay } from './rotate_way'; export { actionSplit } from './split'; export { actionStraighten } from './straighten'; export { actionUnrestrictTurn } from './unrestrict_turn'; -export { actionReflect } from './flip'; +export { actionReflect } from './reflect.js'; diff --git a/modules/actions/flip.js b/modules/actions/reflect.js similarity index 97% rename from modules/actions/flip.js rename to modules/actions/reflect.js index 8464b3265..394948c35 100644 --- a/modules/actions/flip.js +++ b/modules/actions/reflect.js @@ -3,7 +3,7 @@ import _ from 'lodash'; Only operates on "area" ways */ -export function actionFlip(wayId) { +export function actionReflect(wayId) { return function (graph) { const targetWay = graph.entity(wayId); diff --git a/modules/operations/index.js b/modules/operations/index.js index bd4058f5d..fd8882b3e 100644 --- a/modules/operations/index.js +++ b/modules/operations/index.js @@ -9,3 +9,4 @@ export { operationReverse } from './reverse'; export { operationRotate } from './rotate'; export { operationSplit } from './split'; export { operationStraighten } from './straighten'; +export { operationReflect } from './reflect'; \ No newline at end of file diff --git a/modules/operations/reflect.js b/modules/operations/reflect.js index ee9d0840c..51ae03afc 100644 --- a/modules/operations/reflect.js +++ b/modules/operations/reflect.js @@ -2,11 +2,14 @@ import { t } from '../util/locale'; import { actionReflect } from '../actions/index'; export function operationReflect(selectedIDs, context) { - var entityId = selectedIDs[0]; + const entityId = selectedIDs[0]; + const entity = context.entity(entityId); + const extent = entity.extent(context.graph()); + const action = actionReflect(entityId); var operation = function() { context.perform( - actionReflect(entityId, false), + action, t('operations.reflect.annotation') ); }; @@ -17,7 +20,13 @@ export function operationReflect(selectedIDs, context) { }; operation.disabled = function() { - return false; + if (extent.percentContainedIn(context.extent()) < 0.8) { + return 'too_large'; + } else if (context.hasHiddenConnections(entityId)) { + return 'connected_to_hidden'; + } else { + return false; + } }; operation.tooltip = function() { diff --git a/test/spec/actions/flip.js b/test/spec/actions/reflect.js similarity index 86% rename from test/spec/actions/flip.js rename to test/spec/actions/reflect.js index b683e466e..f8573d148 100644 --- a/test/spec/actions/flip.js +++ b/test/spec/actions/reflect.js @@ -1,6 +1,6 @@ -describe('iD.actionFlip', function() { +describe('iD.actionReflect', function() { - it('flips horizontally - does not change graph length', function () { + it('reflects horizontally - does not change graph length', function () { var graph = iD.Graph([ iD.Node({id: 'a', loc: [0, 0]}), iD.Node({id: 'b', loc: [2, 0]}), @@ -9,12 +9,12 @@ describe('iD.actionFlip', function() { iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}}) ]); - graph = iD.actionFlip('-')(graph); + graph = iD.actionReflect('-')(graph); expect(graph.entity('-').nodes).to.have.length(5); }); - it('flips horizontally - alters x value', function () { + it('reflects horizontally - alters x value', function () { var graph = iD.Graph([ iD.Node({id: 'a', loc: [0, 0]}), iD.Node({id: 'b', loc: [2, 0]}), @@ -22,14 +22,14 @@ describe('iD.actionFlip', function() { iD.Node({id: 'd', loc: [0, 2]}), iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}}) ]); - graph = iD.actionFlip('-')(graph); + graph = iD.actionReflect('-')(graph); expect(graph.entity('a').loc[0]).to.equal(2); // A should be 2,0 now expect(graph.entity('b').loc[0]).to.equal(0); // B should be 0,0 now expect(graph.entity('c').loc[0]).to.equal(0); // C should be 0,2 now expect(graph.entity('d').loc[0]).to.equal(2); // D should be 2,2 now }); - it('flips horizontally - does not alter y value', function () { + it('reflects horizontally - does not alter y value', function () { var graph = iD.Graph([ iD.Node({id: 'a', loc: [0, 0]}), iD.Node({id: 'b', loc: [2, 0]}), @@ -37,7 +37,7 @@ describe('iD.actionFlip', function() { iD.Node({id: 'd', loc: [0, 2]}), iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}}) ]); - graph = iD.actionFlip('-')(graph); + graph = iD.actionReflect('-')(graph); expect(graph.entity('a').loc[1]).to.equal(0); // A should be 2,0 now expect(graph.entity('b').loc[1]).to.equal(0); // B should be 0,0 now expect(graph.entity('c').loc[1]).to.equal(2); // C should be 0,2 now @@ -52,7 +52,7 @@ describe('iD.actionFlip', function() { iD.Node({id: 'd', loc: [0, 2]}), iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']}) ]); - graph = iD.actionFlip('-')(graph); + graph = iD.actionReflect('-')(graph); // should be no change expect(graph.entity('a').loc[0]).to.equal(0); expect(graph.entity('b').loc[0]).to.equal(2); @@ -68,7 +68,7 @@ describe('iD.actionFlip', function() { iD.Node({id: 'd', loc: [0, 2]}), iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']}) ]); - graph = iD.actionFlip('-')(graph); + graph = iD.actionReflect('-')(graph); // should be no change expect(graph.entity('a').loc[1]).to.equal(0); expect(graph.entity('b').loc[1]).to.equal(0);