Issue #429 fix minor issues with toolbar and updated eraser code

Former-commit-id: 48eb644d69 [formerly 25a539a1c8] [formerly 27e850d203] [formerly 48eb644d69 [formerly 25a539a1c8] [formerly 27e850d203] [formerly 236ae6f26c [formerly 27e850d203 [formerly f6f3bcc2596735c8371256f4274c9b9e21445f1a]]]]
Former-commit-id: 236ae6f26c
Former-commit-id: 8cfbc1e384 [formerly 5e3bebc033] [formerly c7bbc8af81d1470fb9f760fffe73f1516e976a49 [formerly 0a97f20f3a]]
Former-commit-id: 94a8ece70e11de0ce034b84f543172f55a0366c8 [formerly e7d6b86a2f]
Former-commit-id: 5794564ebd
This commit is contained in:
Matt Nash 2012-03-30 16:35:02 -05:00
parent c2b244db59
commit e414c6c180
5 changed files with 267 additions and 157 deletions

View file

@ -41,6 +41,29 @@
class="com.raytheon.uf.viz.drawing.actions.RedoAddAction" class="com.raytheon.uf.viz.drawing.actions.RedoAddAction"
commandId="com.raytheon.uf.viz.drawing.redoadd"> commandId="com.raytheon.uf.viz.drawing.redoadd">
</handler> </handler>
</extension>
<extension
point="org.eclipse.ui.contexts">
<context
description="Drawing Context"
id="com.raytheon.uf.viz.drawing.context"
name="Drawing Context">
</context>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="com.raytheon.uf.viz.drawing.undoadd"
contextId="com.raytheon.uf.viz.drawing.context"
schemeId="com.raytheon.viz.ui.awips.scheme"
sequence="M1+Z">
</key>
<key
commandId="com.raytheon.uf.viz.drawing.redoadd"
contextId="com.raytheon.uf.viz.drawing.context"
schemeId="com.raytheon.viz.ui.awips.scheme"
sequence="M1+Y">
</key>
</extension> </extension>
<!--extension <!--extension
point="org.eclipse.ui.bindings"> point="org.eclipse.ui.bindings">

View file

