Changeset 27403 in osm for applications/editors/josm/plugins/piclayer
- Timestamp:
- 2012-01-04T14:30:39+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/piclayer
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/piclayer/build.xml
r27352 r27403 22 22 --> 23 23 <project name="PicLayer" default="dist" basedir="."> 24 <property name="commit.message" value="PicLayer - fix of #7171"/>24 <property name="commit.message" value="PicLayer - now all actions are shown in history and user can undo/redo changes"/> 25 25 <property name="plugin.main.version" value="4669"/> 26 26 <!-- -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/GenericPicTransformAction.java
r27168 r27403 13 13 import org.openstreetmap.josm.gui.MapFrame; 14 14 import org.openstreetmap.josm.gui.layer.Layer; 15 import org.openstreetmap.josm.plugins.piclayer.command.TransformCommand; 15 16 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract; 16 17 import org.openstreetmap.josm.tools.Shortcut; … … 24 25 protected EastNorth prevEastNorth = null; 25 26 protected Point2D prevMousePoint = null; 27 protected TransformCommand currentCommand = null; 28 private String actionName; 26 29 27 public GenericPicTransformAction(String name, String iconName,30 public GenericPicTransformAction(String name, String actionName, String iconName, 28 31 String tooltip, Shortcut shortcut, MapFrame mapFrame, Cursor cursor) { 29 32 super(name, iconName, tooltip, shortcut, mapFrame, cursor); 33 this.actionName = actionName; 30 34 } 31 35 32 public GenericPicTransformAction(String name, String iconName,36 public GenericPicTransformAction(String name, String actionName, String iconName, 33 37 String tooltip, MapFrame mapFrame, Cursor cursor) { 34 38 super(name, iconName, tooltip, mapFrame, cursor); 39 this.actionName = actionName; 35 40 } 36 41 … … 61 66 // try to find and fill selected point if possible 62 67 selectedPoint = currentLayer.findSelectedPoint(e.getPoint()); 68 currentCommand = new TransformCommand(currentLayer, actionName); 63 69 } 64 70 } … … 82 88 // End action 83 89 isDragging = false; 90 currentCommand.addIfChanged(); 84 91 } 85 92 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/ResetCalibrationAction.java
r27120 r27403 5 5 import java.awt.event.ActionEvent; 6 6 7 import org.openstreetmap.josm.Main;8 7 import org.openstreetmap.josm.actions.JosmAction; 8 import org.openstreetmap.josm.plugins.piclayer.command.TransformCommand; 9 9 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract; 10 10 import org.openstreetmap.josm.plugins.piclayer.transform.PictureTransform; … … 18 18 this.layer = layer; 19 19 } 20 20 21 21 @Override 22 22 public void actionPerformed(ActionEvent arg0) { 23 TransformCommand currentCommand = new TransformCommand(layer, tr("Calibration reset")); 23 24 layer.resetCalibration(); 24 Main.map.mapView.repaint();25 currentCommand.addIfChanged(); 25 26 } 26 27 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/MovePictureAction.java
r27120 r27403 26 26 27 27 import org.openstreetmap.josm.Main; 28 import org.openstreetmap.josm.data.coor.EastNorth; 28 29 import org.openstreetmap.josm.gui.MapFrame; 29 30 import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction; 30 31 import org.openstreetmap.josm.tools.ImageProvider; 31 import org.openstreetmap.josm.data.coor.EastNorth;32 32 33 33 /** … … 41 41 */ 42 42 public MovePictureAction(MapFrame frame) { 43 super(tr("PicLayer move"), "move", tr("Drag to move the picture"), frame, ImageProvider.getCursor("crosshair", null));43 super(tr("PicLayer move"), tr("Moved"), "move", tr("Drag to move the picture"), frame, ImageProvider.getCursor("crosshair", null)); 44 44 } 45 45 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/RotatePictureAction.java
r27120 r27403 41 41 */ 42 42 public RotatePictureAction(MapFrame frame) { 43 super(tr("PicLayer rotate"), "rotate", tr("Drag to rotate the picture"), frame, ImageProvider.getCursor("crosshair", null));43 super(tr("PicLayer rotate"), tr("Rotated"), "rotate", tr("Drag to rotate the picture"), frame, ImageProvider.getCursor("crosshair", null)); 44 44 } 45 45 … … 52 52 else { 53 53 factor = Main.pref.getDouble("piclayer.rotatefactors.low_precision", 10.0 ); 54 } 54 } 55 55 currentLayer.rotatePictureBy( ( e.getY() - prevMousePoint.getY() ) / factor ); 56 56 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScalePictureActionAbstract.java
r27120 r27403 38 38 * Constructor 39 39 */ 40 public ScalePictureActionAbstract (String name, String icon, String tooltip, MapFrame frame) {41 super(name, icon, tooltip, frame, ImageProvider.getCursor("crosshair", null));40 public ScalePictureActionAbstract (String name, String actionName, String icon, String tooltip, MapFrame frame) { 41 super(name, actionName, icon, tooltip, frame, ImageProvider.getCursor("crosshair", null)); 42 42 } 43 43 44 @Override 44 45 protected void doAction(MouseEvent e) { 45 46 double factor; … … 49 50 else { 50 51 factor = Main.pref.getDouble("piclayer.scalefactors.low_precision", 1.015); 51 } 52 } 52 53 doTheScale( Math.pow(factor, prevMousePoint.getY() - e.getY() ) ); 53 54 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleXPictureAction.java
r27120 r27403 35 35 */ 36 36 public ScaleXPictureAction(MapFrame frame) { 37 super(tr("PicLayer scale X"), "scale_x", tr("Drag to scale the picture in the X Axis"), frame);37 super(tr("PicLayer scale X"), tr("Scaled by X"), "scale_x", tr("Drag to scale the picture in the X Axis"), frame); 38 38 } 39 39 40 @Override 40 41 public void doTheScale( double scale ) { 41 42 currentLayer.scalePictureBy( scale, 1.0 ); -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleXYPictureAction.java
r27120 r27403 35 35 */ 36 36 public ScaleXYPictureAction(MapFrame frame) { 37 super(tr("PicLayer scale"), "scale", tr("Drag to scale the picture in the X and Y Axis"), frame);37 super(tr("PicLayer scale"), tr("Scaled"), "scale", tr("Drag to scale the picture in the X and Y Axis"), frame); 38 38 } 39 39 40 @Override 40 41 public void doTheScale( double scale ) { 41 42 currentLayer.scalePictureBy( scale, scale ); -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleYPictureAction.java
r27120 r27403 35 35 */ 36 36 public ScaleYPictureAction(MapFrame frame) { 37 super(tr("PicLayer scale Y"), "scale_y", tr("Drag to scale the picture in the Y Axis"), frame);37 super(tr("PicLayer scale Y"), tr("Scaled by Y"), "scale_y", tr("Drag to scale the picture in the Y Axis"), frame); 38 38 } 39 39 40 @Override 40 41 public void doTheScale( double scale ) { 41 42 currentLayer.scalePictureBy( 1.0, scale ); -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ShearPictureAction.java
r27120 r27403 28 28 29 29 import org.openstreetmap.josm.Main; 30 import org.openstreetmap.josm.data.coor.EastNorth; 30 31 import org.openstreetmap.josm.gui.MapFrame; 31 32 import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction; 32 33 import org.openstreetmap.josm.tools.ImageProvider; 33 import org.openstreetmap.josm.data.coor.EastNorth;34 34 35 35 /** … … 43 43 */ 44 44 public ShearPictureAction(MapFrame frame) { 45 super(tr("PicLayer shear"), "shear", tr("Drag to shear the picture"), frame, ImageProvider.getCursor("crosshair", null));45 super(tr("PicLayer shear"), tr("Sheared"), "shear", tr("Drag to shear the picture"), frame, ImageProvider.getCursor("crosshair", null)); 46 46 } 47 47 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/MovePointAction.java
r27168 r27403 7 7 import java.awt.geom.Point2D; 8 8 9 import org.openstreetmap.josm.Main;10 9 import org.openstreetmap.josm.gui.MapFrame; 11 10 import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction; … … 17 16 18 17 public MovePointAction(MapFrame frame) { 19 super(tr("PicLayer Move point"), "movepoint", tr("Drag or create point on the picture"), frame, ImageProvider.getCursor("crosshair", null));18 super(tr("PicLayer Move point"), tr("Point added/moved"), "movepoint", tr("Drag or create point on the picture"), frame, ImageProvider.getCursor("crosshair", null)); 20 19 } 21 20 … … 42 41 if (selectedPoint == null) 43 42 currentLayer.getTransformer().addOriginPoint(pressed); 43 44 currentCommand.addIfChanged(); 44 45 } catch (NoninvertibleTransformException e1) { 45 46 e1.printStackTrace(); 46 47 } 47 Main.map.mapView.repaint();48 48 } 49 49 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/TransformPointAction.java
r27168 r27403 17 17 18 18 public TransformPointAction(MapFrame frame) { 19 super(tr("PicLayer Transform point"), "transformpoint", tr("Transform point on the picture"), frame, ImageProvider.getCursor("crosshair", null));19 super(tr("PicLayer Transform point"), tr("Point transformed"), "transformpoint", tr("Transform point on the picture"), frame, ImageProvider.getCursor("crosshair", null)); 20 20 } 21 21 … … 30 30 currentLayer.getTransformer().updatePair(selectedPoint, pressed); 31 31 } 32 33 currentCommand.addIfChanged(); 32 34 } catch (NoninvertibleTransformException e1) { 33 35 e1.printStackTrace(); -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerAbstract.java
r27231 r27403 575 575 return selected; 576 576 } 577 578 public void saveTransformCommand() { 579 580 } 577 581 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/PictureTransform.java
r27191 r27403 12 12 13 13 private List<Point2D> originPoints; 14 private List<Point2D> desiredPoints;15 14 16 15 public PictureTransform() { 17 16 cachedTransform = new AffineTransform(); 18 17 originPoints = new ArrayList<Point2D>(3); 19 desiredPoints = new ArrayList<Point2D>(3);20 18 } 21 19 … … 24 22 } 25 23 26 public List<? extends Point2D> getOriginPoints() { 27 return originPoints; 28 } 29 30 public List<? extends Point2D> getDesiredPoints() { 31 return desiredPoints; 32 } 33 34 public void addDesiredPoint(Point2D picturePoint) { 35 if (desiredPoints.size() < 3) 36 desiredPoints.add(picturePoint); 37 trySolve(); 38 } 39 40 private AffineTransform solveEquation() throws NoSolutionException { 24 private AffineTransform solveEquation(List<Point2D> desiredPoints) throws NoSolutionException { 41 25 Matrix3D X = new Matrix3D(originPoints); 42 26 Matrix3D Y = new Matrix3D(desiredPoints); … … 49 33 if (originPoints.size() < 3) 50 34 originPoints.add(originPoint); 51 trySolve();52 35 } 53 36 54 37 public void resetCalibration() { 55 38 originPoints.clear(); 56 desiredPoints.clear();57 39 modified = false; 58 40 cachedTransform = new AffineTransform(); 59 }60 61 private void trySolve() {62 if (desiredPoints.size() == 3 && originPoints.size() == 3) {63 try {64 cachedTransform.concatenate(solveEquation());65 modified = true;66 desiredPoints.clear();67 } catch (NoSolutionException e) {68 System.err.println(e.getMessage());69 }70 }71 41 } 72 42 … … 86 56 return; 87 57 88 desiredPoints.clear();58 List<Point2D> desiredPoints = new ArrayList<Point2D>(3); 89 59 90 60 for (Point2D origin : originPoints) { … … 94 64 desiredPoints.add(origin); 95 65 } 96 trySolve( );66 trySolve(desiredPoints); 97 67 } 68 69 private void trySolve(List<Point2D> desiredPoints) { 70 if (desiredPoints.size() == 3 && originPoints.size() == 3) { 71 try { 72 cachedTransform.concatenate(solveEquation(desiredPoints)); 73 modified = true; 74 desiredPoints.clear(); 75 } catch (NoSolutionException e) { 76 System.err.println(e.getMessage()); 77 } 78 } 79 } 98 80 99 81 public void replaceOriginPoint(Point2D originPoint, Point2D newOriginPoint) { … … 135 117 modified = false; 136 118 } 119 120 public void setTransform(AffineTransform newTransform) { 121 cachedTransform = new AffineTransform(newTransform); 122 } 123 124 public List<Point2D> getOriginPoints() { 125 return originPoints; 126 } 127 128 public void setOriginPoints(List<Point2D> list) { 129 this.originPoints = new ArrayList<Point2D>(list); 130 } 137 131 }
Note:
See TracChangeset
for help on using the changeset viewer.