Skip to content

DM-7147: fix region bugs as listed in DM-7147. #141

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

Merged
merged 3 commits into from
Aug 11, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions src/firefly/html/demo/ffapi-highlevel-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,12 @@
firefly.addXYPlot({QUERY_ID: 'oldSelectable'}, 'oldXyPlot1');
//-----< old xyplot api ------//

var regionAry = [
window.regionAry = [
/*
'global color=green dashlist=8 3 width=1 font="helvetica 10 normal normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 rotate=0 source=1',
'J2000;point 202.41 47.262 # color=pink text="pt circle 1" point=circle',
'box (100p, 70p, 20p, 20p, 0) #color=red text={IMAGE coordinate - 1}',
'box (100i, 70i, 30i, 30i, 0) #color=orange text={PHYSICAL coordinate -2}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMAGE and PHYSICAL in the text should be switched for these two items: p is used for physical pixels, i - for image pixels

'line(202.414796 47.281999 202.423758 47.247072) # color=orange width=10 select=0 text={line 2}',
'text 30p 40p # color=pink text={text test 3} edit=0 highlite=0 font="BRAGGADOCIO 10 normal roman"',
'text 202.437691 47.234228{more text testing 4} # color=purple move=0',
Expand All @@ -252,7 +255,38 @@
'j2000;box(47.247072i, 180.445347i, 50p, 20p, 0) # color=blue width=6 text="box 12-3"',
'physical;-box point 12 12 # text="pt box 13"',
'j2000;polygon(202.564796, 47.281999,202.553758, 47.247072, 202.445347, 47.244296, 202.479687, 47.264027, 202.492153, 47.290841) # color=blue text="polygon 14" offsety=10 width=10 font="helvetica 16 bold"',
'point 202.45 47.2879 # color=cyan text="pt arrow 15" delete=0 point=arrow 20'
'point 202.45 47.2879 # color=cyan text="pt arrow 15" delete=0 point=arrow 20',
'IMAGE;box (160, 70, 20, 20, 0) #color=red text={IMAGE test - 1}',
'PHYSICAL;box (160, 70, 30, 30, 0) #color=orange text={PHYSICAL test -2}'
*/
'box (240, 220, 20, 20, 0) #color=red text={ ph1}',
'box (240i, 220i, 60i, 60i, 0) #color=orange text={ph2}',
'J2000;point 202.41 47.262 # color=pink text="pt circle 1" point=circle',
'IMAGE;box (360, 220, 20, 20, 0) #color=red text={ im1}',
'PHYSICAL;box (360, 220, 60, 60, 0) #color=orange text={ph3}'
];

window.regionAry2 = [
'J2000',
'boxcircle point 202.45 47.262 # color=red text="pt boxcircle 6" delete=0',
'physical;circle 80 140 20 # color=red offsetx=25 offsety=2 width=5 edit=0 text="circle 7"',
'annulus 13h30m16.41s +47d14m43.9s 30p 40p 50p # color=green text="hello" include=0 text="annulus 8"',
'physical;point 200 140 # color=yellow point=cross 20 text="pt cross 9" offsetx=10',
'physical;point 13h29m52.73s, +47d11m40.9s # color=purple point=diamond 15 text="pt diamond 10"',
'#circle(202.55556, 47.188286 , 20p) # color=blue text="text 11"',
'box(202.55556, 47.188286 ,20p,40p, 30p, 50p, 0) # color=red width=5 text="boxann 11"',
'box(202.52556,47.226286,0.0240,0.006,0) # color=green width=5 text="box 11-2"',
'image;box(100, 150, 50p, 20p, 2r) # color=magenta width=6 text="slanted box 12"',
'image;box(190.564796, 47.281999, 50p, 20p, 0) # color=red width=6 offsety=-15 text="box 12-1"',
'j2000;box(47.247072i, 180.445347i, 50p, 20p, 0) # color=blue width=6 text="box 12-3"',
'physical;-box point 12 12 # text="pt box 13"',
'j2000;polygon(202.564796, 47.281999,202.553758, 47.247072, 202.445347, 47.244296, 202.479687, 47.264027, 202.492153, 47.290841) # color=blue text="polygon 14" offsety=10 width=10 font="helvetica 16 bold"',
'point 202.45 47.2879 # color=cyan text="pt arrow 15" delete=0 point=arrow 20',
];

window.regionWithError = [
'image; box 280 200 72 72 # color=blue text={wrong syntax}',
'image; box 280 200 72 72 0 # color=cyan text={right syntax}'
];

var moreRegionAry = [
Expand All @@ -264,7 +298,7 @@
window.regions = [];
window.regionId = window.regions.length;

document.getElementById('regionLayerContent').value = regionAry.join('\n');
document.getElementById('regionLayerContent').value = window.regionAry.join('\n');
document.getElementById('moreRegionContent').value = moreRegionAry.join('\n');
//document.getElementById('createRegionId').placeholder = "Region_Plot_" + (window.regionId+1);
updateRegionLayerList();
Expand All @@ -279,6 +313,14 @@
document.getElementById('createRegionId').value = layerId;
}

if (window.regionId === 3) {
document.getElementById('regionLayerContent').value = window.regionWithError.join('\n');
} else if (window.regionId > 1) {
document.getElementById('regionLayerContent').value = window.regionAry2.join('\n');
} else {
document.getElementById('regionLayerContent').value = window.regionAry.join('\n');
}

var regionAry = document.getElementById('regionLayerContent').value.split('\n').filter(function(r) { return (r.length !== 0);});
window.regions.push(layerId);
updateRegionLayerList();
Expand Down Expand Up @@ -355,7 +397,7 @@
selectBox.getElementsByTagName('option')[0].selected = 'selected';
firefly.action.dispatchRemoveRegionEntry(selectedLayerId, removeRegions);
firefly.action.dispatchRemoveRegionEntry(selectedLayerId, removeRegions, window.ffViewer.dispatch);
}
};