@ -29,7 +29,6 @@ import com.raytheon.uf.viz.core.rsc.IInputHandler;
import com.raytheon.uf.viz.core.rsc.LoadProperties; import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.core.rsc.ResourceList; import com.raytheon.uf.viz.core.rsc.ResourceList;
import com.raytheon.viz.ui.tools.AbstractModalTool; import com.raytheon.viz.ui.tools.AbstractModalTool;
/** /**
* Describes a basic drawing tool. * Describes a basic drawing tool.
* *

View file

@ -28,7 +28,6 @@ import java.util.Map;
import org.eclipse.jface.action.Action; import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.swt.graphics.RGB;
import com.raytheon.uf.viz.core.IGraphicsTarget; import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.drawables.IWireframeShape; import com.raytheon.uf.viz.core.drawables.IWireframeShape;
@ -43,7 +42,9 @@ import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability; import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability;
import com.raytheon.uf.viz.core.rsc.capabilities.OutlineCapability; import com.raytheon.uf.viz.core.rsc.capabilities.OutlineCapability;
import com.raytheon.viz.ui.cmenu.IContextMenuContributor; import com.raytheon.viz.ui.cmenu.IContextMenuContributor;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.MultiLineString; import com.vividsolutions.jts.geom.MultiLineString;
@ -69,12 +70,17 @@ public class DrawingLayer extends
protected IWireframeShape eraseWireframeShape; protected IWireframeShape eraseWireframeShape;
// TODO take this out
private List<IWireframeShape> erasedShapes;
protected IGraphicsTarget target; protected IGraphicsTarget target;
protected boolean needsRefresh = true;
protected boolean erase = false; protected boolean erase = false;
private PaintProperties paintProps = null;
private boolean needsRefresh = false;
public DrawingLayer(PathDrawingResourceData data, LoadProperties props) { public DrawingLayer(PathDrawingResourceData data, LoadProperties props) {
super(data, props); super(data, props);
} }
@ -100,6 +106,8 @@ public class DrawingLayer extends
this.tempGeometries = new ArrayList<Geometry>(); this.tempGeometries = new ArrayList<Geometry>();
this.wireframeShapes = new LinkedHashMap<Geometry, IWireframeShape>(); this.wireframeShapes = new LinkedHashMap<Geometry, IWireframeShape>();
this.deletedShapes = new LinkedHashMap<Geometry, IWireframeShape>(); this.deletedShapes = new LinkedHashMap<Geometry, IWireframeShape>();
this.erasedShapes = new ArrayList<IWireframeShape>();
this.target = target; this.target = target;
getCapability(OutlineCapability.class); getCapability(OutlineCapability.class);
@ -115,6 +123,7 @@ public class DrawingLayer extends
*/ */
protected void paintInternal(IGraphicsTarget target, protected void paintInternal(IGraphicsTarget target,
PaintProperties paintProps) throws VizException { PaintProperties paintProps) throws VizException {
this.paintProps = paintProps;
if (tempWireframeShape == null || needsRefresh) { if (tempWireframeShape == null || needsRefresh) {
tempWireframeShape = target.createWireframeShape(true, tempWireframeShape = target.createWireframeShape(true,
getDescriptor()); getDescriptor());
@ -125,47 +134,87 @@ public class DrawingLayer extends
getDescriptor()); getDescriptor());
} }
RGB rgb = getCapability(ColorableCapability.class).getColor();
OutlineCapability outline = getCapability(OutlineCapability.class); OutlineCapability outline = getCapability(OutlineCapability.class);
ColorableCapability colorable = getCapability(ColorableCapability.class); ColorableCapability colorable = getCapability(ColorableCapability.class);
// remove after debugging
// MagnificationCapability magnification =
// getCapability(MagnificationCapability.class);
// for (Geometry ls : wireframeShapes.keySet()) {
// if (ls instanceof LineString) {
// LineString string = (LineString) ls;
// for (int i = 0; i < string.getNumPoints(); i++) {
// target.drawPoint(string.getPointN(i).getX(), string
// .getPointN(i).getY(), 0, colorable.getColor(),
// PointStyle.BOX, magnification.getMagnification()
// .floatValue());
// DrawableString dString = new DrawableString(string
// .getPointN(i).getCoordinate().toString(),
// colorable.getColor());
// dString.basics.x = string.getPointN(i).getX();
// dString.basics.y = string.getPointN(i).getY();
// target.drawStrings(dString);
// }
// }
// }
for (IWireframeShape sh : wireframeShapes.values()) { for (IWireframeShape sh : wireframeShapes.values()) {
target.drawWireframeShape(sh, colorable.getColor(), target.drawWireframeShape(sh, colorable.getColor(),
(float) outline.getOutlineWidth()); (float) outline.getOutlineWidth(), outline.getLineStyle());
} }
for (Geometry g : this.tempGeometries) { for (Geometry g : this.tempGeometries) {
drawTempLinePrimitive(g, target, rgb); drawTempLinePrimitive(g, tempWireframeShape);
} }
// if (erase) {
// target.drawWireframeShape(tempWireframeShape, new RGB(255, 0, 0),
// 1.0f);
// } else {
target.drawWireframeShape(tempWireframeShape, colorable.getColor(), target.drawWireframeShape(tempWireframeShape, colorable.getColor(),
outline.getOutlineWidth(), outline.getLineStyle()); outline.getOutlineWidth(), outline.getLineStyle());
// }
// target.drawWireframeShape(eraseWireframeShape, new RGB(255, 0, 0),
// 4.0f);
} }
private void drawTempLinePrimitive(Geometry shape, IGraphicsTarget target, private void drawTempLinePrimitive(Geometry shape, IWireframeShape wShape) {
RGB color) throws VizException {
LineString line = (LineString) shape; LineString line = (LineString) shape;
int pts = line.getNumPoints(); int pts = line.getNumPoints();
for (int i = 1; i < pts; i++) { for (int i = 1; i < pts; i++) {
double[] p1 = this.descriptor double[] p1 = new double[] { line.getPointN(i - 1).getX(),
.worldToPixel(new double[] { line.getPointN(i - 1).getX(), line.getPointN(i - 1).getY() };
line.getPointN(i - 1).getY() }); double[] p2 = new double[] { line.getPointN(i).getX(),
double[] p2 = this.descriptor.worldToPixel(new double[] { line.getPointN(i).getY() };
line.getPointN(i).getX(), line.getPointN(i).getY() });
double[][] coords = new double[2][2]; double[][] coords = new double[2][2];
coords[0][0] = p1[0]; coords[0][0] = p1[0];
coords[0][1] = p1[1]; coords[0][1] = p1[1];
coords[1][0] = p2[0]; coords[1][0] = p2[0];
coords[1][1] = p2[1]; coords[1][1] = p2[1];
tempWireframeShape.addLineSegment(coords); wShape.addLineSegment(coords);
} }
} }
/** /**
* Draw a line using pixel coordinates * Convert from world to gl pixels
*
* @param line
* @param i
* @return
*/
public LineString convertPixels(LineString line) {
int pts = line.getNumPoints();
GeometryFactory factory = new GeometryFactory();
List<Coordinate> coords = new ArrayList<Coordinate>();
for (int i = 0; i < pts; i++) {
double[] point = this.descriptor.worldToPixel(new double[] {
line.getPointN(i).getX(), line.getPointN(i).getY() });
coords.add(new Coordinate(point[0], point[1]));
}
return factory.createLineString(coords.toArray(new Coordinate[0]));
}
/**
* Finalize a temporary line by putting it in the map of all the drawn
* shapes
* *
* UUID is optional, and generally should be null * UUID is optional, and generally should be null
* *
@ -173,74 +222,68 @@ public class DrawingLayer extends
* @param isFinal * @param isFinal
* @param uuid * @param uuid
*/ */
public void addLine(LineString line, String uuid) { public void finalizeLine(LineString line, String uuid) {
tempWireframeShape.compile(); tempWireframeShape.compile();
wireframeShapes.put(line, tempWireframeShape); wireframeShapes.put(line, tempWireframeShape);
} }
public void addTempLine(LineString line) { public void addTempDrawLine(LineString line) {
if (!erase) { this.tempGeometries.add(line);
this.tempGeometries.add(line); }
} else {
Map<Geometry, IWireframeShape> shapes = new HashMap<Geometry, IWireframeShape>();
shapes.putAll(wireframeShapes);
GeometryFactory factory = new GeometryFactory();
for (Geometry geom : shapes.keySet()) {
if (line.intersects(geom)) {
Point point = factory
.createPoint(line.getCoordinates()[line
.getNumPoints() - 1]);
Geometry intersection = point.buffer(1).intersection(geom);
Geometry finalGeom = geom.difference(intersection);
deletedShapes.put(geom, wireframeShapes.remove(geom));
if (finalGeom instanceof MultiLineString) { public void addTempEraseLine(LineString line) {
MultiLineString mLineString = (MultiLineString) finalGeom; this.tempGeometries.add(line);
for (int j = 0; j < mLineString.getNumGeometries(); j++) { Map<Geometry, IWireframeShape> shapes = new HashMap<Geometry, IWireframeShape>();
LineString lineString = (LineString) mLineString shapes.putAll(wireframeShapes);
.getGeometryN(j); for (Geometry geom : shapes.keySet()) {
eraseWireframeShape = target.createWireframeShape( double extentPercentageX = paintProps.getView().getExtent()
true, descriptor); .getWidth()
int pts = lineString.getNumPoints(); / (double) paintProps.getCanvasBounds().width;
for (int i = 1; i < pts; i++) { double cursorSize = 16;
double[] p1 = this.descriptor double size = extentPercentageX * cursorSize;
.worldToPixel(new double[] { if (line.buffer(size / 2).intersects(geom)) {
lineString.getPointN(i - 1) Geometry intersection = line.buffer(size / 2)
.getX(), .intersection(geom);
lineString.getPointN(i - 1) Geometry finalGeom = geom.difference(intersection);
.getY() }); deletedShapes.put(geom, wireframeShapes.remove(geom));
double[] p2 = this.descriptor
.worldToPixel(new double[] { Geometry lString = null;
lineString.getPointN(i).getX(), // should be split into multiple pieces (half or more)
lineString.getPointN(i).getY() }); if (finalGeom instanceof MultiLineString) {
double[][] coords = new double[2][2]; lString = (MultiLineString) finalGeom;
coords[0][0] = p1[0]; for (int j = 0; j < lString.getNumGeometries(); j++) {
coords[0][1] = p1[1]; LineString lineString = (LineString) lString
coords[1][0] = p2[0]; .getGeometryN(j);
coords[1][1] = p2[1]; eraseWireframeShape = target.createWireframeShape(true,
eraseWireframeShape.addLineSegment(coords); descriptor);
// try { drawTempLinePrimitive(lineString, eraseWireframeShape);
// target.drawPoint(coords[0][0], this.wireframeShapes.put(lineString,
// coords[0][1], 0, eraseWireframeShape);
// new RGB(0, 0, 255), erasedShapes.add(eraseWireframeShape);
// PointStyle.CIRCLE);
// } catch (VizException e) {
// e.printStackTrace();
// }
}
this.wireframeShapes.put(lineString,
eraseWireframeShape);
// try {
// target.drawWireframeShape(eraseWireframeShape,
// new RGB(0, 0, 255), 10.0f);
// } catch (VizException e) {
// e.printStackTrace();
// }
issueRefresh();
}
} }
} }
if (finalGeom instanceof LineString) {
GeometryFactory factory = new GeometryFactory();
lString = (LineString) finalGeom;
Point point = factory
.createPoint(lString.getCoordinates()[0]);
intersection = point.buffer(size / 2).intersection(geom);
finalGeom = geom.difference(intersection);
eraseWireframeShape = target.createWireframeShape(true,
descriptor);
drawTempLinePrimitive(lString, eraseWireframeShape);
this.wireframeShapes.put(lString, eraseWireframeShape);
erasedShapes.add(eraseWireframeShape);
} else {
lString = (GeometryCollection) finalGeom;
// for (int j = 0; j < lString.getNumGeometries(); j++) {
// System.out.println(lString.getGeometryN(j).getClass());
// }
// System.out.println(finalGeom.getClass() + " has "
// + lString.getNumGeometries() + " geometries");
}
} }
tempGeometries.clear();
} }
} }
@ -251,6 +294,7 @@ public class DrawingLayer extends
} }
public void resetTemp() { public void resetTemp() {
// this.tempWireframeShape.dispose();
this.tempGeometries.clear(); this.tempGeometries.clear();
needsRefresh = true; needsRefresh = true;
} }
@ -268,12 +312,16 @@ public class DrawingLayer extends
for (IWireframeShape shape : this.deletedShapes.values()) { for (IWireframeShape shape : this.deletedShapes.values()) {
shape.dispose(); shape.dispose();
} }
this.tempWireframeShape.dispose();
this.eraseWireframeShape.dispose(); this.eraseWireframeShape.dispose();
this.wireframeShapes.clear(); this.wireframeShapes.clear();
this.deletedShapes.clear(); this.deletedShapes.clear();
} }
/**
* Remove the last drawn shape
*/
public void undoAdd() { public void undoAdd() {
if (!this.wireframeShapes.isEmpty()) { if (!this.wireframeShapes.isEmpty()) {
Geometry geom = this.wireframeShapes.keySet().toArray( Geometry geom = this.wireframeShapes.keySet().toArray(
@ -284,7 +332,7 @@ public class DrawingLayer extends
} }
/** /**
* Add the ability to remove and redo * Redraw the last deleted shape
*/ */
public void redoAdd() { public void redoAdd() {
if (!deletedShapes.isEmpty()) { if (!deletedShapes.isEmpty()) {
@ -296,40 +344,18 @@ public class DrawingLayer extends
} }
/** /**
* @return the wireframeShapes * Add items to the right click menu, in this case just a button to launch
*/ * the Drawing toolbar
public IWireframeShape getTempWireframeShape() {
return tempWireframeShape;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.ui.cmenu.IContextMenuContributor#addContextMenuItems
* (org.eclipse.jface.action.IMenuManager, int, int)
*/ */
@Override @Override
public void addContextMenuItems(IMenuManager menuManager, int x, int y) { public void addContextMenuItems(IMenuManager menuManager, int x, int y) {
ResourcePair pair = new ResourcePair(); ResourcePair pair = new ResourcePair();
pair.setResource(this); pair.setResource(this);
Action action = new Action("Draw Toolbar") { Action action = new Action("Draw Toolbar...") {
public void run() { public void run() {
PathToolbar.getToolbar().open(); PathToolbar.getToolbar().open();
}; };
}; };
// ClearDrawingAction cAction = new ClearDrawingAction();
// cAction.setSelectedRsc(pair);
// cAction.setImageDescriptor(ToolsUtils.getImageDescriptor("remove.gif"));
// UndoAddAction uAction = new UndoAddAction();
// uAction.setSelectedRsc(pair);
// uAction.setImageDescriptor(ToolsUtils.getImageDescriptor("undo.gif"));
// RedoAddAction rAction = new RedoAddAction();
// rAction.setSelectedRsc(pair);
// rAction.setImageDescriptor(ToolsUtils.getImageDescriptor("redo.gif"));
// menuManager.add(cAction);
// menuManager.add(uAction);
// menuManager.add(rAction);
menuManager.add(action); menuManager.add(action);
} }

View file

@ -19,14 +19,13 @@
**/ **/
package com.raytheon.uf.viz.drawing; package com.raytheon.uf.viz.drawing;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
@ -34,11 +33,15 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem; import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.drawables.IDescriptor; import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.drawables.ResourcePair; import com.raytheon.uf.viz.core.drawables.ResourcePair;
import com.raytheon.uf.viz.core.icon.IconUtil; import com.raytheon.uf.viz.core.icon.IconUtil;
import com.raytheon.uf.viz.core.rsc.ResourceList;
import com.raytheon.uf.viz.drawing.actions.ClearDrawingAction; import com.raytheon.uf.viz.drawing.actions.ClearDrawingAction;
import com.raytheon.uf.viz.drawing.actions.EraseObjectsAction; import com.raytheon.uf.viz.drawing.actions.EraseObjectsAction;
import com.raytheon.uf.viz.drawing.actions.RedoAddAction; import com.raytheon.uf.viz.drawing.actions.RedoAddAction;
@ -72,15 +75,23 @@ public class PathToolbar extends CaveSWTDialog implements
private static PathToolbar toolbar; private static PathToolbar toolbar;
private Map<AbstractEditor, ResourcePair> layers; // private Map<AbstractEditor, ResourcePair> layers;
private ToolItem drawItem; private ToolItem drawItem;
private ToolItem eraserItem; private ToolItem eraserItem;
private ToolItem undoItem;
private ToolItem redoItem;
private ToolItem clearItem;
private IContextActivation drawingContext;
public static PathToolbar getToolbar() { public static PathToolbar getToolbar() {
if (toolbar == null) { if (toolbar == null) {
toolbar = new PathToolbar(Display.getCurrent().getActiveShell()); toolbar = new PathToolbar(new Shell(Display.getCurrent()));
} }
return toolbar; return toolbar;
} }
@ -91,7 +102,6 @@ public class PathToolbar extends CaveSWTDialog implements
*/ */
protected PathToolbar(Shell parentShell) { protected PathToolbar(Shell parentShell) {
super(parentShell, SWT.DIALOG_TRIM | CAVE.DO_NOT_BLOCK); super(parentShell, SWT.DIALOG_TRIM | CAVE.DO_NOT_BLOCK);
layers = new HashMap<AbstractEditor, ResourcePair>();
setText("Drawing"); setText("Drawing");
} }
@ -112,6 +122,18 @@ public class PathToolbar extends CaveSWTDialog implements
*/ */
@Override @Override
protected void initializeComponents(Shell shell) { protected void initializeComponents(Shell shell) {
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent e) {
PathToolbar.getToolbar().getShell().removeShellListener(this);
IContextService contextService = (IContextService) PlatformUI
.getWorkbench().getService(IContextService.class);
contextService.deactivateContext(drawingContext);
super.shellClosed(e);
}
});
Composite comp = new Composite(shell, SWT.NONE); Composite comp = new Composite(shell, SWT.NONE);
GridLayout layout = new GridLayout(); GridLayout layout = new GridLayout();
comp.setLayout(layout); comp.setLayout(layout);
@ -141,10 +163,9 @@ public class PathToolbar extends CaveSWTDialog implements
.getActiveEditorAs(AbstractEditor.class); .getActiveEditorAs(AbstractEditor.class);
IDescriptor desc = editor.getActiveDisplayPane() IDescriptor desc = editor.getActiveDisplayPane()
.getDescriptor(); .getDescriptor();
if (layers.containsKey(editor)) { for (ResourcePair pair : desc.getResourceList()) {
if (((DrawingLayer) layers.get(editor).getResource()).erase) { if (pair.getResource() instanceof DrawingLayer) {
((DrawingLayer) layers.get(editor).getResource()) ((DrawingLayer) pair.getResource()).erase = false;
.setErase(false);
eraserItem.setSelection(false); eraserItem.setSelection(false);
} }
} }
@ -153,49 +174,39 @@ public class PathToolbar extends CaveSWTDialog implements
// ((VizMultiPaneEditor) editor) // ((VizMultiPaneEditor) editor)
// .addSelectedPaneChangedListener(PathToolbar // .addSelectedPaneChangedListener(PathToolbar
// .getToolbar()); // .getToolbar());
for (ResourcePair pair : desc.getResourceList()) { updateToolbar();
if (pair.getResource() instanceof DrawingLayer) {
layers.put(editor, pair);
eraserItem.setEnabled(true);
// drawItem.setEnabled(false);
}
}
} }
}); });
ToolItem undoItem = new ToolItem(toolbar, SWT.FLAT); undoItem = new ToolItem(toolbar, SWT.FLAT);
undoItem.setText("Undo"); undoItem.setText("Undo");
undoItem.setImage(IconUtil.getImageDescriptor( undoItem.setImage(IconUtil.getImageDescriptor(
Activator.getDefault().getBundle(), "undo.gif").createImage()); Activator.getDefault().getBundle(), "undo.gif").createImage());
undoItem.setToolTipText("Ctrl+Z to Undo");
undoItem.addSelectionListener(new SelectionAdapter() { undoItem.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
UndoAddAction action = new UndoAddAction(); UndoAddAction action = new UndoAddAction();
AbstractEditor editor = EditorUtil executeAction(action);
.getActiveEditorAs(AbstractEditor.class); updateToolbar();
if (layers.get(editor) != null) {
executeAction(action);
}
} }
}); });
ToolItem redoItem = new ToolItem(toolbar, SWT.FLAT); redoItem = new ToolItem(toolbar, SWT.FLAT);
redoItem.setText("Redo"); redoItem.setText("Redo");
redoItem.setImage(IconUtil.getImageDescriptor( redoItem.setImage(IconUtil.getImageDescriptor(
Activator.getDefault().getBundle(), "redo.gif").createImage()); Activator.getDefault().getBundle(), "redo.gif").createImage());
redoItem.setToolTipText("Ctrl+Y to Redo");
redoItem.addSelectionListener(new SelectionAdapter() { redoItem.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
RedoAddAction action = new RedoAddAction(); RedoAddAction action = new RedoAddAction();
AbstractEditor editor = EditorUtil executeAction(action);
.getActiveEditorAs(AbstractEditor.class); updateToolbar();
if (layers.get(editor) != null) {
executeAction(action);
}
} }
}); });
ToolItem clearItem = new ToolItem(toolbar, SWT.FLAT); clearItem = new ToolItem(toolbar, SWT.FLAT);
clearItem.setText("Clear"); clearItem.setText("Clear");
clearItem clearItem
.setImage(IconUtil.getImageDescriptor( .setImage(IconUtil.getImageDescriptor(
@ -205,11 +216,8 @@ public class PathToolbar extends CaveSWTDialog implements
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
ClearDrawingAction action = new ClearDrawingAction(); ClearDrawingAction action = new ClearDrawingAction();
AbstractEditor editor = EditorUtil executeAction(action);
.getActiveEditorAs(AbstractEditor.class); updateToolbar();
if (layers.get(editor) != null) {
executeAction(action);
}
} }
}); });
@ -219,18 +227,23 @@ public class PathToolbar extends CaveSWTDialog implements
.setImage(IconUtil.getImageDescriptor( .setImage(IconUtil.getImageDescriptor(
Activator.getDefault().getBundle(), "eraser.png") Activator.getDefault().getBundle(), "eraser.png")
.createImage()); .createImage());
eraserItem.setEnabled(false);
eraserItem.addSelectionListener(new SelectionAdapter() { eraserItem.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
EraseObjectsAction action = new EraseObjectsAction(); EraseObjectsAction action = new EraseObjectsAction();
AbstractEditor editor = EditorUtil executeAction(action);
.getActiveEditorAs(AbstractEditor.class);
if (layers.get(editor) != null) {
executeAction(action);
}
} }
}); });
updateToolbar();
}
@Override
protected void opened() {
IContextService contextService = (IContextService) PlatformUI
.getWorkbench().getService(IContextService.class);
drawingContext = contextService
.activateContext("com.raytheon.uf.viz.drawing.context");
super.opened();
} }
private void executeAction(AbstractHandler action) { private void executeAction(AbstractHandler action) {
@ -262,4 +275,41 @@ public class PathToolbar extends CaveSWTDialog implements
} }
} }
private void updateToolbar() {
if (true) {
return;
}
AbstractEditor editor = EditorUtil
.getActiveEditorAs(AbstractEditor.class);
ResourceList list = editor.getActiveDisplayPane().getDescriptor()
.getResourceList();
for (ResourcePair pair : list) {
if (pair.getResource() instanceof DrawingLayer) {
DrawingLayer layer = (DrawingLayer) pair.getResource();
if (layer.getDeletedShapes().isEmpty()
&& layer.getWireframeShapes().isEmpty()) {
undoItem.setEnabled(false);
redoItem.setEnabled(false);
clearItem.setEnabled(false);
} else {
clearItem.setEnabled(true);
if (layer.getDeletedShapes().isEmpty()) {
undoItem.setEnabled(true);
redoItem.setEnabled(false);
} else {
undoItem.setEnabled(false);
redoItem.setEnabled(true);
}
if (layer.getWireframeShapes().isEmpty()) {
redoItem.setEnabled(true);
undoItem.setEnabled(false);
} else {
redoItem.setEnabled(false);
undoItem.setEnabled(true);
}
}
}
}
}
} }

View file

@ -31,6 +31,7 @@ import org.eclipse.swt.widgets.Display;
import com.raytheon.uf.viz.core.icon.IconUtil; import com.raytheon.uf.viz.core.icon.IconUtil;
import com.raytheon.uf.viz.core.rsc.AbstractResourceData; import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
import com.raytheon.uf.viz.core.rsc.IInputHandler; import com.raytheon.uf.viz.core.rsc.IInputHandler;
import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability;
import com.raytheon.uf.viz.drawing.AbstractDrawingTool; import com.raytheon.uf.viz.drawing.AbstractDrawingTool;
import com.raytheon.uf.viz.drawing.Activator; import com.raytheon.uf.viz.drawing.Activator;
import com.raytheon.uf.viz.drawing.PathDrawingResourceData; import com.raytheon.uf.viz.drawing.PathDrawingResourceData;
@ -83,7 +84,9 @@ public class PathDrawingTool extends AbstractDrawingTool {
*/ */
@Override @Override
public boolean handleMouseDown(int anX, int aY, int button) { public boolean handleMouseDown(int anX, int aY, int button) {
if (button != 1) if (button != 1
|| !theDrawingLayer.getCapability(EditableCapability.class)
.isEditable())
return false; return false;
Cursor cursor = null; Cursor cursor = null;
@ -120,7 +123,9 @@ public class PathDrawingTool extends AbstractDrawingTool {
*/ */
@Override @Override
public boolean handleMouseDownMove(int x, int y, int button) { public boolean handleMouseDownMove(int x, int y, int button) {
if (button != 1) if (button != 1
|| !theDrawingLayer.getCapability(EditableCapability.class)
.isEditable())
return false; return false;
Coordinate p1 = editor.translateClick(theLastMouseX, theLastMouseY); Coordinate p1 = editor.translateClick(theLastMouseX, theLastMouseY);
Coordinate p2 = editor.translateClick(x, y); Coordinate p2 = editor.translateClick(x, y);
@ -133,8 +138,12 @@ public class PathDrawingTool extends AbstractDrawingTool {
GeometryFactory gf = new GeometryFactory(); GeometryFactory gf = new GeometryFactory();
LineString ls = gf.createLineString(new Coordinate[] { p1, p2 }); LineString ls = gf.createLineString(new Coordinate[] { p1, p2 });
theDrawingLayer.addTempLine(ls); ls = theDrawingLayer.convertPixels(ls);
if (theDrawingLayer.isErase()) {
theDrawingLayer.addTempEraseLine(ls);
} else {
theDrawingLayer.addTempDrawLine(ls);
}
theLastMouseX = x; theLastMouseX = x;
theLastMouseY = y; theLastMouseY = y;
editor.refresh(); editor.refresh();
@ -149,25 +158,28 @@ public class PathDrawingTool extends AbstractDrawingTool {
*/ */
@Override @Override
public boolean handleMouseUp(int anX, int aY, int button) { public boolean handleMouseUp(int anX, int aY, int button) {
if (button != 1
|| !theDrawingLayer.getCapability(EditableCapability.class)
.isEditable()) {
return false;
}
// change the cursor back on up // change the cursor back on up
Cursor cursor = new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW); Cursor cursor = new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW);
Display.getCurrent().getActiveShell().setCursor(cursor); Display.getCurrent().getActiveShell().setCursor(cursor);
cursor.dispose(); cursor.dispose();
if (button != 1) {
return false;
}
theDrawingLayer.resetTemp(); theDrawingLayer.resetTemp();
Coordinate[] coords = (Coordinate[]) pathList Coordinate[] coords = (Coordinate[]) pathList
.toArray(new Coordinate[pathList.size()]); .toArray(new Coordinate[pathList.size()]);
GeometryFactory gf = new GeometryFactory(); GeometryFactory gf = new GeometryFactory();
if (coords.length > 1) { if (coords.length > 1) {
LineString ls = gf.createLineString(coords); LineString ls = gf.createLineString(coords);
ls = theDrawingLayer.convertPixels(ls);
if (!theDrawingLayer.isErase()) { if (!theDrawingLayer.isErase()) {
theDrawingLayer.addLine(ls, null); theDrawingLayer.finalizeLine(ls, null);
} }
} }
editor.refresh();
return true; return true;
} }
} }