Skip to content

Commit

Permalink
create offsetwcs when using and add some error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
loveluthien committed Apr 30, 2024
1 parent 77fe57e commit a24102c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
Expand Up @@ -147,7 +147,7 @@ export class ImageViewSettingsPanelComponent extends React.Component<WidgetProps
const frame = appStore.activeFrame;
const isPVImage = frame?.isPVImage;

const getFovInfoString = (value: number, valueWcs: string) => {
const getInfoString = (value: number, valueWcs: string) => {
return this.panAndZoomCoord === CoordinateMode.Image ? `WCS: ${valueWcs}` : `Image: ${toFixed(value, 3)} px`;
};
const fovLabelInfo = this.panAndZoomCoord === CoordinateMode.Image ? "(px)" : "";
Expand All @@ -166,7 +166,7 @@ export class ImageViewSettingsPanelComponent extends React.Component<WidgetProps
onChangeWcs={val => frame?.setCenterWcs(val, frame?.centerWCS?.y)}
wcsDisabled={isPVImage}
/>
<span className="info-string">{getFovInfoString(frame?.center?.x, frame?.centerWCS?.x)}</span>
<span className="info-string">{getInfoString(frame?.center?.x, frame?.centerWCS?.x)}</span>
</FormGroup>
<FormGroup inline={true} label="Center (Y)" labelInfo={fovLabelInfo}>
<CoordNumericInput
Expand All @@ -178,7 +178,7 @@ export class ImageViewSettingsPanelComponent extends React.Component<WidgetProps
onChangeWcs={val => frame?.setCenterWcs(frame?.centerWCS?.x, val)}
wcsDisabled={isPVImage}
/>
<span className="info-string">{getFovInfoString(frame?.center?.y, frame?.centerWCS?.y)}</span>
<span className="info-string">{getInfoString(frame?.center?.y, frame?.centerWCS?.y)}</span>
</FormGroup>
<FormGroup inline={true} label="Size (X)" labelInfo={fovLabelInfo}>
<CoordNumericInput
Expand All @@ -191,7 +191,7 @@ export class ImageViewSettingsPanelComponent extends React.Component<WidgetProps
wcsDisabled={isPVImage}
customPlaceholder="Width"
/>
<span className="info-string">{getFovInfoString(frame?.fovSize?.x, frame?.fovSizeWCS?.x)}</span>
<span className="info-string">{getInfoString(frame?.fovSize?.x, frame?.fovSizeWCS?.x)}</span>
</FormGroup>
<FormGroup inline={true} label="Size (Y)" labelInfo={fovLabelInfo}>
<CoordNumericInput
Expand All @@ -204,13 +204,13 @@ export class ImageViewSettingsPanelComponent extends React.Component<WidgetProps
wcsDisabled={isPVImage}
customPlaceholder="Height"
/>
<span className="info-string">{getFovInfoString(frame?.fovSize?.y, frame?.fovSizeWCS?.y)}</span>
<span className="info-string">{getInfoString(frame?.fovSize?.y, frame?.fovSizeWCS?.y)}</span>
</FormGroup>
<FormGroup inline={true} label="Offset Coordinates">
<Switch checked={frame.isOffsetCoord} onChange={frame.toggleOffsetCoord} />
<Switch checked={frame.isOffsetCoord} disabled={frame.isPVImage || frame.isSwappedZ || frame.isUVImage} onChange={frame.toggleOffsetCoord} />
<Collapse isOpen={frame.isOffsetCoord}>
<Tooltip2 content="Set offset to current view center" position={Position.BOTTOM} hoverOpenDelay={300}>
<Button icon="locate" disabled={!frame.isOffsetCoord} onClick={() => frame.updateWcsInfoShifted()} />
<Button icon="locate" disabled={!frame.isOffsetCoord} onClick={() => frame.updateOffseCenter()} />
</Tooltip2>
</Collapse>
</FormGroup>
Expand All @@ -225,7 +225,7 @@ export class ImageViewSettingsPanelComponent extends React.Component<WidgetProps
onChangeWcs={val => frame?.setOffsetCenterWcs(val, frame?.offsetCenterWCS?.y)}
wcsDisabled={isPVImage}
/>
<span className="info-string">{getFovInfoString(frame?.offsetCenter?.x, frame?.offsetCenterWCS?.x)}</span>
<span className="info-string">{getInfoString(frame?.offsetCenter?.x, frame?.offsetCenterWCS?.x)}</span>
</FormGroup>
<FormGroup inline={true} label="Offset Center (Y)" labelInfo={fovLabelInfo}>
<CoordNumericInput
Expand All @@ -237,7 +237,7 @@ export class ImageViewSettingsPanelComponent extends React.Component<WidgetProps
onChangeWcs={val => frame?.setOffsetCenterWcs(frame?.offsetCenterWCS?.x, val)}
wcsDisabled={isPVImage}
/>
<span className="info-string">{getFovInfoString(frame?.offsetCenter?.y, frame?.offsetCenterWCS?.y)}</span>
<span className="info-string">{getInfoString(frame?.offsetCenter?.y, frame?.offsetCenterWCS?.y)}</span>
</FormGroup>
</Collapse>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ImageView/Toolbar/ToolbarComponent.tsx
Expand Up @@ -180,10 +180,10 @@ export class ToolbarComponent extends React.Component<ToolbarComponentProps> {
<MenuItem text={ToolbarComponent.CoordinateSystemName.get(SystemType.Ecliptic)} onClick={() => this.handleCoordinateSystemClicked(SystemType.Ecliptic)} />
<MenuItem text={ToolbarComponent.CoordinateSystemName.get(SystemType.ICRS)} onClick={() => this.handleCoordinateSystemClicked(SystemType.ICRS)} />
<FormGroup inline={false} className="offset-group">
<Switch className="offset-switch" checked={frame.isOffsetCoord} onChange={frame.toggleOffsetCoord} label="Offset Coord." />
<Switch className="offset-switch" disabled={frame.isPVImage || frame.isSwappedZ || frame.isUVImage} checked={frame.isOffsetCoord} onChange={frame.toggleOffsetCoord} label="Offset Coord." />
<Collapse isOpen={frame.isOffsetCoord}>
<Tooltip2 content="Set offset to current view center" position={Position.BOTTOM} hoverOpenDelay={300}>
<Button icon="locate" disabled={!frame.isOffsetCoord} onClick={() => frame.updateWcsInfoShifted()} />
<Button icon="locate" disabled={!frame.isOffsetCoord} onClick={() => frame.updateOffseCenter()} />
</Tooltip2>
</Collapse>
</FormGroup>
Expand Down
30 changes: 19 additions & 11 deletions src/stores/Frame/FrameStore.ts
Expand Up @@ -159,8 +159,14 @@ export class FrameStore {
@observable spectralSystem: SpectralSystem;
@observable channelValues: Array<number>;
@observable channelSecondaryValues: Array<number>;
@observable center: Point2D; // pixel coordinates
@observable offsetCenter: Point2D; // pixel coordinates
/**
* View center in pixel coordinates
*/
@observable center: Point2D;
/**
* View center for the relative coordinate in pixel coordinates
*/
@observable offsetCenter: Point2D;
@observable cursorInfo: CursorInfo;
@observable cursorValue: {position: Point2D; channel: number; value: number};
@observable cursorMoving: boolean;
Expand Down Expand Up @@ -1387,10 +1393,6 @@ export class FrameStore {
this.zoomLevel = preferenceStore.isZoomRAWMode ? 1.0 : this.zoomLevelForFit;
this.pixelUnitSizeArcsec = this.getPixelUnitSize();

// initialize offset values for the relative coordinates of image
// it depends on center, therefore it should be placed after initCenter()
this.updateWcsInfoShifted();

// init spectral settings
if (this.spectralAxis && IsSpectralTypeSupported(this.spectralAxis.type.code as string) && IsSpectralUnitSupported(this.spectralAxis.type.unit as string)) {
if (this.isPVImage) {
Expand Down Expand Up @@ -2168,6 +2170,9 @@ export class FrameStore {
* Toggle of the offset coordinates.
*/
@action toggleOffsetCoord = () => {
if (!this.wcsInfoShifted && !this.isPVImage && !this.isPreview && !this.isSwappedZ && !this.isUVImage) {
this.updateOffseCenter();
}
this.setIsOffsetCoord(!this.isOffsetCoord);
};

Expand All @@ -2177,16 +2182,19 @@ export class FrameStore {
} else {
if (this.wcsInfo && this.offsetCenter) {
const centerInRad = getUnformattedWCSPoint(this.wcsInfo, this.offsetCenter);
this.wcsInfoShifted = AST.createShiftmapFrameset(this.wcsInfo, centerInRad.x, centerInRad.y);
for (const frame of this.secondarySpatialImages) {
const frameCenterInRad = getUnformattedWCSPoint(frame.wcsInfo, frame.offsetCenter);
frame.wcsInfoShifted = AST.createShiftmapFrameset(frame.wcsInfo, frameCenterInRad.x, frameCenterInRad.y);

if (centerInRad) {
this.wcsInfoShifted = AST.createShiftmapFrameset(this.wcsInfo, centerInRad.x, centerInRad.y);
for (const frame of this.secondarySpatialImages) {
const frameCenterInRad = getUnformattedWCSPoint(frame.wcsInfo, frame.offsetCenter);
frame.wcsInfoShifted = AST.createShiftmapFrameset(frame.wcsInfo, frameCenterInRad.x, frameCenterInRad.y);
}
}
}
}
};

@action updateWcsInfoShifted = () => {
@action updateOffseCenter = () => {
this.setOffsetCenter(this.center.x, this.center.y);
};

Expand Down

0 comments on commit a24102c

Please sign in to comment.