001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.project;
018:
019: import java.awt.Dimension;
020: import java.awt.Point;
021: import java.awt.Rectangle;
022: import java.awt.Shape;
023: import java.awt.geom.AffineTransform;
024: import java.io.IOException;
025: import java.util.List;
026:
027: import net.refractions.udig.project.render.IRenderManager;
028: import net.refractions.udig.project.render.IViewportModel;
029: import net.refractions.udig.project.render.displayAdapter.IMapDisplay;
030:
031: import org.geotools.feature.FeatureCollection;
032: import org.geotools.geometry.jts.ReferencedEnvelope;
033: import org.opengis.referencing.crs.CoordinateReferenceSystem;
034: import org.opengis.referencing.operation.MathTransform2D;
035:
036: import com.vividsolutions.jts.geom.Coordinate;
037: import com.vividsolutions.jts.geom.Envelope;
038: import com.vividsolutions.jts.geom.Geometry;
039:
040: /**
041: * Provides access to contextual information.
042: * <p>
043: * Toolkits are used by extensions to access Map and Project information. A Toolkit should never be
044: * instantiated by a developer. The framework provides Toolkits to extensions.
045: * </p>
046: * <p>
047: * Responsibilities:
048: * <ul>
049: * <li>Provide access to the objects that an extension can use for its operations.</li>
050: * <li>Provide convenience methods for extension developers to use.</li>
051: * <li>Provide a consistent interface for extensions which will not easily change in future
052: * versions</li>
053: * </ul>
054: * </p>
055: *
056: * @author Jesse
057: * @since 0.5
058: */
059: public interface IAbstractContext {
060:
061: /**
062: * The map's viewport model.
063: * <p>
064: * Convenience for getMap().getViewportModel().
065: * </p>
066: * <p>
067: * Called to obtain current viewport bounds and crs.
068: * </p>
069: *
070: * @return The Viewportmodel for the map.
071: * @see IViewportModel
072: */
073: IViewportModel getViewportModel();
074:
075: /**
076: * The map's edit manager.
077: * <p>
078: * Convenience for getMap().getEditManager().
079: * </p>
080: * <p>
081: * Called to obtain the currently editable feature.
082: * </p>
083: *
084: * @return The map's edit manager.
085: * @see IEditManager
086: */
087: IEditManager getEditManager();
088:
089: /**
090: * The map's render manager
091: * <p>
092: * Convenience for getMap().getRenderManager().
093: * </p>
094: * <p>
095: * Called to refresh the current display.
096: * </p>
097: *
098: * @return The RenderManager for the map.
099: * @see IRenderManager
100: */
101: IRenderManager getRenderManager();
102:
103: /**
104: * The map's display object.
105: * <p>
106: * Convenience for getMap().getRenderManager().getMapDisplay().
107: * </p>
108: * <p>
109: * Called to obtain the height and width of the display.
110: * </p>
111: *
112: * @return The IMapDisplay for the map.
113: * @see IMapDisplay
114: */
115: IMapDisplay getMapDisplay();
116:
117: /**
118: * The context's map.
119: * <p>
120: * The Map data object.
121: * </p>
122: *
123: * @return The context's map.
124: * @see IMap
125: */
126: IMap getMap();
127:
128: /**
129: * The map's containing Project.
130: * <p>
131: * Convenience for getMap().getProject().
132: * </p>
133: * <p>
134: * Contains all the {@linkplain IProjectElements} in the project.
135: * </p>
136: *
137: * @return The containing Project of the map.
138: * @see IProject
139: */
140: IProject getProject();
141:
142: /**
143: * Gets up the affine transform that will transform from the world to screen. A convenience
144: * method.
145: *
146: * @return a transform that maps from real world coordinates to the screen
147: */
148: AffineTransform worldToScreenTransform();
149:
150: /**
151: * Returns the pixel on the screen for a given coordinate in world space. A convenience method.
152: *
153: * @param coord A coordinate in world space.
154: * @return The pixel on the screen that the world coordinate is drawn on.
155: */
156: Point worldToPixel(Coordinate coord);
157:
158: /**
159: * Converts a coordinate expressed on the device space back to real world coordinates A
160: * convenience method.
161: *
162: * @param x horizontal coordinate on device space
163: * @param y vertical coordinate on device space
164: * @return The correspondent real world coordinate
165: */
166: Coordinate pixelToWorld(int x, int y);
167:
168: /**
169: * Creates an Envelope that is close, error to slightly larger, to the Rectangle when it is
170: * transformed into world coordinates.
171: *
172: * @param rectangle
173: * @return
174: */
175: public ReferencedEnvelope worldBounds(Rectangle rectangle);
176:
177: /**
178: * Creates a MathTransform that will transform from the screen CRS to the world CRS.
179: *
180: * @return
181: */
182: public MathTransform2D worldToScreenMathTransform();
183:
184: /**
185: * Returns the size of a pixel in world units. A convenience method.
186: *
187: * @return the size of a pixel in world units.
188: */
189: Coordinate getPixelSize();
190:
191: /**
192: * Returns a world bounding box the size of a pixel at the location corresponding to the point
193: * on the screen. A convenience method.
194: *
195: * @return the size of a pixel in world units.
196: */
197: Envelope getPixelBoundingBox(Point screenLocation);
198:
199: /**
200: * Returns a world bounding box the scalefactor * (size of a pixel) at the location
201: * corresponding to the point on the screen. A convenience method.
202: * <p>
203: * XXX: Can we make this a ReferencedEnvelope?
204: * </p>
205: *
206: * @return the size of a pixel in world units.
207: */
208: ReferencedEnvelope getBoundingBox(Point screenLocation,
209: int scalefactor);
210:
211: /**
212: * CoordinateReferenceSystem of the map.
213: *
214: * @return getViewportModel().getCRS();
215: */
216: CoordinateReferenceSystem getCRS();
217:
218: /**
219: * Transform the provided envelope to a java 2d shape (in screen coordiantes).
220: *
221: * @param box
222: * @return
223: */
224: Shape toShape(ReferencedEnvelope envelope);
225:
226: /**
227: * Returns the currently Selected Layer
228: *
229: * @return the currently Selected Layer
230: */
231: public ILayer getSelectedLayer();
232:
233: /**
234: * Transform the provided geometry to a java 2d shape (in screen coordiantes).
235: *
236: * @param box
237: * @return
238: */
239: Shape toShape(Geometry geometry, CoordinateReferenceSystem crs);
240:
241: /**
242: * Returns all the features that intersect with the bounding box.
243: *
244: * @param source The featuresource to get features from.
245: * @param bbox The bounding box that acts as a filter. Must be in map coordinates.
246: * @return all the features that intersect with the bounding box.
247: */
248: FeatureCollection getFeaturesInBbox(ILayer layer, Envelope bbox)
249: throws IOException;
250:
251: /**
252: * Returns the list of layers in the current map.
253: *
254: * @return The list of layers in the current map.
255: */
256: List<ILayer> getMapLayers();
257:
258: /**
259: * Makes a deep copy of this object, if necessary.
260: * This is an alternative to clone since I hate clone, it is too hard to implement.
261: *
262: * @return a new copy of this object.
263: */
264: public IAbstractContext copy();
265:
266: /**
267: * Transforms the coordinate from the bounding box (bbox) to the area defined by the rectangle it starts at 0,0. A simple
268: * Affine transform is used and the y-axis is flipped since it is assumed the bbox is a world bbox and the Rectangle
269: * is a cartesian like on the screen.
270: *
271: * @param bbox The from area
272: * @param displaySize the to area
273: * @param coordinate the coordinate to transform.
274: * @return the point that the coordiante transforms to.
275: */
276: Point tranformCoordinate(Envelope bbox, Dimension displaySize,
277: Coordinate coordinate);
278:
279: }
|