|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jfig.canvas.FigTrafo2D
simple 2D transformation with translation and rotation.
Class FigTrafo2D collects the coordinate transformation methods needed for the xfig/jfig object model.
The internal representation in jfig files (.fig) uses integer coordinates with 2400dpi resolution, called world-coordinates (WC). This allows easy and accurate scaling to typical bitmapped output devices, although the usual output is expected to be to a 75dpi screen or a (resolution independent) Postscript file. As is standard with screen-based coordinates, the origin (0,0) is in the top-left corner of the screen/page.
This program does not use SI-units (that is, meters). A simple hack is provided to scale the internal WC-values back to mm-values. The resolution of 2400 dpi provides an equivalent of approximately 96 dots/mm.
The grid and slider scales may be set and displayed in inch or mm.
Coordinates of objects (as multiples of 2400dpi) may be positive or negative in the range -MAXINT .. MAXINT. The output filters take care to center or align a drawing on a given piece of paper.
The standard transformations between world-coordinates and the computer screen do not allow for rotations. A zoom factor, however, is supported. jfig assumes a fixed screen resolution of 75dpi.
I hope to include compound and hierarchical objects in the editor in the future. The transformations used for these objects will allow rotations.
Field Summary | |
protected java.awt.Point |
anchor
|
static int |
COARSE_GRID
|
static int |
COARSE_SNAP
|
protected double |
d_zoom_factor
|
static boolean |
debug
|
static int |
DOTS_PER_INCH
|
static int |
DOTS_PER_MM
|
static int |
DOTS_PER_XMM
|
static int |
dpi
|
static int |
DPI
|
(package private) static double |
FACTOR
|
(package private) static double[] |
factors
|
static int |
FINE_GRID
|
static int |
FINE_SNAP
|
int |
gridMode
|
static double |
MAX_ZOOM_FACTOR
|
static int |
MEDIUM_GRID
|
static int |
MEDIUM_SNAP
|
static double |
MIN_ZOOM_FACTOR
|
static int |
NO_GRID
|
static int |
NO_SNAP
|
(package private) static double[] |
offsets
|
protected java.awt.Point |
p
|
protected double |
snapDelta
|
int |
snapMode
|
static int |
TEN_GRID
|
static int |
TEN_SNAP
|
long |
timestamp
|
int |
units
|
static int |
UNITS_INCHES
|
static int |
UNITS_MM
|
static java.lang.String[] |
UNITS_STRING
|
static int |
UNITS_XMM
|
protected double |
zoom_factor
|
protected int |
zoom_factor75
|
Constructor Summary | |
FigTrafo2D()
default constructor. |
Method Summary | |
void |
doChangeUnits()
toggle the current units (UNITS_INCHES -> UNITS_MM -> UNITS_XMM) |
java.lang.String |
get_units_string()
get string representation of current units, one of "in", "mm", "xmm". |
int |
get_units()
get current units (only UNITS_MM and UNITS_INCHES are currently defined) |
java.awt.Point |
getAnchor()
get the current viewport anchor |
FigTrafo2D |
getClone()
build a clone of the current transformation. |
int |
getGridMode()
get the current grid mode (none, coarse, medium, fine) |
double |
getGridSpacingValue()
return the spacing (in world coordinates) of two grid points. |
double |
getMaxZoomFactor()
|
double |
getMinZoomFactor()
|
java.awt.Point |
getScreenCoords(java.awt.Point WP)
|
double |
getSnap()
get the current snapDelta value, that is, the current world coordinate distance of two snap points. |
int |
getSnapRelative()
return a 'relative' snap distance. |
long |
getTimestamp()
get the timestamp of this FigTrafo2D. |
int |
getUnits()
|
double |
getValueInUnits(int v)
convert the value of world coordinate v into the current units |
java.awt.Point |
getWorldCoords(int sx,
int sy)
construct a new world coordinate Point from screen coords (sx,sy). |
java.awt.Point |
getWorldCoords(java.awt.Point SP)
construct a new world coordinate Point from screen coordinate Point SP. |
java.awt.Point |
getWorldCoordsSnapped(int sx,
int sy)
construct a new world-coord Point from grid-snapped screen coords (sx,sy). |
java.awt.Point |
getWorldCoordsSnapped(java.awt.Point SP)
construct a new world-coord Point from grid-snapped screen-coord Point SP. |
double |
getZoom()
|
double |
getZoomFactor_MultipleOfTwo()
get the current zoom factor, rounded to the next multiple of 2 |
double |
getZoomFactor()
get the current zoom factor. |
boolean |
insideSnap(int x1,
int x2)
check whether two world coordinates differ by less than the current snap distance (of the equivalent of five screen pixels at the current zoom factor). |
void |
message(java.lang.String msg)
print a String message via jfig.utils.ExceptionTracer |
java.awt.Point |
screen_to_wc_snapped(int sx,
int sy,
java.awt.Point p)
set Point p world coordinates from grid-snapped screen coords (sx,sy). |
java.awt.Point |
screen_to_wc_snapped(java.awt.Point sc_p,
java.awt.Point p)
transform a point from screen-coordinates to grid-snapped world-coordinates. |
int |
screen_to_wc_x(int sx)
|
int |
screen_to_wc_y(int sy)
|
int |
screen_to_wc(int dsx)
get the world coordinate length dwx of a length dsx in screen coords. |
java.awt.Point |
screen_to_wc(java.awt.Point sc_p,
java.awt.Point p)
transform a point from screen-coordinates to world-coordinates |
void |
set_zoom_region_ooooolllllldddd(int wx,
int wy,
int wx2,
int wy2,
int width,
int height)
set_zoom_region(): set the viewport to the given region |
void |
set_zoom_region(int wx,
int wy,
int wx2,
int wy2,
int width,
int height)
set_zoom_region(): set the viewport to the given region. |
void |
set_zoom(double zoom)
change the zoom factor. |
void |
setAnchor(java.awt.Point anchor)
set the viewport anchor (left bottom corner of the part of the drawing currently visible on the screen). |
void |
setGridMode(int gridMode)
set a new grid mode. |
void |
setSnapAbsolute(double snapDelta)
set the snapDelta absolutely. |
void |
setSnapRelative(int mode)
set the snapDelta relative to the current zoom factor and units. |
void |
setUnits(int _units)
|
int |
wc_to_screen_x(int wc_x)
transform a world-coordinate-x to screen-coordinate-x |
int |
wc_to_screen_y(int wc_y)
transform a world-coordinate-y to screen-coordinate-y |
double |
wc_to_screen(double dwx)
|
java.awt.Point |
wc_to_screen(double wx,
double wy,
java.awt.Point sp)
transform a point from world-coordinates to a point sp in screen-coordinates. |
int |
wc_to_screen(int dwx)
get the screen coordinate length dsx of a length dwx in world coords. |
java.awt.Point |
wc_to_screen(java.awt.Point wp,
java.awt.Point sp)
transform a point wp from world-coordinates to a point sp in screen-coordinates. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int dpi
public static final int DPI
public static final int DOTS_PER_MM
public static final int DOTS_PER_INCH
public static final int DOTS_PER_XMM
public static final int UNITS_MM
public static final int UNITS_INCHES
public static final int UNITS_XMM
public static java.lang.String[] UNITS_STRING
public static final int NO_GRID
public static final int FINE_GRID
public static final int MEDIUM_GRID
public static final int COARSE_GRID
public static final int TEN_GRID
public static final int NO_SNAP
public static final int COARSE_SNAP
public static final int MEDIUM_SNAP
public static final int FINE_SNAP
public static final int TEN_SNAP
public static final double MIN_ZOOM_FACTOR
public static final double MAX_ZOOM_FACTOR
public static final boolean debug
public int units
protected double zoom_factor
protected int zoom_factor75
protected double d_zoom_factor
protected double snapDelta
public int snapMode
public int gridMode
public long timestamp
protected java.awt.Point anchor
protected java.awt.Point p
static final double[] offsets
static final double[] factors
static final double FACTOR
Constructor Detail |
public FigTrafo2D()
Method Detail |
public void setAnchor(java.awt.Point anchor)
The size of the viewport in world-coordinates depends both on the size of the drawing canvas on the screen and the current zoom-factor.
anchor
- The new value (Point) for the viewport anchor.public java.awt.Point getAnchor()
public void set_zoom(double zoom)
zoom
- The new zoom factor. Currently only positive integers
are allowed.public void set_zoom_region(int wx, int wy, int wx2, int wy2, int width, int height)
Actually, this method tries to fit the specified region as far as possible into the current window size, while limiting the zoom-factors to multiples of sqrt(2).
anchor'(
wx
- the top left corner (x)wy
- the top left corner (y)wx2
- the bottom right corner (x)wy2
- (y)width
- the current window size (width)height
- (height)public void set_zoom_region_ooooolllllldddd(int wx, int wy, int wx2, int wy2, int width, int height)
wx
- the top left corner (x)wy
- the top left corner (y)wx2
- the bottom right corner (x)wy2
- (y)width
- the current window size (width)height
- (height)public double getZoomFactor()
public double getZoom()
public double getMinZoomFactor()
public double getMaxZoomFactor()
public double getZoomFactor_MultipleOfTwo()
public int get_units()
public int getUnits()
public java.lang.String get_units_string()
public double getValueInUnits(int v)
public void setSnapAbsolute(double snapDelta)
snapDelta
- The new value for the snapDelta variablepublic void setSnapRelative(int mode)
public double getSnap()
public int getSnapRelative()
This method either returns the current world coordinate distance of two snap points like method getSnap() (if snapping is active), or the world coordinate distance of five pixels in screen coords at the current zoom factor.
Use this method to find out whether a given mouse position is 'near' a given coordinate, dependent on current snap mode and zoom factor.
public boolean insideSnap(int x1, int x2)
public double getGridSpacingValue()
public int screen_to_wc(int dsx)
public int screen_to_wc_x(int sx)
public int screen_to_wc_y(int sy)
public java.awt.Point screen_to_wc(java.awt.Point sc_p, java.awt.Point p)
sc_p
- The point in screen-coordinates to be transformedp
- The point in world-coordinates to be transformed,public int wc_to_screen(int dwx)
public double wc_to_screen(double dwx)
public int wc_to_screen_x(int wc_x)
wc_x
- The world-coordinate x-value to be transformedpublic int wc_to_screen_y(int wc_y)
wc_y
- The world-coordinate y-value to be transformedpublic java.awt.Point wc_to_screen(java.awt.Point wp, java.awt.Point sp)
public java.awt.Point wc_to_screen(double wx, double wy, java.awt.Point sp)
public java.awt.Point screen_to_wc_snapped(java.awt.Point sc_p, java.awt.Point p)
public java.awt.Point screen_to_wc_snapped(int sx, int sy, java.awt.Point p)
public java.awt.Point getWorldCoords(int sx, int sy)
public java.awt.Point getWorldCoords(java.awt.Point SP)
public java.awt.Point getWorldCoordsSnapped(int sx, int sy)
public java.awt.Point getWorldCoordsSnapped(java.awt.Point SP)
public java.awt.Point getScreenCoords(java.awt.Point WP)
public void setGridMode(int gridMode)
gridMode
- the integer value of the new grid spacing,
one of NO_GRID, COARSE_GRID, MEDIUM_GRID, FINE_GRID.public int getGridMode()
public long getTimestamp()
The timestamp is updated whenever the transformation anchor or zoom factor is changed.
Compare the transformation timestamp with object timestamps to decide whether the screen representation of those objects need to be updated.
public void doChangeUnits()
public void setUnits(int _units)
public FigTrafo2D getClone()
public void message(java.lang.String msg)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |