001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.plugin.edit;
034:
035: import java.util.*;
036: import java.awt.*;
037: import java.awt.event.*;
038:
039: import javax.swing.*;
040: import com.vividsolutions.jump.I18N;
041:
042: import com.vividsolutions.jts.geom.*;
043: import com.vividsolutions.jump.geom.*;
044: import com.vividsolutions.jump.util.ColorUtil;
045: import com.vividsolutions.jump.feature.*;
046: import com.vividsolutions.jump.task.*;
047: import com.vividsolutions.jump.workbench.WorkbenchContext;
048: import com.vividsolutions.jump.workbench.model.*;
049: import com.vividsolutions.jump.workbench.plugin.*;
050: import com.vividsolutions.jump.workbench.ui.*;
051:
052: /**
053: * Class used by {@link AffineTransformation} to build a transformation from a src
054: * Coordinate[3] array and a dest Coordinate[3] array.
055: *
056: * @author Martin Davis
057: */
058:
059: class TriPointTransRotScaleBuilder extends TransRotScaleBuilder {
060:
061: /**
062: * Creates a builder from two Coordinate[3] arrays defining the src and dest control points
063: *
064: * @param srcVector the two Coordinates defining the src vector
065: * @param destVector the two Coordinates defining the dest vector
066: */
067: TriPointTransRotScaleBuilder(Coordinate[] srcPt, Coordinate[] destPt) {
068: super (srcPt, destPt);
069: }
070:
071: protected void compute(Coordinate[] srcPt, Coordinate[] destPt) {
072: /**
073: * For now just extract a Y scale from the third pt.
074: * In future could do shear too.
075: */
076:
077: /*
078: AffineTransformationBuilder atBuilder = new AffineTransformationBuilder(
079: srcPt[0],
080: srcPt[1],
081: srcPt[2],
082: destPt[0],
083: destPt[1],
084: destPt[2]
085: );
086: */
087:
088: originX = srcPt[1].x;
089: originY = srcPt[1].y;
090:
091: double srcLenBase = srcPt[1].distance(srcPt[2]);
092: double destLenBase = destPt[1].distance(destPt[2]);
093:
094: double srcLenSide = srcPt[0].distance(srcPt[1]);
095: double destLenSide = destPt[0].distance(destPt[1]);
096:
097: boolean isZeroLength = (srcLenBase == 0.0 || destLenBase == 0.0
098: || srcLenSide == 0.0 || destLenSide == 0.0);
099:
100: if (!isZeroLength) {
101: scaleX = destLenBase / srcLenBase;
102: scaleY = destLenSide / srcLenSide;
103:
104: double angleSrc = Angle.angle(srcPt[1], srcPt[2]);
105: double angleDest = Angle.angle(destPt[1], destPt[2]);
106: double angleRad = angleDest - angleSrc;
107: angle = Math.toDegrees(angleRad);
108: }
109:
110: dx = destPt[1].x - srcPt[1].x;
111: dy = destPt[1].y - srcPt[1].y;
112: }
113:
114: }
|