plotRemote= function() {
firefly.getViewer().showImage({plotId: 'xxq',
Expand Down
51 changes: 29 additions & 22 deletions src/firefly/js/drawingLayers/RegionPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {MouseState} from '../visualize/VisMouseSync.js';
import DrawOp from '../visualize/draw/DrawOp.js';
import DrawLayerCntrl, {dispatchModifyCustomField,
dispatchAddRegionEntry,
dispatchRemoveRegionEntry} from '../visualize/DrawLayerCntlr.js';
dispatchRemoveRegionEntry, dlRoot} from '../visualize/DrawLayerCntlr.js';

import {get, isEmpty} from 'lodash';

Expand Down Expand Up @@ -125,7 +125,17 @@ function highlightChange(mouseStatePayload) {
const sId = window.setInterval( () => {
if (done) {
window.clearInterval(sId);
dispatchModifyCustomField(TYPE_ID, {highlightedRegion: closestObj}, false);

// set the highlight region on current drawLayer,
// unset the highlight on other drawLayer if a highlight is found for current layer

dlRoot().drawLayerAry.forEach( (dl) => {
if (dl.drawLayerId === drawLayer.drawLayerId) {
dispatchModifyCustomField(dl.drawLayerId, {highlightedRegion: closestObj}, plotId, false);
} else if (closestObj) {
dispatchModifyCustomField(dl.drawLayerId, {highlightedRegion: null}, plotId, false);
}
});
}

for (let i = 0; i < maxChunk; i++ ) {
Expand Down Expand Up @@ -157,30 +167,27 @@ function highlightChange(mouseStatePayload) {
* @returns {*}
*/
function getLayerChanges(drawLayer, action) {
const {changes, regionId, regionChanges } = action.payload;
const {changes, regionId, regionChanges, drawLayerId } = action.payload;

if (drawLayerId && drawLayerId !== drawLayer.drawLayerId) return null;
var dd = Object.assign({}, drawLayer.drawData);

switch (action.type) {
case DrawLayerCntlr.MODIFY_CUSTOM_FIELD:
/*
if (changes && changes.regions) { // this should not happen
dd[DataTypes.HIGHLIGHT_DATA] = null;
dd[DataTypes.DATA] = null;
if (drawLayer.highlightedRegion) drawLayer.highlightedRegion = null;
} else */
if (changes && changes.highlightedRegion) {
dd[DataTypes.HIGHLIGHT_DATA] = null;
if (drawLayer.highlightedRegion) drawLayer.highlightedRegion.highlight = 0;
changes.highlightedRegion.highlight = 1;
} else if (changes) {
dd[DataTypes.HIGHLIGHT_DATA] = null;
if (drawLayer.highlightedRegion) {
drawLayer.highlightedRegion.highlight = 0; // un-highlight the last one
drawLayer.highlightedRegion = null;
}
}

return Object.assign({}, changes, {drawData: dd});
if (changes) {
dd[DataTypes.HIGHLIGHT_DATA] = null;
if (!changes.highlightedRegion) {
if (drawLayer.highlightedRegion) {
drawLayer.highlightedRegion.highlight = 0; // un-highlight the last selected region
drawLayer.highlightedRegion = null;
}
} else {
if (drawLayer.highlightedRegion) drawLayer.highlightedRegion.highlight = 0;
changes.highlightedRegion.highlight = 1;

}
}
return Object.assign({}, changes, {drawData: dd});
case DrawLayerCntrl.REGION_ADD_ENTRY:
if (regionId === drawLayer.drawLayerId && regionChanges) {
dd[DataTypes.DATA] = addRegionsToData(drawLayer, dd[DataTypes.DATA], regionChanges);
Expand Down
25 changes: 21 additions & 4 deletions src/firefly/js/visualize/region/RegionFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {convertAngle} from '../VisUtil.js';
import CsysConverter from '../CsysConverter.js';
import {primePlot} from '../PlotViewUtil.js';
import {visRoot } from '../ImagePlotCntlr.js';
import {logError} from '../../util/WebUtil.js'

import {set, unset, has, get, isEmpty} from 'lodash';
import Enum from 'enum';
Expand All @@ -31,6 +32,15 @@ var RegionParseError = {
NotImplemented: 'region type is not yet implemented'
};

function outputError(rg, rgStr) {
if (rg.type === RegionType.message) {
logError(rg.message);
} else if (!rg.options) {
logError(`[invalid region: no options created]: '${rgStr}'`);
} else if (rg.type === RegionType.undefined ) {
logError(`[invalid region: undefined region type] '${rgStr}'`);
}
}

export class RegionFactory {

Expand All @@ -45,6 +55,7 @@ export class RegionFactory {

if (rg) { // skip comment line and no good line
prev.push(rg);
outputError(rg, region);
}
return prev;
}, []) : null;
Expand Down Expand Up @@ -80,6 +91,7 @@ export class RegionFactory {
} else {
prev.push(rg);
}
outputError(rg, region);
}
return prev;
}, []) : null;
Expand Down Expand Up @@ -146,9 +158,9 @@ export class RegionFactory {
regionCoord = tmpAry[0].trim();
tmpAry = tmpAry[1].split('#');
} else {
// default coordinate is J2000 in case not specified
// default coordinate is PHYSICAL in case not specified
regionCoord = globalOptions && has(globalOptions, regionPropsList.COORD) ?
globalOptions[regionPropsList.COORD] : 'J2000';
globalOptions[regionPropsList.COORD] : 'PHYSICAL';
tmpAry = tmpAry[0].split('#');
}

Expand Down Expand Up @@ -178,9 +190,13 @@ export class RegionFactory {
var regionCsys = getRegionCoordSys(regionCoord);
if (regionCsys === RegionCsys.UNDEFINED) {
return makeRegionMsg(`[${RegionParseError.InvalidCoord}] ${rgMsg}`);
} else if (regionCsys === RegionCsys.PHYSICAL) { // PHYSICAL is treated the same as IMAGE, more detail
// transformation will be investigated furteher.
regionCsys = RegionCsys.IMAGE;
}



// check region description syntax and region type
// [ RegionType, wp.x, wp.y, ...], at least 3 items

Expand Down Expand Up @@ -672,13 +688,14 @@ export class RegionFactory {
unit = RegionValueUnit.RADIAN;
break;
case 'p':
unit = RegionValueUnit.SCREEN_PIXEL;
//unit = RegionValueUnit.SCREEN_PIXEL;
unit = RegionValueUnit.IMAGE_PIXEL; // treat 'p' same as 'i' (more detail transformation will be
// further investigated)
break;
case 'i':
unit = RegionValueUnit.IMAGE_PIXEL;
break;
case 's':

default:
unit = RegionValueUnit.CONTEXT;
}
Expand Down