Issue #235 Added ability to capture multiple frames to NSharp
Change-Id: Ib6ab3acff6d9357679f4116493c1d3a97b57c2cc Former-commit-id: 447253e7cd0ea5ab64c020a4fe0822ffc3a01d3f
This commit is contained in:
parent
3f60daa9c7
commit
6bfd8ccfee
7 changed files with 548 additions and 186 deletions
|
@ -34,6 +34,7 @@ Import-Package: com.raytheon.uf.common.dataplugin,
|
|||
com.raytheon.uf.viz.d2d.core.time,
|
||||
com.raytheon.viz.core.graphing,
|
||||
com.raytheon.viz.ui,
|
||||
com.raytheon.viz.ui.actions,
|
||||
com.raytheon.viz.ui.dialogs,
|
||||
com.raytheon.viz.ui.editor,
|
||||
com.raytheon.viz.ui.perspectives,
|
||||
|
@ -50,6 +51,7 @@ Import-Package: com.raytheon.uf.common.dataplugin,
|
|||
gov.noaa.nws.ncep.ui.nsharp.skewt.bkgd,
|
||||
gov.noaa.nws.ncep.ui.nsharp.skewt.rsc,
|
||||
gov.noaa.nws.ncep.viz.common.soundingQuery,
|
||||
gov.noaa.nws.ncep.viz.ui.display,
|
||||
javax.measure.converter,
|
||||
javax.measure.unit,
|
||||
org.eclipse.core.commands,
|
||||
|
@ -57,6 +59,7 @@ Import-Package: com.raytheon.uf.common.dataplugin,
|
|||
org.eclipse.swt,
|
||||
org.eclipse.swt.graphics,
|
||||
org.eclipse.swt.layout,
|
||||
org.eclipse.swt.printing,
|
||||
org.eclipse.swt.widgets,
|
||||
org.eclipse.ui,
|
||||
org.eclipse.ui.part,
|
||||
|
|
|
@ -31,4 +31,27 @@
|
|||
visible="false"/>
|
||||
</perspectiveExtension>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.handlers">
|
||||
<handler
|
||||
class="com.raytheon.uf.viz.d2d.nsharp.rsc.action.NSharpSaveScreenAction"
|
||||
commandId="com.raytheon.viz.ui.actions.saveScreen">
|
||||
<activeWhen>
|
||||
<with variable="activeEditorId">
|
||||
<equals value="gov.noaa.nws.ncep.ui.nsharp.skewt.NsharpSkewTEditor"/>
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="com.raytheon.uf.viz.d2d.nsharp.rsc.action.NSharpPrintScreenAction"
|
||||
commandId="com.raytheon.viz.ui.actions.printScreenAction">
|
||||
<activeWhen>
|
||||
<with variable="activeEditorId">
|
||||
<equals value="gov.noaa.nws.ncep.ui.nsharp.skewt.NsharpSkewTEditor"/>
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,199 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
|
||||
package com.raytheon.uf.viz.d2d.nsharp.rsc.action;
|
||||
|
||||
import gov.noaa.nws.ncep.ui.nsharp.palette.NsharpPrintHandle;
|
||||
import gov.noaa.nws.ncep.ui.nsharp.skewt.NsharpSkewTDescriptor;
|
||||
import gov.noaa.nws.ncep.ui.nsharp.skewt.NsharpSkewTEditor;
|
||||
import gov.noaa.nws.ncep.ui.nsharp.skewt.rsc.NsharpSkewTResource;
|
||||
import gov.noaa.nws.ncep.ui.nsharp.skewt.rsc.NsharpSkewTResource.ElementStateProperty;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.swt.printing.PrintDialog;
|
||||
import org.eclipse.swt.printing.Printer;
|
||||
import org.eclipse.swt.printing.PrinterData;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.IFrameCoordinator.FrameChangeMode;
|
||||
import com.raytheon.uf.viz.core.drawables.IFrameCoordinator.FrameChangeOperation;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.viz.ui.EditorUtil;
|
||||
import com.raytheon.viz.ui.actions.PrintScreenAction;
|
||||
|
||||
/**
|
||||
* Print the current map
|
||||
*
|
||||
* <pre>
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 26, 2006 chammack Initial Creation.
|
||||
* Aug 08, 2008 #703 randerso fixed bug, changed to scale to fit
|
||||
* paper and rotate if necessary
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author chammack
|
||||
* @version 1
|
||||
*/
|
||||
public class NSharpPrintScreenAction extends PrintScreenAction {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
|
||||
* ExecutionEvent)
|
||||
*/
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
NsharpSkewTEditor editor = null;
|
||||
IEditorPart part = EditorUtil.getActiveEditor();
|
||||
if (part instanceof NsharpSkewTEditor) {
|
||||
editor = (NsharpSkewTEditor) part;
|
||||
}
|
||||
if (editor == null) {
|
||||
return super.execute(event);
|
||||
}
|
||||
IDisplayPane pane = editor.getActiveDisplayPane();
|
||||
IDescriptor desc = pane.getDescriptor();
|
||||
|
||||
NsharpSkewTDescriptor ndesc = editor.getNsharpSkewTDescriptor();
|
||||
|
||||
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getShell();
|
||||
|
||||
// display the printer dialog to get print options
|
||||
PrintDialog pd = new PrintDialog(shell);
|
||||
String frameMode = event.getParameter("frameSelection");
|
||||
if (frameMode == null || frameMode.equalsIgnoreCase("current")) {
|
||||
// selection doesn't seem to work.
|
||||
pd.setScope(PrinterData.PAGE_RANGE);
|
||||
pd.setStartPage(getCurrentIndex(ndesc.getSkewtResource()) + 1);
|
||||
pd.setEndPage(getCurrentIndex(ndesc.getSkewtResource()) + 1);
|
||||
} else if (frameMode.equalsIgnoreCase("all")) {
|
||||
pd.setScope(PrinterData.ALL_PAGES);
|
||||
} else {
|
||||
throw new ExecutionException("Invalid frameMode: " + frameMode);
|
||||
}
|
||||
PrinterData printerData = pd.open();
|
||||
if (printerData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
NsharpPrintHandle handle = new NsharpPrintHandle();
|
||||
handle.createPrinter(printerData);
|
||||
if (handle.startJob()) {
|
||||
switch (pd.getScope()) {
|
||||
case PrinterData.ALL_PAGES: {
|
||||
try {
|
||||
printAllFrames(handle, editor);
|
||||
} catch (VizException e) {
|
||||
throw new ExecutionException(
|
||||
"Error occurred while writing image", e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PrinterData.PAGE_RANGE: {
|
||||
try {
|
||||
printFrames(handle, editor, pd.getStartPage() - 1,
|
||||
pd.getEndPage());
|
||||
} catch (VizException e) {
|
||||
throw new ExecutionException(
|
||||
"Error occurred while writing image", e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PrinterData.SELECTION: {
|
||||
printImage(handle, editor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
handle.endJob();
|
||||
|
||||
}
|
||||
handle.disposePrinter();
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getCurrentIndex(NsharpSkewTResource rsc) {
|
||||
int index = rsc.getDataTimelineList().size();
|
||||
for (ElementStateProperty element : rsc.getDataTimelineList()) {
|
||||
index -= 1;
|
||||
if (element.getElementDescription().equals(
|
||||
rsc.getPickedStnInfoStr())) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void printAllFrames(NsharpPrintHandle printer,
|
||||
NsharpSkewTEditor editor) throws VizException {
|
||||
printFrames(printer, editor, 0, editor.getNsharpSkewTDescriptor()
|
||||
.getSkewtResource().getDataTimelineList().size());
|
||||
}
|
||||
|
||||
private void printFrames(NsharpPrintHandle printer,
|
||||
NsharpSkewTEditor editor, int startIndex, int endIndex)
|
||||
throws VizException {
|
||||
NsharpSkewTDescriptor ndesc = editor.getNsharpSkewTDescriptor();
|
||||
IDisplayPane pane = editor.getActiveDisplayPane();
|
||||
String picked = ndesc.getSkewtResource().getPickedStnInfoStr();
|
||||
if (getCurrentIndex(ndesc.getSkewtResource()) > startIndex) {
|
||||
ndesc.getFrameCoordinator().changeFrame(FrameChangeOperation.FIRST,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
editor.getActiveDisplayPane().refresh();
|
||||
}
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
boolean first = true;
|
||||
for (int i = getCurrentIndex(ndesc.getSkewtResource()); i < endIndex; i++) {
|
||||
if (!first) {
|
||||
ndesc.getFrameCoordinator().changeFrame(
|
||||
FrameChangeOperation.NEXT,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
pane.refresh();
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
}
|
||||
if (i >= startIndex) {
|
||||
printImage(printer, editor);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
while (!ndesc.getSkewtResource().getPickedStnInfoStr().equals(picked)) {
|
||||
ndesc.getFrameCoordinator().changeFrame(FrameChangeOperation.NEXT,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
pane.refresh();
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
}
|
||||
}
|
||||
|
||||
private void printImage(NsharpPrintHandle printer, NsharpSkewTEditor editor) {
|
||||
printer.printPage(editor.getNsharpSkewTDescriptor());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
|
||||
package com.raytheon.uf.viz.d2d.nsharp.rsc.action;
|
||||
|
||||
import gov.noaa.nws.ncep.ui.nsharp.skewt.NsharpSkewTDescriptor;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.IFrameCoordinator.FrameChangeMode;
|
||||
import com.raytheon.uf.viz.core.drawables.IFrameCoordinator.FrameChangeOperation;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.viz.ui.actions.SaveScreenAction;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
|
||||
/**
|
||||
* Save the current screen to a file
|
||||
*
|
||||
* <pre>
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 26, 2006 chammack Initial Creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author chammack
|
||||
* @version 1
|
||||
*/
|
||||
public class NSharpSaveScreenAction extends SaveScreenAction {
|
||||
|
||||
@Override
|
||||
protected BufferedImage captureCurrentFrames(AbstractEditor editor) {
|
||||
return editor.getActiveDisplayPane().getTarget().screenshot();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<BufferedImage> captureAllFrames(AbstractEditor editor)
|
||||
throws VizException {
|
||||
IDescriptor desc = editor.getActiveDisplayPane().getDescriptor();
|
||||
if (!(desc instanceof NsharpSkewTDescriptor)) {
|
||||
return super.captureAllFrames(editor);
|
||||
}
|
||||
NsharpSkewTDescriptor ndesc = (NsharpSkewTDescriptor) desc;
|
||||
int startIndex = 0;
|
||||
int endIndex = ndesc.getSkewtResource().getDataTimelineList().size();
|
||||
return captureFrames(editor, startIndex, endIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<BufferedImage> captureFrames(AbstractEditor editor,
|
||||
int startIndex, int endIndex) throws VizException {
|
||||
IDisplayPane pane = editor.getActiveDisplayPane();
|
||||
IDescriptor desc = pane.getDescriptor();
|
||||
if (!(desc instanceof NsharpSkewTDescriptor)) {
|
||||
return super.captureFrames(editor, startIndex, endIndex);
|
||||
}
|
||||
NsharpSkewTDescriptor ndesc = (NsharpSkewTDescriptor) desc;
|
||||
// save the frame we are on;
|
||||
String picked = ndesc.getSkewtResource().getPickedStnInfoStr();
|
||||
List<BufferedImage> images = new ArrayList<BufferedImage>();
|
||||
|
||||
desc.getFrameCoordinator().changeFrame(FrameChangeOperation.FIRST,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
pane.refresh();
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
for (int i = 0; i < endIndex; i++) {
|
||||
if (i >= startIndex) {
|
||||
images.add(captureCurrentFrames(editor));
|
||||
}
|
||||
if (i < endIndex - 1) {
|
||||
desc.getFrameCoordinator().changeFrame(
|
||||
FrameChangeOperation.NEXT,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
pane.refresh();
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
}
|
||||
}
|
||||
while (!ndesc.getSkewtResource().getPickedStnInfoStr().equals(picked)) {
|
||||
desc.getFrameCoordinator().changeFrame(FrameChangeOperation.NEXT,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
pane.refresh();
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
}
|
||||
return images;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
|
@ -31,6 +32,9 @@ public abstract class AbstractScreenCaptureAction extends AbstractHandler {
|
|||
int startIndex = 0;
|
||||
int endIndex = editor.getActiveDisplayPane().getDescriptor()
|
||||
.getFramesInfo().getFrameCount();
|
||||
if(endIndex == 0){
|
||||
endIndex = 1;
|
||||
}
|
||||
return captureFrames(editor, startIndex, endIndex);
|
||||
}
|
||||
|
||||
|
@ -60,11 +64,18 @@ public abstract class AbstractScreenCaptureAction extends AbstractHandler {
|
|||
|
||||
private void setFrameIndex(IDescriptor desc, int index) {
|
||||
FramesInfo fi = desc.getFramesInfo();
|
||||
if(fi.getFrameTimes() == null || fi.getFrameCount() <= 1){
|
||||
return;
|
||||
}
|
||||
index = index % fi.getFrameCount();
|
||||
if(index < 0){
|
||||
index += fi.getFrameCount();
|
||||
}
|
||||
fi = new FramesInfo(fi.getFrameTimes(), index, fi.getTimeMap());
|
||||
desc.setFramesInfo(fi);
|
||||
}
|
||||
|
||||
private void renderPane(IDisplayPane pane, LoopProperties loopProperties)
|
||||
protected void renderPane(IDisplayPane pane, LoopProperties loopProperties)
|
||||
throws VizException {
|
||||
IGraphicsTarget target = pane.getTarget();
|
||||
IRenderableDisplay display = pane.getRenderableDisplay();
|
||||
|
|
|
@ -130,7 +130,7 @@ public class SaveScreenAction extends AbstractScreenCaptureAction {
|
|||
String frameMode = arg0.getParameter("frameSelection");
|
||||
|
||||
if (frameMode == null || frameMode.equalsIgnoreCase("current")) {
|
||||
BufferedImage bi = editor.screenshot();
|
||||
BufferedImage bi = captureCurrentFrames(editor);
|
||||
|
||||
try {
|
||||
writer.setOutput(new FileImageOutputStream(new File(path)));
|
||||
|
|
|
@ -65,7 +65,9 @@ public class NsharpPrintHandle {
|
|||
private static int HODO_X_ORIG= SKEWT_X_ORIG + SKEWT_WIDTH-130;
|
||||
private static int HODO_HEIGHT= 130;
|
||||
private static int HODO_WIDTH= HODO_HEIGHT;
|
||||
|
||||
private Font printerFont;
|
||||
private Color printerForegroundColor, printerBackgroundColor;
|
||||
private Transform transform;
|
||||
|
||||
private static NsharpPrintHandle printHandle=null;
|
||||
public static NsharpPrintHandle getPrintHandle() {
|
||||
|
@ -137,9 +139,12 @@ public class NsharpPrintHandle {
|
|||
}
|
||||
try{
|
||||
// Do the printing in a background thread so that spooling does not freeze the UI.
|
||||
printer = new Printer(data);
|
||||
print(printer);
|
||||
printer.dispose();
|
||||
createPrinter(data);
|
||||
if (startJob()) {
|
||||
printPage(NsharpSkewTEditor.getActiveNsharpEditor().getNsharpSkewTDescriptor());
|
||||
endJob();
|
||||
}
|
||||
disposePrinter();
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
|
@ -155,14 +160,12 @@ public class NsharpPrintHandle {
|
|||
|
||||
}
|
||||
|
||||
private void print(Printer printer) {
|
||||
public void createPrinter(PrinterData data){
|
||||
this.printer = new Printer(data);
|
||||
}
|
||||
|
||||
public boolean startJob(){
|
||||
String tabs;
|
||||
Font printerFont;
|
||||
Color printerForegroundColor, printerBackgroundColor;
|
||||
|
||||
NsharpSkewTDescriptor desc = NsharpSkewTEditor.getActiveNsharpEditor().getNsharpSkewTDescriptor();
|
||||
NsharpBackgroundResource bkRsc = desc.getSkewTBkGResource();
|
||||
|
||||
if (printer.startJob("NSHARP")) { // the string is the job name - shows up in the printer's job list
|
||||
Rectangle clientArea = printer.getClientArea();
|
||||
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
|
||||
|
@ -171,7 +174,7 @@ public class NsharpPrintHandle {
|
|||
float dpiScaleX = dpi.x/72f;
|
||||
float dpiScaleY = dpi.y/72f;
|
||||
|
||||
Transform transform = new Transform(printer);
|
||||
transform = new Transform(printer);
|
||||
transform.scale(dpiScaleX, dpiScaleY);
|
||||
|
||||
leftMargin = 72 + trim.x; // one inch from left side of paper
|
||||
|
@ -202,6 +205,13 @@ public class NsharpPrintHandle {
|
|||
printerBackgroundColor = new Color(printer, rgb);
|
||||
gc.setBackground(printerBackgroundColor);
|
||||
gc.setTransform(transform);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void printPage(NsharpSkewTDescriptor desc){
|
||||
NsharpBackgroundResource bkRsc = desc.getSkewTBkGResource();
|
||||
printer.startPage();
|
||||
// Print SkewT square
|
||||
gc.drawRectangle(leftMargin+SKEWT_X_ORIG, topMargin, SKEWT_WIDTH, SKEWT_HEIGHT);
|
||||
|
@ -325,6 +335,9 @@ public class NsharpPrintHandle {
|
|||
gc.drawLine(leftMargin+445, curY, leftMargin+445,preY);
|
||||
|
||||
printer.endPage();
|
||||
}
|
||||
|
||||
public void endJob(){
|
||||
printer.endJob();
|
||||
|
||||
/* Cleanup graphics resources used in printing */
|
||||
|
@ -334,7 +347,11 @@ public class NsharpPrintHandle {
|
|||
transform.dispose();
|
||||
gc.dispose();
|
||||
}
|
||||
|
||||
public void disposePrinter(){
|
||||
printer.dispose();
|
||||
}
|
||||
|
||||
private int x, y;
|
||||
private int index, end;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue