Rename for consistency, add logic to prevent flip if all of object not visible and if linked to hidden. Label does not render for message when not enabled

This commit is contained in:
Jon D
2016-11-06 11:15:15 +00:00
parent 23990214be
commit 73f3069c59
7 changed files with 34 additions and 14 deletions

View File

@@ -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.

View File

@@ -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.",

View File

@@ -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';

View File

@@ -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);

View File

@@ -9,3 +9,4 @@ export { operationReverse } from './reverse';
export { operationRotate } from './rotate';
export { operationSplit } from './split';
export { operationStraighten } from './straighten';
export { operationReflect } from './reflect';

View File

@@ -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() {

View File

@@ -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);